Created
February 6, 2015 08:18
Revisions
-
lidemin created this gist
Feb 6, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ public class DLRecyclerView extends RecyclerView { public interface OnScrollListener { /** * only works when layoutmanager is LinearLayoutManager */ public abstract void onScrollToEnd(); } private OnScrollListener _onScrollListener; public void setOnScrollListener(OnScrollListener onScrollListener) { _onScrollListener = onScrollListener; } public DLRecyclerView(Context context) { super(context); init(); } public DLRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public DLRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private boolean _loading = false; int pastVisibleItems, visibleItemCount, totalItemCount; public boolean isLoading() { return _loading; } public void setLoading(boolean loading) { this._loading = loading; } private void init() { if (!isInEditMode()) { setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (getLayoutManager() instanceof LinearLayoutManager) { visibleItemCount = getLayoutManager().getChildCount(); totalItemCount = getLayoutManager().getItemCount(); pastVisibleItems = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition(); if (!_loading) { if ((visibleItemCount + pastVisibleItems) >= totalItemCount) { _loading = true; if (_onScrollListener != null) { _onScrollListener.onScrollToEnd(); } } } } } }); } } }