Java Code Examples for androidx.recyclerview.widget.RecyclerView#NO_ID
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#NO_ID .
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: StableIdKeyProvider.java From FairEmail with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("WeakerAccess") /* synthetic access */ void onAttached(@NonNull View view) { RecyclerView.ViewHolder holder = mRecyclerView.findContainingViewHolder(view); if (holder == null) { if (DEBUG) { Log.w(TAG, "Unable to find ViewHolder for View. Ignoring onAttached event."); } return; } int position = holder.getAbsoluteAdapterPosition(); long id = holder.getItemId(); if (position != RecyclerView.NO_POSITION && id != RecyclerView.NO_ID) { mPositionToKey.put(position, id); mKeyToPosition.put(id, position); } }
Example 2
Source File: StableIdKeyProvider.java From FairEmail with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("WeakerAccess") /* synthetic access */ void onDetached(@NonNull View view) { RecyclerView.ViewHolder holder = mRecyclerView.findContainingViewHolder(view); if (holder == null) { if (DEBUG) { Log.w(TAG, "Unable to find ViewHolder for View. Ignoring onDetached event."); } return; } int position = holder.getAbsoluteAdapterPosition(); long id = holder.getItemId(); if (position != RecyclerView.NO_POSITION && id != RecyclerView.NO_ID) { mPositionToKey.delete(position); mKeyToPosition.remove(id); } }
Example 3
Source File: RecyclerViewConcatenateAdapter.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
long getGlobalItemId(int localPosition, long defaultGlobalValue) { final long localItemId = adapter.getItemId(localPosition); if (RecyclerView.NO_ID == localItemId) { return RecyclerView.NO_ID; } final Long globalItemId = localItemIdMap.get(localItemId); if (globalItemId == null) { localItemIdMap.put(localItemId, defaultGlobalValue); return defaultGlobalValue; } return globalItemId; }
Example 4
Source File: StickyHeaderDecoration.java From RecyclerExt with Apache License 2.0 | 6 votes |
/** * Replaces the <code>stickyHeader</code> with the header associated with * the <code>headerId</code>. * * @param headerId The id for the header view */ protected void performHeaderSwap(long headerId) { //If we don't have a valid headerId then clear the current header if (headerId == RecyclerView.NO_ID) { clearStickyHeader(); return; } //Get the position of the associated header int headerPosition = getHeaderPosition(headerId); if (headerPosition == RecyclerView.NO_POSITION) { return; } updateHeader(headerId, headerPosition); }
Example 5
Source File: StatisticActivity.java From Telegram with GNU General Public License v2.0 | 5 votes |
public void update() { saveOldState(); adapter.update(); int start = layoutManager.findFirstVisibleItemPosition(); int end = layoutManager.findLastVisibleItemPosition(); long scrollToItemId = RecyclerView.NO_ID; int offset = 0; for (int i = start; i <= end; i++) { if (adapter.getItemId(i) != RecyclerView.NO_ID) { View v = layoutManager.findViewByPosition(i); if (v != null) { scrollToItemId = adapter.getItemId(i); offset = v.getTop(); break; } } } DiffUtil.calculateDiff(this).dispatchUpdatesTo(adapter); if (scrollToItemId != RecyclerView.NO_ID) { int position = -1; for (int i = 0; i < adapter.getItemCount(); i++) { if (adapter.getItemId(i) == scrollToItemId) { position = i; break; } } if (position > 0) { layoutManager.scrollToPositionWithOffset(position, offset); } } }
Example 6
Source File: CheckInDrawable.java From cathode with Apache License 2.0 | 5 votes |
public void reset() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { resetImageDrawables(); id = RecyclerView.NO_ID; watching = false; currentDrawable = checkInDrawable; invalidateSelf(); } }
Example 7
Source File: StatisticActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public void update() { saveOldState(); adapter.update(); int start = layoutManager.findFirstVisibleItemPosition(); int end = layoutManager.findLastVisibleItemPosition(); long scrollToItemId = RecyclerView.NO_ID; int offset = 0; for (int i = start; i <= end; i++) { if (adapter.getItemId(i) != RecyclerView.NO_ID) { View v = layoutManager.findViewByPosition(i); if (v != null) { scrollToItemId = adapter.getItemId(i); offset = v.getTop(); break; } } } DiffUtil.calculateDiff(this).dispatchUpdatesTo(adapter); if (scrollToItemId != RecyclerView.NO_ID) { int position = -1; for (int i = 0; i < adapter.getItemCount(); i++) { if (adapter.getItemId(i) == scrollToItemId) { position = i; break; } } if (position > 0) { layoutManager.scrollToPositionWithOffset(position, offset); } } }
Example 8
Source File: StickyHeaderDecoration.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Retrieves the id for the header associated with the <code>childPosition</code> from * the specified <code>headerAdapter</code> * * @param childPosition The child position associated with the header * @return The id for the header or {@link RecyclerView#NO_ID} */ protected long getHeaderId(int childPosition) { if (childPosition < 0 || childPosition >= headerApi.getChildCount()) { return RecyclerView.NO_ID; } return headerApi.getHeaderId(childPosition); }
Example 9
Source File: HeaderDataGenerator.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Calculates the information necessary to display headers * using the associated {@link DataSource} * * @param reuseData A {@link HeaderData} that will be reused instead of creating a new one * @param dataSource The data to use when calculating the header information * @return The <code>reuseData</code> that has been populated with the header information */ @NonNull public HeaderData calculate(@NonNull HeaderData reuseData, @NonNull DataSource dataSource) { reuseData.headerItems.clear(); reuseData.adapterPositionItemMap.clear(); HeaderItem currentHeader = null; for (int i = 0; i < dataSource.getChildCount(); i++) { int adapterPosition = i + (reuseData.showHeaderAsChild ? 0 : reuseData.headerItems.size()); long headerId = dataSource.getHeaderId(i); if (headerId == RecyclerView.NO_ID) { currentHeader = null; reuseData.adapterPositionItemMap.put(adapterPosition, new AdapterItem(null, i, headerApi.getChildViewType(i) & ~HeaderApi.HEADER_VIEW_TYPE_MASK)); continue; } //Adds new headers to the list when detected if (currentHeader == null || currentHeader.getId() != headerId) { currentHeader = new HeaderItem(headerId, adapterPosition); reuseData.headerItems.put(headerId, currentHeader); reuseData.adapterPositionItemMap.put(adapterPosition, new AdapterItem(currentHeader, i, headerApi.getHeaderViewType(i) | HeaderApi.HEADER_VIEW_TYPE_MASK)); if (reuseData.showHeaderAsChild) { currentHeader.setChildCount(1); continue; } adapterPosition++; } currentHeader.setChildCount(currentHeader.getChildCount() + 1); reuseData.adapterPositionItemMap.put(adapterPosition, new AdapterItem(null, i, headerApi.getChildViewType(i) & ~HeaderApi.HEADER_VIEW_TYPE_MASK)); } return reuseData; }
Example 10
Source File: HeaderCore.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Determines the adapter position for the header associated with * the <code>headerId</code> * * @param headerId The id to find the header for * @return The associated headers position or {@link RecyclerView#NO_POSITION} */ public int getHeaderPosition(long headerId) { if (headerId == RecyclerView.NO_ID) { return RecyclerView.NO_POSITION; } HeaderItem headerItem = headerData.headerItems.get(headerId); return headerItem != null ? headerItem.getAdapterPosition() : RecyclerView.NO_POSITION; }
Example 11
Source File: HeaderCore.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Returns the total number of views that are associated with the specified * header id. If the headerId doesn't exist then 0 will be returned. * * @param headerId The headerId to find the number of children for * @return The number of children views associated with the given <code>headerId</code> */ public int getChildCount(long headerId) { if (headerId == RecyclerView.NO_ID) { return 0; } HeaderItem headerItem = headerData.headerItems.get(headerId); return headerItem != null ? headerItem.getChildCount() : 0; }
Example 12
Source File: PreferenceGroupAdapter.java From MaterialPreference with Apache License 2.0 | 5 votes |
@Override public long getItemId(int position) { if (!hasStableIds()) { return RecyclerView.NO_ID; } return this.getItem(position).getId(); }
Example 13
Source File: ItemsAdapter.java From appbarsyncedfab with Apache License 2.0 | 5 votes |
@Override public long getItemId(int position) { if (position >= 0 && position < dataset.size()) { return dataset.get(position); } return RecyclerView.NO_ID; }
Example 14
Source File: PaginationAdapter.java From OmegaRecyclerView with MIT License | 5 votes |
@Override public long getItemId(int position) { if (position == super.getItemCount()) { return RecyclerView.NO_ID; } return super.getItemId(position); }
Example 15
Source File: HeaderAdapter.java From RecyclerExt with Apache License 2.0 | 4 votes |
@Override public long getHeaderId(int childPosition) { return RecyclerView.NO_ID; }
Example 16
Source File: HeaderListAdapter.java From RecyclerExt with Apache License 2.0 | 4 votes |
@Override public long getHeaderId(int childPosition) { return RecyclerView.NO_ID; }
Example 17
Source File: ItemRecyclerViewAdapter.java From materialistic with Apache License 2.0 | 4 votes |
@Override public long getItemId(int position) { Item item = getItem(position); return item != null ? item.getLongId() : RecyclerView.NO_ID; }
Example 18
Source File: HeaderAdapter.java From cathode with Apache License 2.0 | 4 votes |
protected long getItemId(Type item) { return RecyclerView.NO_ID; }