question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

return true on hasLoadedAllItems not working

See original GitHub issue

I have the following code and loading row is still showing. Why?

@Override
   public void onLoadMore() {
       Log.d("EncryptionPager","onLoadMore");

   }

   @Override
   public boolean isLoading() {
       Log.d("EncryptionPager","isLoading");
       return false;
   }

   @Override
   public boolean hasLoadedAllItems() {
       Log.d("EncryptionPager","hasLoadedAllItems");
       return true;
   }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
4lfantcommented, Mar 3, 2017

Loading row hides only when setHasMoreDataToLoad() method is called.

From RecyclerPaginate.java:

@Override
public void setHasMoreDataToLoad(boolean hasMoreDataToLoad) {
        if (wrapperAdapter != null) {
        wrapperAdapter.displayLoadingRow(hasMoreDataToLoad);
    }
}

The problem is that method is only called when adapter data is changed.

So there are two solutions:

  1. When all data is loaded and you want to hide the loading row, get the hasLoadedAllItems() to return true and after this notify the adapter by calling adapter.notifyDataSetChanged();
private class PaginateCallbacks implements Paginate.Callbacks {
        private boolean loading = false;
        private boolean loadedAll = false;

        @Override
        public void onLoadMore() {
            loading = true;
            RetrofitService.getClient().getData()
            .enqueue(new Callback<Data>() {
                        @Override
                        public void onResponse(Call<Data> call, Response<Data> response) {
                            if (response.isSuccessful()) {
                                if (response.body().isEmpty()) {
                                    loadedAll = true;
                                    adapter.notifyDataSetChanged();
                                    return;
                                }
                                data.addAll(response.body());
                                if (response.body().size() < DATA_PORTION_SIZE) {
                                    loadedAll = true;
                                }
                                adapter.notifyDataSetChanged();
                                loading = false;
                            } else {
                                Log.e(TAG, response.errorBody().toString());
                            }
                        }
                        @Override
                        public void onFailure(Call<Data> call, Throwable t) {
                              t.printStackTrace();
                        }
                    });
        }

        @Override
        public boolean isLoading() {
            return loading;
        }

        @Override
        public boolean hasLoadedAllItems() {
            return loadedAll;
        }
}
  1. Or manually hide the loading row by calling paginate.setHasMoreDataToLoad(false);
Paginate paginate = Paginate.with(recyclerView, new PaginateCallbacks())
                .setLoadingTriggerThreshold(0)
                .addLoadingListItem(true)
                .build();

And then in callbacks:

private class PaginateCallbacks implements Paginate.Callbacks {
        private boolean loading = false;

        @Override
        public void onLoadMore() {
            loading = true;
            RetrofitService.getClient().getData()
            .enqueue(new Callback<Data>() {
                        @Override
                        public void onResponse(Call<Data> call, Response<Data> response) {
                            if (response.isSuccessful()) {
                                if (response.body().isEmpty()) {
                                    paginate.setHasMoreDataToLoad(false);
                                    return;
                                }
                                data.addAll(response.body());
                                loading = false;
                                if (response.body().size() < DATA_PORTION_SIZE) {
                                    paginate.setHasMoreDataToLoad(false);
                                }
                            } else {
                                Log.e(TAG, response.errorBody().toString());
                            }
                        }
                        @Override
                        public void onFailure(Call<Data> call, Throwable t) {
                              t.printStackTrace();
                        }
                    });
        }

        @Override
        public boolean isLoading() {
            return loading;
        }

        @Override
        public boolean hasLoadedAllItems() {
            return false;
        }
    }
0reactions
MarkoMiloscommented, Sep 23, 2020

This has been resolved as a part of the latest release (check out release 1.0.0)

I’m closing this MR, feel free to reopen if you still experiencing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

It's been while but I think if hasLoadedAllItems returns true then the ...
It's been while but I think if hasLoadedAllItems returns true then the library wouldn't add a loading item at the bottom of the...
Read more >
Return true or false not working in JavaScript - Stack Overflow
The problem here is that you are getting the return value of outer , but outer doesn't return anything. return true (or false...
Read more >
Scroll Views - Paginate - The Android Arsenal
For a working implementation of this project see the ... Indicate whether all data (pages) are loaded or not return hasLoadedAllItems; } };....
Read more >
com.paginate.Paginate Maven / Gradle / Ivy
@return true if loading is currently in progress, false otherwise. ... boolean hasLoadedAllItems(); } /** * Use this method to indicate that there...
Read more >
About RecyclerView in Android
... loading or not } @Override public boolean hasLoadedAllItems() { return currentPage == totalPages; // if all pages are loaded return true } ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found