Skip to content

Instantly share code, notes, and snippets.

@sonvp
Last active July 5, 2016 08:30
Show Gist options
  • Save sonvp/3d71f0da5c9e80c0cdd753d473e14902 to your computer and use it in GitHub Desktop.
Save sonvp/3d71f0da5c9e80c0cdd753d473e14902 to your computer and use it in GitHub Desktop.
Base on swipeRefreshLayoutRecyclerView.java of Mandhor . I fixed bug SwipeRefreshLayout catches scroll up too early - not on top of the list when use with recyclerview. But in some cases It disable SwipeRefreshLayout I can't scroll up . I fixed it with code below
public class SwipeRefreshLayoutToggleScrollListener extends RecyclerView.OnScrollListener {
private int overallYScroll = 0;
private GeneralSwipeRefreshLayout mSwipeLayout;
public SwipeRefreshLayoutToggleScrollListener(GeneralSwipeRefreshLayout swipeLayout) {
mSwipeLayout = swipeLayout;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
overallYScroll = overallYScroll + dy;
if (overallYScroll <= 0) {
//enable swipeRefreshLayout
mSwipeLayout.setEnabled(true);
} else {
//disable
mSwipeLayout.setEnabled(false);
}
}
}
....
///Refresh RecyclerView.OnScrollListener
private void initRefreshingListener() {
if (swipeRefreshLayout != null) {
if (listener != null) {
recyclerView.removeOnScrollListener(listener);
}
swipeRefreshLayout.setEnabled(true);
listener = new SwipeRefreshLayoutToggleScrollListener(swipeRefreshLayout);
recyclerView.addOnScrollListener(listener);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment