Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
/**
* Created by rajanmaurya on 16/4/2016.
*/

public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static final String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();
int firstVisibleItem, visibleItemCount, totalItemCount;
private int firstVisibleItem, visibleItemCount, totalItemCount;
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to
// load.
Expand All @@ -28,6 +29,11 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

visibleItemCount = recyclerView.getChildCount();
totalItemCount = mLinearLayoutManager.getItemCount();

// If user refreshed a layout
if (previousTotal > totalItemCount) {
previousTotal = 0;
}
firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

if (loading && (totalItemCount > previousTotal + 1)) {
Expand All @@ -38,7 +44,6 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem +
visibleThreshold)) {
// End has been reached
// Do something
current_page++;
onLoadMore(current_page);
loading = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public void onScrolled(RecyclerView view, int dx, int dy) {
this.previousTotalItemCount = totalItemCount;
if (totalItemCount == 0) {
this.loading = true;
} else {
this.loading = false;
}
}
// If it’s still loading, we check to see if the dataset count has
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.adapters.ClientNameListAdapter;
import com.mifos.mifosxdroid.core.EndlessRecyclerOnScrollListener;
import com.mifos.mifosxdroid.core.EndlessRecyclerViewScrollListener;
import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.core.MifosBaseFragment;
import com.mifos.mifosxdroid.core.RecyclerItemClickListener;
Expand Down Expand Up @@ -188,10 +188,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
* This is the LoadMore of the RecyclerView. It called When Last Element of RecyclerView
* is shown on the Screen.
*/
rv_clients.addOnScrollListener(new EndlessRecyclerOnScrollListener(mLayoutManager) {
rv_clients.addOnScrollListener(new EndlessRecyclerViewScrollListener(mLayoutManager) {
@Override
public void onLoadMore(int current_page) {
mClientListPresenter.loadClients(true, clientList.size());
public void onLoadMore(int page, int totalItemCount) {
mClientListPresenter.loadClients(true, totalItemCount);
}
});

Expand Down