@@ -0,0 +1,2943 @@
+package com.setiawanpaiman.sunnyreader.ui.widget;%0A%0Aimport android.content.Context;%0Aimport android.support.v7.widget.LinearLayoutManager;%0Aimport android.support.v7.widget.RecyclerView;%0Aimport android.util.AttributeSet;%0A%0Aimport com.setiawanpaiman.sunnyreader.ui.adapter.EndlessListAdapter;%0A%0Apublic class EndlessRecyclerView extends RecyclerView %7B%0A%0A    private int mPreviousTotal = 0;%0A%0A    private boolean mLoading = false;%0A%0A    private EndlessListAdapter mEndlessListAdapter;%0A%0A    private OnLoadMoreListener mOnLoadMoreListener = null;%0A%0A    private OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() %7B%0A        @Override%0A        public void onScrolled(RecyclerView recyclerView, int dx, int dy) %7B%0A            LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();%0A            if (layoutManager == null %7C%7C mOnLoadMoreListener == null) %7B%0A                return;%0A            %7D%0A%0A            int visibleItemCount = layoutManager.getChildCount();%0A            int totalItemCount = layoutManager.getItemCount();%0A            int pastVisibleItems = layoutManager.findFirstVisibleItemPosition();%0A//            boolean nextPageAvailable =%0A//                    mEndlessListAdapter == null %7C%7C mEndlessListAdapter.isNextPageAvailable();%0A%0A            if (mLoading && mPreviousTotal != totalItemCount) %7B%0A                mLoading = false;%0A                mPreviousTotal = totalItemCount;%0A            %7D%0A%0A            if (!mLoading && (visibleItemCount + pastVisibleItems) %3E= totalItemCount) %7B%0A                mLoading = true;%0A                mPreviousTotal = totalItemCount;%0A                mOnLoadMoreListener.onLoadMore();%0A            %7D%0A        %7D%0A    %7D;%0A%0A    public EndlessRecyclerView(Context context) %7B%0A        super(context);%0A        init();%0A    %7D%0A%0A    public EndlessRecyclerView(Context context, AttributeSet attrs) %7B%0A        super(context, attrs);%0A        init();%0A    %7D%0A%0A    public EndlessRecyclerView(Context context, AttributeSet attrs, int defStyle) %7B%0A        super(context, attrs, defStyle);%0A        init();%0A    %7D%0A%0A    @Override%0A    public void setAdapter(Adapter adapter) %7B%0A        super.setAdapter(adapter);%0A        setEndlessListAdapter(adapter);%0A    %7D%0A%0A    public void enableLoadMore() %7B%0A        mPreviousTotal = Integer.MIN_VALUE;%0A        mLoading = true;%0A    %7D%0A%0A    public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) %7B%0A        mOnLoadMoreListener = onLoadMoreListener;%0A    %7D%0A%0A    private void setLoadMoreScrollListener() %7B%0A        removeOnScrollListener(mOnScrollListener);%0A        addOnScrollListener(mOnScrollListener);%0A    %7D%0A%0A    private void setEndlessListAdapter(Adapter adapter) %7B%0A        if (adapter instanceof EndlessListAdapter) %7B%0A            mEndlessListAdapter = (EndlessListAdapter) adapter;%0A        %7D%0A    %7D%0A%0A    private void init() %7B%0A        setLoadMoreScrollListener();%0A    %7D%0A%0A    public interface OnLoadMoreListener %7B%0A%0A        void onLoadMore();%0A    %7D%0A%7D

Implement EndlessRecyclerView