66import android .view .View ;
77
88import androidx .annotation .NonNull ;
9+ import androidx .annotation .Nullable ;
910
1011import org .schabi .newpipe .error .ErrorInfo ;
1112import org .schabi .newpipe .error .UserAction ;
@@ -65,7 +66,7 @@ public void onResume() {
6566 super .onResume ();
6667 // Check if it was loading when the fragment was stopped/paused,
6768 if (wasLoading .getAndSet (false )) {
68- if (hasMoreItems () && infoListAdapter .getItemsList ().size () > 0 ) {
69+ if (hasMoreItems () && ! infoListAdapter .getItemsList ().isEmpty () ) {
6970 loadMoreItems ();
7071 } else {
7172 doInitialLoadLogic ();
@@ -105,6 +106,7 @@ public void readFrom(@NonNull final Queue<Object> savedObjects) throws Exception
105106 // Load and handle
106107 //////////////////////////////////////////////////////////////////////////*/
107108
109+ @ Override
108110 protected void doInitialLoadLogic () {
109111 if (DEBUG ) {
110112 Log .d (TAG , "doInitialLoadLogic() called" );
@@ -144,6 +146,7 @@ public void startLoading(final boolean forceLoad) {
144146 currentInfo = result ;
145147 currentNextPage = result .getNextPage ();
146148 handleResult (result );
149+ ifMoreItemsLoadableLoadUntilScrollable ();
147150 }, throwable ->
148151 showError (new ErrorInfo (throwable , errorUserAction ,
149152 "Start loading: " + url , serviceId )));
@@ -158,7 +161,8 @@ public void startLoading(final boolean forceLoad) {
158161 */
159162 protected abstract Single <ListExtractor .InfoItemsPage > loadMoreItemsLogic ();
160163
161- protected void loadMoreItems () {
164+ @ Override
165+ protected void loadMoreItems (@ Nullable final Runnable initialDataLoadCallback ) {
162166 isLoading .set (true );
163167
164168 if (currentWorker != null ) {
@@ -171,9 +175,12 @@ protected void loadMoreItems() {
171175 .subscribeOn (Schedulers .io ())
172176 .observeOn (AndroidSchedulers .mainThread ())
173177 .doFinally (this ::allowDownwardFocusScroll )
174- .subscribe (( @ NonNull ListExtractor . InfoItemsPage InfoItemsPage ) -> {
178+ .subscribe (infoItemsPage -> {
175179 isLoading .set (false );
176- handleNextItems (InfoItemsPage );
180+ handleNextItems (infoItemsPage );
181+ if (initialDataLoadCallback != null ) {
182+ initialDataLoadCallback .run ();
183+ }
177184 }, (@ NonNull Throwable throwable ) ->
178185 dynamicallyShowErrorPanelOrSnackbar (new ErrorInfo (throwable ,
179186 errorUserAction , "Loading more items: " + url , serviceId )));
@@ -223,7 +230,7 @@ public void handleResult(@NonNull final I result) {
223230 setTitle (name );
224231
225232 if (infoListAdapter .getItemsList ().isEmpty ()) {
226- if (result .getRelatedItems ().size () > 0 ) {
233+ if (! result .getRelatedItems ().isEmpty () ) {
227234 infoListAdapter .addInfoItemList (result .getRelatedItems ());
228235 showListFooter (hasMoreItems ());
229236 } else {
@@ -240,7 +247,7 @@ public void handleResult(@NonNull final I result) {
240247 final List <Throwable > errors = new ArrayList <>(result .getErrors ());
241248 // handling ContentNotSupportedException not to show the error but an appropriate string
242249 // so that crashes won't be sent uselessly and the user will understand what happened
243- errors .removeIf (throwable -> throwable instanceof ContentNotSupportedException );
250+ errors .removeIf (ContentNotSupportedException . class :: isInstance );
244251
245252 if (!errors .isEmpty ()) {
246253 dynamicallyShowErrorPanelOrSnackbar (new ErrorInfo (result .getErrors (),
0 commit comments