Java Code Examples for androidx.recyclerview.widget.LinearLayoutManager#findLastVisibleItemPosition()
The following examples show how to use
androidx.recyclerview.widget.LinearLayoutManager#findLastVisibleItemPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectionHandler.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void changeSelectionOfRecyclerView(CellRecyclerView recyclerView, AbstractViewHolder .SelectionState selectionState, @ColorInt int backgroundColor) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView .getLayoutManager(); for (int i = linearLayoutManager.findFirstVisibleItemPosition(); i < linearLayoutManager .findLastVisibleItemPosition() + 1; i++) { AbstractViewHolder viewHolder = (AbstractViewHolder) recyclerView .findViewHolderForAdapterPosition(i); if (viewHolder != null) { if (!mTableView.isIgnoreSelectionColors()) { // Change background color viewHolder.setBackgroundColor(backgroundColor); } // Change selection status of the view holder viewHolder.setSelected(selectionState); } } }
Example 2
Source File: ConversationFragment.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
private void manageMessageSeenState() { LinearLayoutManager layoutManager = (LinearLayoutManager)list.getLayoutManager(); int firstPos = layoutManager.findFirstVisibleItemPosition(); int lastPos = layoutManager.findLastVisibleItemPosition(); if(firstPos == RecyclerView.NO_POSITION || lastPos == RecyclerView.NO_POSITION) { return; } int[] ids = new int[lastPos - firstPos + 1]; int index = 0; for(int pos = firstPos; pos <= lastPos; pos++) { DcMsg message = ((ConversationAdapter) list.getAdapter()).getMsg(pos); if (message.getFromId() != DC_CONTACT_ID_SELF && !message.isSeen()) { ids[index] = message.getId(); index++; } } dcContext.markseenMsgs(ids); }
Example 3
Source File: SelectionHandler.java From TableView with MIT License | 6 votes |
public void changeSelectionOfRecyclerView(CellRecyclerView recyclerView, @NonNull AbstractViewHolder .SelectionState selectionState, @ColorInt int backgroundColor) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView .getLayoutManager(); for (int i = linearLayoutManager.findFirstVisibleItemPosition(); i < linearLayoutManager .findLastVisibleItemPosition() + 1; i++) { AbstractViewHolder viewHolder = (AbstractViewHolder) recyclerView .findViewHolderForAdapterPosition(i); if (viewHolder != null) { if (!mTableView.isIgnoreSelectionColors()) { // Change background color viewHolder.setBackgroundColor(backgroundColor); } // Change selection status of the view holder viewHolder.setSelected(selectionState); } } }
Example 4
Source File: HorizontalRecyclerViewListener.java From TableView with MIT License | 6 votes |
/** * This method calculates the current scroll position and its offset to help new attached * recyclerView on window at that position and offset * * @see #getScrollPosition() * @see #getScrollPositionOffset() */ private void renewScrollPosition(@NonNull RecyclerView recyclerView) { LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); mScrollPosition = layoutManager.findFirstCompletelyVisibleItemPosition(); // That means there is no completely visible Position. if (mScrollPosition == -1) { mScrollPosition = layoutManager.findFirstVisibleItemPosition(); // That means there is just a visible item on the screen if (mScrollPosition == layoutManager.findLastVisibleItemPosition()) { // in this case we use the position which is the last & first visible item. } else { // That means there are 2 visible item on the screen. However, second one is not // completely visible. mScrollPosition = mScrollPosition + 1; } } mScrollPositionOffset = layoutManager.findViewByPosition(mScrollPosition).getLeft(); }
Example 5
Source File: MessagesActivity.java From android with MIT License | 6 votes |
@Override public void onScrolled(RecyclerView view, int dx, int dy) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) view.getLayoutManager(); if (linearLayoutManager != null) { int lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition(); int totalItemCount = view.getAdapter().getItemCount(); if (lastVisibleItem > totalItemCount - 15 && totalItemCount != 0 && messages.canLoadMore(appId)) { if (!isLoadMore) { isLoadMore = true; new LoadMore().execute(appId); } } } }
Example 6
Source File: BookmarksView.java From FirefoxReality with Mozilla Public License 2.0 | 6 votes |
@Override public void onMore(@NonNull View view, @NonNull Bookmark item) { mBinding.bookmarksList.requestFocusFromTouch(); int rowPosition = mBookmarkAdapter.getItemPosition(item.getGuid()); RecyclerView.ViewHolder row = mBinding.bookmarksList.findViewHolderForLayoutPosition(rowPosition); boolean isLastVisibleItem = false; if (mBinding.bookmarksList.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.bookmarksList.getLayoutManager(); int lastItem = mBookmarkAdapter.getItemCount(); if ((rowPosition == layoutManager.findLastVisibleItemPosition() || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() || rowPosition == layoutManager.findLastVisibleItemPosition()-1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition()-1) && rowPosition != lastItem) { isLastVisibleItem = true; } } mBinding.getCallback().onShowContextMenu( row.itemView, item, isLastVisibleItem); }
Example 7
Source File: DownloadsView.java From FirefoxReality with Mozilla Public License 2.0 | 6 votes |
@Override public void onMore(@NonNull View view, @NonNull Download item) { mBinding.downloadsList.requestFocusFromTouch(); int rowPosition = mDownloadsAdapter.getItemPosition(item.getId()); RecyclerView.ViewHolder row = mBinding.downloadsList.findViewHolderForLayoutPosition(rowPosition); boolean isLastVisibleItem = false; if (mBinding.downloadsList.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.downloadsList.getLayoutManager(); int lastItem = mDownloadsAdapter.getItemCount(); if ((rowPosition == layoutManager.findLastVisibleItemPosition() || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() || rowPosition == layoutManager.findLastVisibleItemPosition() - 1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() - 1) && ((rowPosition == (lastItem - 1)) && rowPosition > 2)) { isLastVisibleItem = true; } } if (row != null) { mBinding.getCallback().onShowContextMenu( row.itemView, item, isLastVisibleItem); } }
Example 8
Source File: HistoryView.java From FirefoxReality with Mozilla Public License 2.0 | 6 votes |
@Override public void onMore(View view, VisitInfo item) { mBinding.historyList.requestFocusFromTouch(); int rowPosition = mHistoryAdapter.getItemPosition(item.getVisitTime()); RecyclerView.ViewHolder row = mBinding.historyList.findViewHolderForLayoutPosition(rowPosition); boolean isLastVisibleItem = false; if (mBinding.historyList.getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.historyList.getLayoutManager(); int lastItem = mHistoryAdapter.getItemCount(); if ((rowPosition == layoutManager.findLastVisibleItemPosition() || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() || rowPosition == layoutManager.findLastVisibleItemPosition() - 1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() - 1) && (rowPosition != lastItem && rowPosition > 2)) { isLastVisibleItem = true; } } if (row != null) { mBinding.getCallback().onShowContextMenu( row.itemView, item, isLastVisibleItem); } }
Example 9
Source File: HorizontalRecyclerViewListener.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method calculates the current scroll position and its offset to help new attached * recyclerView on window at that position and offset * * @see #getScrollPosition() * @see #getScrollPositionOffset() */ private void renewScrollPosition(RecyclerView recyclerView) { LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); mScrollPosition = layoutManager.findFirstCompletelyVisibleItemPosition(); // That means there is no completely visible Position. if (mScrollPosition == -1) { mScrollPosition = layoutManager.findFirstVisibleItemPosition(); // That means there is just a visible item on the screen if (mScrollPosition == layoutManager.findLastVisibleItemPosition()) { // in this case we use the position which is the last & first visible item. } else { // That means there are 2 visible item on the screen. However, second one is not // completely visible. mScrollPosition = mScrollPosition + 1; } } mScrollPositionOffset = layoutManager.findViewByPosition(mScrollPosition).getLeft(); }
Example 10
Source File: BaseRecyclerAdapter.java From NewFastFrame with Apache License 2.0 | 5 votes |
private void notifyLoadMoreChanged() { if (data.size() == 0) { // 数据为空的时候不要显示脚步布局 if (mLoadMoreFooterContainer!=null&&mLoadMoreFooterContainer.getChildAt(0) instanceof LoadMoreFooterView) { ((LoadMoreFooterView) mLoadMoreFooterContainer.getChildAt(0)).setStatus(LoadMoreFooterView.Status.GONE); } return; } if (hasMoreLoadView()) { int lastVisiblePosition; if (layoutManager instanceof LinearLayoutManager) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; lastVisiblePosition = linearLayoutManager.findLastVisibleItemPosition(); } else { StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) layoutManager; lastVisiblePosition = gridLayoutManager.findLastVisibleItemPositions(null)[0]; } int position; position = getItemUpCount() + getData().size(); if (lastVisiblePosition == 0 && getData().size() > 0) { lastVisiblePosition+=getData().size(); } if (lastVisiblePosition != -1 && lastVisiblePosition == position) { if (mLoadMoreFooterContainer.getChildAt(0) instanceof LoadMoreFooterView) { ((LoadMoreFooterView) mLoadMoreFooterContainer.getChildAt(0)).setStatus(LoadMoreFooterView.Status.THE_END); } } } }
Example 11
Source File: HorizontalScrollCompat.java From SmoothRefreshLayout with MIT License | 5 votes |
public static boolean canAutoLoadMore(View view) { if (ViewCatcherUtil.isRecyclerView(view)) { RecyclerView recyclerView = (RecyclerView) view; RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager == null) { return false; } int lastVisiblePosition = 0; if (manager instanceof LinearLayoutManager) { LinearLayoutManager linearManager = ((LinearLayoutManager) manager); if (linearManager.getOrientation() != RecyclerView.HORIZONTAL) { return false; } lastVisiblePosition = linearManager.findLastVisibleItemPosition(); } else if (manager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager; if (gridLayoutManager.getOrientation() != RecyclerView.HORIZONTAL) { return false; } int[] lastPositions = new int[gridLayoutManager.getSpanCount()]; gridLayoutManager.findLastVisibleItemPositions(lastPositions); for (int value : lastPositions) { if (value > lastVisiblePosition) { lastVisiblePosition = value; } } } RecyclerView.Adapter adapter = recyclerView.getAdapter(); return adapter != null && adapter.getItemCount() > 0 && lastVisiblePosition >= 0 && lastVisiblePosition >= adapter.getItemCount() - 1; } return false; }
Example 12
Source File: AsyncAdapter.java From financisto with GNU General Public License v2.0 | 5 votes |
@Override public void getItemRangeInto(int[] outRange) { if (outRange == null) { return; } if(recyclerView.getLayoutManager() instanceof LinearLayoutManager){ LinearLayoutManager llm = (LinearLayoutManager) recyclerView.getLayoutManager(); outRange[0] = llm.findFirstVisibleItemPosition(); outRange[1] = llm.findLastVisibleItemPosition(); } if (outRange[0] == -1 && outRange[1] == -1) { outRange[0] = 0; outRange[1] = 0; } }
Example 13
Source File: HomeFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@UiThread @Override public void scrollToTop() { LinearLayoutManager layoutManager = ((LinearLayoutManager) bundlesList.getLayoutManager()); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); if (lastVisibleItemPosition > 10) { bundlesList.scrollToPosition(10); } bundlesList.smoothScrollToPosition(0); }
Example 14
Source File: AppsFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@UiThread @Override public void scrollToTop() { LinearLayoutManager layoutManager = ((LinearLayoutManager) appsRecyclerView.getLayoutManager()); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); if (lastVisibleItemPosition > 10) { appsRecyclerView.scrollToPosition(10); } appsRecyclerView.smoothScrollToPosition(0); }
Example 15
Source File: SearchResultFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@Override public void scrollToTop() { RecyclerView list; if (followedStoresResultList.getVisibility() == View.VISIBLE) { list = followedStoresResultList; } else { list = allStoresResultList; } LinearLayoutManager layoutManager = ((LinearLayoutManager) list.getLayoutManager()); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); if (lastVisibleItemPosition > 10) { list.scrollToPosition(10); } list.smoothScrollToPosition(0); }
Example 16
Source File: MoreBundleFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@UiThread @Override public void scrollToTop() { LinearLayoutManager layoutManager = ((LinearLayoutManager) bundlesList.getLayoutManager()); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); if (lastVisibleItemPosition > 10) { bundlesList.scrollToPosition(10); } bundlesList.smoothScrollToPosition(0); }
Example 17
Source File: MyStoresFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@Override @UiThread public void scrollToTop() { RecyclerView view = getRecyclerView(); LinearLayoutManager layoutManager = ((LinearLayoutManager) view.getLayoutManager()); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); if (lastVisibleItemPosition > 10) { view.scrollToPosition(10); } view.smoothScrollToPosition(0); }
Example 18
Source File: ZoomableRecyclerView.java From Hentoid with Apache License 2.0 | 5 votes |
@Override public void onScrolled(int dx, int dy) { super.onScrolled(dx, dy); LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager(); if (layoutManager != null) { lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); } }
Example 19
Source File: SearchResultFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 4 votes |
private boolean isEndReached(RecyclerViewScrollEvent event) { final LinearLayoutManager layoutManager = (LinearLayoutManager) event.view() .getLayoutManager(); return layoutManager.getItemCount() - layoutManager.findLastVisibleItemPosition() <= VISIBLE_THRESHOLD; }
Example 20
Source File: ScrollPositionListener.java From Hentoid with Apache License 2.0 | 4 votes |
@Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (!Preferences.isViewerSwipeToTurn() || !isScrollEnabled) { recyclerView.stopScroll(); return; } LinearLayoutManager llm = (LinearLayoutManager) recyclerView.getLayoutManager(); if (llm != null) { if (RecyclerView.SCROLL_STATE_DRAGGING == newState) { dragStartPositionX = recyclerView.computeHorizontalScrollOffset(); dragStartPositionY = recyclerView.computeVerticalScrollOffset(); isSettlingX = false; isSettlingY = false; } else if (RecyclerView.SCROLL_STATE_SETTLING == newState) { // If the settling position is different from the original position, ignore that scroll // (e.g. snapping back to the original position after a small scroll) if (recyclerView.computeHorizontalScrollOffset() != dragStartPositionX) isSettlingX = true; if (recyclerView.computeVerticalScrollOffset() != dragStartPositionY) isSettlingY = true; } else if (RecyclerView.SCROLL_STATE_IDLE == newState) { // Don't do anything if we're not on a boundary if (!(llm.findLastVisibleItemPosition() == llm.getItemCount() - 1 || 0 == llm.findFirstVisibleItemPosition())) return; if (recyclerView.computeHorizontalScrollOffset() == dragStartPositionX && !isSettlingX && llm.canScrollHorizontally()) { if (0 == dragStartPositionX && !llm.getReverseLayout()) onStartOutOfBoundScroll.run(); else if (0 == dragStartPositionX) onEndOutOfBoundScroll.run(); else if (llm.getReverseLayout()) onStartOutOfBoundScroll.run(); else onEndOutOfBoundScroll.run(); } if (recyclerView.computeVerticalScrollOffset() == dragStartPositionY && !isSettlingY && llm.canScrollVertically()) { if (0 == dragStartPositionY && !llm.getReverseLayout()) onStartOutOfBoundScroll.run(); else if (0 == dragStartPositionY) onEndOutOfBoundScroll.run(); else if (llm.getReverseLayout()) onStartOutOfBoundScroll.run(); else onEndOutOfBoundScroll.run(); } } } }