Skip to content

Commit 85f701b

Browse files
committed
Fixed listener not re-registering after e.g. a new search is started
1 parent ff7cfe4 commit 85f701b

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,28 +304,36 @@ public void selected(final PlaylistInfoItem selectedItem) {
304304
}
305305
});
306306

307-
infoListAdapter.setOnCommentsSelectedListener(new OnClickGesture<CommentsInfoItem>() {
307+
infoListAdapter.setOnCommentsSelectedListener(new OnClickGesture<>() {
308308
@Override
309309
public void selected(final CommentsInfoItem selectedItem) {
310310
onItemSelected(selectedItem);
311311
}
312312
});
313+
}
313314

315+
/**
316+
* Remove all listeners and add the initial scroll listener to the {@link #itemsList}.
317+
* <br/>
318+
* Which tries to load more items when not enough are in the view (not scrollable)
319+
* and more are available.
320+
* <br/>
321+
* Note: This method only works because "This callback will also be called if visible
322+
* item range changes after a layout calculation. In that case, dx and dy will be 0."
323+
* - which might be unexpected because no actual scrolling occurs...
324+
* <br/>
325+
* This listener will be replaced by DefaultItemListOnScrolledDownListener when
326+
* <ul>
327+
* <li>the view was actually scrolled</li>
328+
* <li>the view is scrollable</li>
329+
* <li>no more items can be loaded</li>
330+
* </ul>
331+
*/
332+
protected void setItemsListInitialScrollListener() {
333+
if (DEBUG) {
334+
Log.d(TAG, "setItemsListInitialScrollListener called");
335+
}
314336
itemsList.clearOnScrollListeners();
315-
316-
/*
317-
* Add initial scroll listener - which tries to load more items when not enough
318-
* are in the view (not scrollable) and more are available.
319-
*
320-
* Note: This method only works because "This callback will also be called if visible
321-
* item range changes after a layout calculation. In that case, dx and dy will be 0."
322-
* - which might be unexpected because no actual scrolling occurs...
323-
*
324-
* This listener will be replaced by DefaultItemListOnScrolledDownListener when
325-
* * the view was actually scrolled
326-
* * the view is scrollable
327-
* * No more items can be loaded
328-
*/
329337
itemsList.addOnScrollListener(new DefaultItemListOnScrolledDownListener() {
330338
@Override
331339
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
@@ -360,7 +368,6 @@ public void onScrolled(final RecyclerView recyclerView, final int dx, final int
360368
}
361369

362370
private void useNormalScrollListener() {
363-
log("Unregistering and using normal listener");
364371
itemsList.removeOnScrollListener(this);
365372
itemsList.addOnScrollListener(new DefaultItemListOnScrolledDownListener());
366373
}
@@ -467,6 +474,12 @@ public void onCreateOptionsMenu(@NonNull final Menu menu,
467474
// Load and handle
468475
//////////////////////////////////////////////////////////////////////////*/
469476

477+
@Override
478+
protected void startLoading(final boolean forceLoad) {
479+
setItemsListInitialScrollListener();
480+
super.startLoading(forceLoad);
481+
}
482+
470483
protected abstract void loadMoreItems();
471484

472485
protected abstract boolean hasMoreItems();

0 commit comments

Comments
 (0)