androidx.recyclerview.widget.RecyclerView#NO_ID源码实例Demo

下面列出了androidx.recyclerview.widget.RecyclerView#NO_ID 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
源代码2 项目: FairEmail   文件: StableIdKeyProvider.java
@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);
    }
}
 
源代码3 项目: FairEmail   文件: StableIdKeyProvider.java
@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);
    }
}
 
源代码4 项目: RecyclerExt   文件: StickyHeaderDecoration.java
/**
 * 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);
}
 
源代码5 项目: OmegaRecyclerView   文件: PaginationAdapter.java
@Override
public long getItemId(int position) {
    if (position == super.getItemCount()) {
        return RecyclerView.NO_ID;
    }
    return super.getItemId(position);
}
 
源代码6 项目: appbarsyncedfab   文件: ItemsAdapter.java
@Override
public long getItemId(int position) {
    if (position >= 0 && position < dataset.size()) {
        return dataset.get(position);
    }
    return RecyclerView.NO_ID;
}
 
@Override
public long getItemId(int position) {
    if (!hasStableIds()) {
        return RecyclerView.NO_ID;
    }
    return this.getItem(position).getId();
}
 
源代码8 项目: RecyclerExt   文件: HeaderCore.java
/**
 * 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;
}
 
源代码9 项目: RecyclerExt   文件: HeaderCore.java
/**
 * 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;
}
 
源代码10 项目: RecyclerExt   文件: HeaderDataGenerator.java
/**
 * 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;
}
 
源代码11 项目: RecyclerExt   文件: StickyHeaderDecoration.java
/**
 * 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);
}
 
源代码12 项目: Telegram-FOSS   文件: StatisticActivity.java
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);
        }
    }
}
 
源代码13 项目: cathode   文件: CheckInDrawable.java
public void reset() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    resetImageDrawables();

    id = RecyclerView.NO_ID;
    watching = false;

    currentDrawable = checkInDrawable;
    invalidateSelf();
  }
}
 
源代码14 项目: Telegram   文件: StatisticActivity.java
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);
        }
    }
}
 
源代码15 项目: materialistic   文件: ItemRecyclerViewAdapter.java
@Override
public long getItemId(int position) {
    Item item = getItem(position);
    return item != null ? item.getLongId() : RecyclerView.NO_ID;
}
 
源代码16 项目: RecyclerExt   文件: HeaderListAdapter.java
@Override
public long getHeaderId(int childPosition) {
    return RecyclerView.NO_ID;
}
 
源代码17 项目: RecyclerExt   文件: HeaderAdapter.java
@Override
public long getHeaderId(int childPosition) {
    return RecyclerView.NO_ID;
}
 
源代码18 项目: cathode   文件: HeaderAdapter.java
protected long getItemId(Type item) {
  return RecyclerView.NO_ID;
}