Skip to content

Commit

Permalink
Merge pull request #559 from TypicalGitHubUser/scrolling-bug-fix
Browse files Browse the repository at this point in the history
fix: LoadMore not working at one case. (#300)
  • Loading branch information
therajanmaurya authored Mar 14, 2017
2 parents 3f11163 + f5042b2 commit 5b61e1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit 5b61e1e

Please sign in to comment.