Java Code Examples for androidx.recyclerview.widget.RecyclerView#NO_POSITION
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#NO_POSITION .
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: ChannelAdminLogActivity.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void checkScrollForLoad(boolean scroll) { if (chatLayoutManager == null || paused) { return; } int firstVisibleItem = chatLayoutManager.findFirstVisibleItemPosition(); int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(chatLayoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; if (visibleItemCount > 0) { int totalItemCount = chatAdapter.getItemCount(); int checkLoadCount; if (scroll) { checkLoadCount = 25; } else { checkLoadCount = 5; } if (firstVisibleItem <= checkLoadCount && !loading && !endReached) { loadMessages(false); } } }
Example 2
Source File: LibraryFragment.java From Hentoid with Apache License 2.0 | 6 votes |
@Override public void itemSwiped(int position, int direction) { ContentItem item = getItemAdapter().getAdapterItem(position); item.setSwipeDirection(direction); if (item.getContent() != null) { Debouncer<ContentItem> deleteDebouncer = new Debouncer<>(2000, this::onDeleteSwipedBook); deleteDebouncer.submit(item); Runnable cancelSwipe = () -> { deleteDebouncer.clear(); item.setSwipeDirection(0); int position1 = getItemAdapter().getAdapterPosition(item); if (position1 != RecyclerView.NO_POSITION) fastAdapter.notifyItemChanged(position1); }; item.setUndoSwipeAction(cancelSwipe); fastAdapter.notifyItemChanged(position); } }
Example 3
Source File: ErrorsFragment.java From Hentoid with Apache License 2.0 | 6 votes |
@Override public void itemSwiped(int position, int direction) { ContentItem item = itemAdapter.getAdapterItem(position); item.setSwipeDirection(direction); if (item.getContent() != null) { Debouncer<Content> deleteDebouncer = new Debouncer<>(2000, this::onDeleteBook); deleteDebouncer.submit(item.getContent()); Runnable cancelSwipe = () -> { deleteDebouncer.clear(); item.setSwipeDirection(0); int position1 = itemAdapter.getAdapterPosition(item); if (position1 != RecyclerView.NO_POSITION) fastAdapter.notifyItemChanged(position1); }; item.setUndoSwipeAction(cancelSwipe); fastAdapter.notifyItemChanged(position); } }
Example 4
Source File: FocusDelegate.java From FairEmail with GNU General Public License v3.0 | 6 votes |
static <K> FocusDelegate<K> dummy() { return new FocusDelegate<K>() { @Override public void focusItem(@NonNull ItemDetails<K> item) { } @Override public boolean hasFocusedItem() { return false; } @Override public int getFocusedPosition() { return RecyclerView.NO_POSITION; } @Override public void clearFocus() { } }; }
Example 5
Source File: AdapterNavFolder.java From FairEmail with GNU General Public License v3.0 | 6 votes |
@Override public void onClick(View v) { int pos = getAdapterPosition(); if (pos == RecyclerView.NO_POSITION) return; TupleFolderNav folder = items.get(pos); if (folder == null) return; LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_MESSAGES) .putExtra("account", folder.account) .putExtra("folder", folder.id) .putExtra("type", folder.type)); }
Example 6
Source File: ExpandableStickyDecoration.java From OmegaRecyclerView with MIT License | 5 votes |
private int calculateGroupOffset(RecyclerView parent, long currentHeaderId, int nextPosition) { if (mExpandableAdapter == null) return 0; int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(nextPosition)); if (adapterPosHere != RecyclerView.NO_POSITION) { long nextId = mExpandableAdapter.getGroupUniqueId(adapterPosHere); if (nextId != currentHeaderId && nextId != NO_STICKY_ID) { View next = parent.getChildAt(nextPosition); RecyclerView.ViewHolder viewHolder = getGroupHeader(parent, adapterPosHere); if (viewHolder == null) return OFFSET_NOT_FOUND; return (int) next.getY() - viewHolder.itemView.getHeight(); } } return OFFSET_NOT_FOUND; }
Example 7
Source File: PermissionGroupAdapter.java From AppOpsX with MIT License | 5 votes |
@Override public void onClick(View v) { Object tag = v.getTag(); if (tag instanceof RecyclerView.ViewHolder) { int flatPosition = ((RecyclerView.ViewHolder) v.getTag()).getAdapterPosition(); if (flatPosition == RecyclerView.NO_POSITION) { return; } long expandablePosition = mExpandableItemManager.getExpandablePosition(flatPosition); int groupPosition = RecyclerViewExpandableItemManager .getPackedPositionGroup(expandablePosition); // int childPosition = RecyclerViewExpandableItemManager // .getPackedPositionChild(expandablePosition); switch (v.getId()) { case R.id.layout_group_item: // toggle expanded/collapsed if (mExpandableItemManager.isGroupExpanded(groupPosition)) { mExpandableItemManager.collapseGroup(groupPosition); } else { mExpandableItemManager.expandGroup(groupPosition); } break; case R.id.img_menu_ups: if (mOnGroupOtherClickListener != null) { mOnGroupOtherClickListener.onOtherClick(groupPosition, v); } break; } } if (v.getTag() instanceof ChildViewHolder) { ((ChildViewHolder) v.getTag()).switchCompat.toggle(); } }
Example 8
Source File: RecyclerViewHelper.java From AndroidFastScroll with Apache License 2.0 | 5 votes |
@Override public int getScrollOffset() { int firstItemPosition = getFirstItemPosition(); if (firstItemPosition == RecyclerView.NO_POSITION) { return 0; } int itemHeight = getItemHeight(); int firstItemTop = getFirstItemOffset(); return mView.getPaddingTop() + firstItemPosition * itemHeight - firstItemTop; }
Example 9
Source File: FeatureOverviewActivity.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 5 votes |
int getConvertedPosition(int sectionedPosition) { if (isSectionHeaderPosition(sectionedPosition)) { return RecyclerView.NO_POSITION; } int offset = 0; for (int i = 0; i < sections.size(); i++) { if (sections.valueAt(i).sectionedPosition > sectionedPosition) { break; } --offset; } return sectionedPosition + offset; }
Example 10
Source File: StickyRecyclerHeadersDecoration.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); int itemPosition = parent.getChildAdapterPosition(view); if (itemPosition == RecyclerView.NO_POSITION) { return; } if (mHeaderPositionCalculator.hasNewHeader(itemPosition)) { View header = getHeaderView(parent, itemPosition); setItemOffsetsForHeader(outRect, header, mOrientationProvider.getOrientation(parent)); } }
Example 11
Source File: RcvStickyLayout.java From RecyclerViewAdapter with Apache License 2.0 | 5 votes |
private void updateStickyLayout(int position) { if (position == RecyclerView.NO_POSITION) { return; } RcvSectionWrapper wrapper = (RcvSectionWrapper) mAdapter.getDatas().get(position - mAdapter.getHeadCounts()); mAdapter.onBindSectionLabelView(mHolder, wrapper.getSection(), position); mCurrentIndicatePosition = position; }
Example 12
Source File: MainActivity.java From views-widgets-samples with Apache License 2.0 | 5 votes |
private void changeItem(View view) { int position = mRecyclerView.getChildAdapterPosition(view); if (position != RecyclerView.NO_POSITION) { int color = generateColor(); mColors.set(position, color); notifyItemChanged(position); } }
Example 13
Source File: ActionModeHelper.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
/** * Gets the activated position only when mode is {@code SINGLE}. * * @return the activated position when {@code SINGLE}. -1 if no item is selected * @since 1.0.0-b1 */ public int getActivatedPosition() { List<Integer> selectedPositions = mAdapter.getSelectedPositions(); if (mAdapter.getMode() == Mode.SINGLE && selectedPositions.size() == 1) { return selectedPositions.get(0); } return RecyclerView.NO_POSITION; }
Example 14
Source File: LabelListAdapter.java From lttrs-android with Apache License 2.0 | 5 votes |
public void setSelectedLabel(final Label label) { if ((label == null && this.selectedLabel == null) || (same(label, this.selectedLabel))) { return; } final int previous = getPosition(this.selectedLabel); final int position = getPosition(label); this.selectedLabel = label; if (previous != RecyclerView.NO_POSITION) { notifyItemChanged(previous); } if (position != RecyclerView.NO_POSITION) { notifyItemChanged(position); } }
Example 15
Source File: StickyHeaderDecoration.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
protected int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) { int headerHeight = getHeaderHeightForLayout(header); int top = getChildY(parent, child) - headerHeight; if (sticky && layoutPos == 0) { final int count = parent.getChildCount(); final long currentId = adapter.getHeaderId(adapterPos); // find next view with header and compute the offscreen push if needed for (int i = 1; i < count; i++) { int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(translatedChildPosition(parent, i))); if (adapterPosHere != RecyclerView.NO_POSITION) { long nextId = adapter.getHeaderId(adapterPosHere); if (nextId != currentId) { final View next = parent.getChildAt(translatedChildPosition(parent, i)); final int offset = getChildY(parent, next) - (headerHeight + getHeader(parent, adapter, adapterPosHere).itemView.getHeight()); if (offset < 0) { return offset; } else { break; } } } } if (sticky) top = Math.max(0, top); } return top; }
Example 16
Source File: MessagesFragment.java From tindroid with Apache License 2.0 | 5 votes |
private int findItemPositionById(long id) { final int first = mMessageViewLayoutManager.findFirstVisibleItemPosition(); final int last = mMessageViewLayoutManager.findLastVisibleItemPosition(); if (last == RecyclerView.NO_POSITION) { return -1; } return mMessagesAdapter.findItemPositionById(id, first, last); }
Example 17
Source File: PreferenceGroupAdapter.java From MaterialPreference with Apache License 2.0 | 5 votes |
@Override public int getPreferenceAdapterPosition(Preference preference) { final int size = mPreferenceList.size(); for (int i = 0; i < size; i++) { final Preference candidate = mPreferenceList.get(i); if (candidate != null && candidate.equals(preference)) { return i; } } return RecyclerView.NO_POSITION; }
Example 18
Source File: AbstractRecyclerViewAdapter.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void changeItem(int position, T item) { if (position != RecyclerView.NO_POSITION && item != null) { mItemList.set(position, item); notifyItemChanged(position); } }
Example 19
Source File: GroupItemDecoration.java From CalendarView with Apache License 2.0 | 4 votes |
/** * 绘制悬浮组 * * @param c Canvas * @param parent RecyclerView */ protected void onDrawOverGroup(Canvas c, RecyclerView parent) { int firstVisiblePosition = ((LinearLayoutManager) parent.getLayoutManager()).findFirstVisibleItemPosition(); if (firstVisiblePosition == RecyclerView.NO_POSITION) { return; } Group group = getCroup(firstVisiblePosition); if (group == null) return; String groupTitle = group.toString(); if (TextUtils.isEmpty(groupTitle)) { return; } boolean isRestore = false; Group nextGroup = getCroup(firstVisiblePosition + 1); if (nextGroup != null && !group.equals(nextGroup)) { //说明是当前组最后一个元素,但不一定碰撞了 View child = parent.findViewHolderForAdapterPosition(firstVisiblePosition).itemView; if (child.getTop() + child.getMeasuredHeight() < mGroupHeight) { //进一步检测碰撞 c.save();//保存画布当前的状态 isRestore = true; c.translate(0, child.getTop() + child.getMeasuredHeight() - mGroupHeight); } } int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); int top = parent.getPaddingTop(); int bottom = top + mGroupHeight; c.drawRect(left, top, right, bottom, mBackgroundPaint); float x; float y = top + mTextBaseLine; if (isCenter) { x = parent.getMeasuredWidth() / 2 - getTextX(groupTitle); } else { x = mPaddingLeft; } c.drawText(groupTitle, x, y, mTextPaint); if (isRestore) { //还原画布为初始状态 c.restore(); } }
Example 20
Source File: ContentViewHolder.java From FlexibleAdapter with Apache License 2.0 | 3 votes |
/** * Overcomes the situation of returning an unknown position (-1) of ViewHolders created out of * the LayoutManager (ex. StickyHeaders). * <p><b>NOTE:</b> Always call this method, instead of {@code getAdapterPosition()}, in case * of StickyHeaders use case.</p> * * @return the Adapter position result of {@link #getAdapterPosition()} OR the backup position * preset and known, if the previous result was {@link RecyclerView#NO_POSITION}. * @see #setBackupPosition(int) * @since 5.0.0-b6 */ public final int getFlexibleAdapterPosition() { int position = getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { position = mBackupPosition; } return position; }