/** * Creates a Attacher for AbsListView implementations * * @param absListView The List for which load more functionality is needed * @param callbacks The callbacks which will receive the Load more events */ public static AbsListViewAttacher with(final AbsListView absListView, final MugenCallbacks callbacks) { return new AbsListViewAttacher(absListView, callbacks); }
/** * Creates a Attacher for RecyclerView implementations * * @param recyclerView The List for which load more functionality is needed * @param callbacks The callbacks which will receive the Load more events */ public static RecyclerViewAttacher with(final RecyclerView recyclerView, final MugenCallbacks callbacks) { return new RecyclerViewAttacher(recyclerView, callbacks); }
public RecyclerViewAttacher(final RecyclerView recyclerView, final MugenCallbacks callbacks) { super(recyclerView, callbacks); mRecyclerViewHelper = RecyclerViewPositionHelper.createHelper(recyclerView); }
mPrevFirstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition(); } else { final int firstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition(); if (firstVisibleItem > mPrevFirstVisibleItem) { final int totalItemCount = mRecyclerViewHelper.getItemCount(); final int firstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition(); final int visibleItemCount = Math.abs(mRecyclerViewHelper.findLastVisibleItemPosition() - firstVisibleItem); final int lastAdapterPosition = totalItemCount - 1; final int lastVisiblePosition = (firstVisibleItem + visibleItemCount) - 1;
/** * Returns the adapter position of the first visible view. This position does not include * adapter changes that were dispatched after the last layout pass. * * @return The adapter position of the first visible item or {@link RecyclerView#NO_POSITION} if * there aren't any visible items. */ public int findFirstVisibleItemPosition() { final View child = findOneVisibleChild(0, layoutManager.getChildCount(), false, true); return child == null ? NO_POSITION : recyclerView.getChildAdapterPosition(child); }
public static RecyclerViewPositionHelper createHelper(RecyclerView recyclerView) { if (recyclerView == null) { throw new NullPointerException("Recycler View is null"); } return new RecyclerViewPositionHelper(recyclerView); }
/** * Begin load more on the attached Adapter View * * @throws java.lang.IllegalStateException If any configuration is incorrect */ public BaseAttacher start() { if(mAdapterView == null) { throw new IllegalStateException("Adapter View cannot be null"); } if(mMugenCallbacks == null) { throw new IllegalStateException("MugenCallbacks cannot be null"); } if(mLoadMoreOffset <= 0) { throw new IllegalStateException("Trigger Offset must be > 0"); } mIsLoadMoreEnabled = true; init(); return this; }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mBaseAttacher = Mugen.with(mRecyclerView, new MugenCallbacks() { @Override public void onLoadMore() { if (currentPage <= 5) { loadData(query, language, currentPage + 1, perPage); } } @Override public boolean isLoading() { return isLoading; } @Override public boolean hasLoadedAllItems() { return false; } }).start(); }
/** * Returns the adapter position of the first fully visible view. This position does not include * adapter changes that were dispatched after the last layout pass. * * @return The adapter position of the first fully visible item or * {@link RecyclerView#NO_POSITION} if there aren't any visible items. */ public int findFirstCompletelyVisibleItemPosition() { final View child = findOneVisibleChild(0, layoutManager.getChildCount(), true, false); return child == null ? NO_POSITION : recyclerView.getChildAdapterPosition(child); }
/** * Returns the adapter position of the last visible view. This position does not include * adapter changes that were dispatched after the last layout pass. * * @return The adapter position of the last visible view or {@link RecyclerView#NO_POSITION} if * there aren't any visible items */ public int findLastVisibleItemPosition() { final View child = findOneVisibleChild(layoutManager.getChildCount() - 1, -1, false, true); return child == null ? NO_POSITION : recyclerView.getChildAdapterPosition(child); }
/** * Returns the adapter position of the last fully visible view. This position does not include * adapter changes that were dispatched after the last layout pass. * * @return The adapter position of the last fully visible view or * {@link RecyclerView#NO_POSITION} if there aren't any visible items. */ public int findLastCompletelyVisibleItemPosition() { final View child = findOneVisibleChild(layoutManager.getChildCount() - 1, -1, true, false); return child == null ? NO_POSITION : recyclerView.getChildAdapterPosition(child); }