Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public abstract class PaginationScrollListener extends RecyclerView.OnScrollListener {
  2.  
  3. private int previousTotalItemCount = 0;
  4. private boolean loading = true;
  5.  
  6. @Override
  7. public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  8. super.onScrollStateChanged(recyclerView, newState);
  9. }
  10.  
  11. @Override
  12. public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  13. super.onScrolled(recyclerView, dx, dy);
  14. //we don't interested in scroll up
  15. if (dy <= 0) {
  16. return;
  17. }
  18.  
  19. LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
  20. int totalItemCount = layoutManager.getItemCount();
  21. int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
  22.  
  23. if (loading && totalItemCount > previousTotalItemCount) {
  24. loading = false;
  25. previousTotalItemCount = totalItemCount;
  26. }
  27.  
  28. if (!loading && lastVisibleItemPosition == (totalItemCount - 1)) {
  29. loading = true;
  30. loadMore();
  31. }
  32. }
  33.  
  34. public abstract void loadMore();
  35. }
Add Comment
Please, Sign In to add comment