1 package com.moiseum.wolnelektury.components.recycler;
4 * Created by Piotr Ostrowski on 28.11.2017.
7 import android.support.v7.widget.LinearLayoutManager;
8 import android.support.v7.widget.RecyclerView;
10 public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
12 public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();
15 * The total number of items in the dataset after the last load
17 private int mPreviousTotal = 0;
19 * True if we are still waiting for the last set of data to load.
21 private boolean mLoading = true;
24 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
25 super.onScrolled(recyclerView, dx, dy);
27 int visibleItemCount = recyclerView.getChildCount();
28 int totalItemCount = recyclerView.getLayoutManager().getItemCount();
29 int firstVisibleItem = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
32 if (totalItemCount > mPreviousTotal) {
34 mPreviousTotal = totalItemCount;
37 int visibleThreshold = 5;
38 if (!mLoading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
39 // End has been reached
49 public abstract void onLoadMore();