Disable srolling down comment list while comments are loading

Prevents comment list from losing focus to some outside View
when user tries to scroll down after reaching "end"
This commit is contained in:
Alexander-- 2019-11-14 20:54:40 +06:59
parent 5f051a9766
commit 7d75950624

View file

@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.views.NewPipeRecyclerView;
import java.util.Queue; import java.util.Queue;
@ -17,6 +18,8 @@ import icepick.State;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
public abstract class BaseListInfoFragment<I extends ListInfo> public abstract class BaseListInfoFragment<I extends ListInfo>
@ -136,9 +139,13 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
isLoading.set(true); isLoading.set(true);
if (currentWorker != null) currentWorker.dispose(); if (currentWorker != null) currentWorker.dispose();
forbidDownwardFocusScroll();
currentWorker = loadMoreItemsLogic() currentWorker = loadMoreItemsLogic()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doFinally(this::allowDownwardFocusScroll)
.subscribe((@io.reactivex.annotations.NonNull ListExtractor.InfoItemsPage InfoItemsPage) -> { .subscribe((@io.reactivex.annotations.NonNull ListExtractor.InfoItemsPage InfoItemsPage) -> {
isLoading.set(false); isLoading.set(false);
handleNextItems(InfoItemsPage); handleNextItems(InfoItemsPage);
@ -148,6 +155,18 @@ public abstract class BaseListInfoFragment<I extends ListInfo>
}); });
} }
private void forbidDownwardFocusScroll() {
if (itemsList instanceof NewPipeRecyclerView) {
((NewPipeRecyclerView) itemsList).setFocusScrollAllowed(false);
}
}
private void allowDownwardFocusScroll() {
if (itemsList instanceof NewPipeRecyclerView) {
((NewPipeRecyclerView) itemsList).setFocusScrollAllowed(true);
}
}
@Override @Override
public void handleNextItems(ListExtractor.InfoItemsPage result) { public void handleNextItems(ListExtractor.InfoItemsPage result) {
super.handleNextItems(result); super.handleNextItems(result);