/** * finds the int ItemId from the IItem which exists at the given position * * @param position the global position * @return the itemId for this position */ @Override public long getItemId(int position) { return getItem(position).getIdentifier(); }
/** * is called inside the onCreateViewHolder method and creates the viewHolder based on the provided viewTyp * * @param parent the parent which will host the View * @param viewType the type of the ViewHolder we want to create * @return the generated ViewHolder based on the given viewType */ @Override public RecyclerView.ViewHolder onPreCreateViewHolder(FastAdapter<Item> fastAdapter, ViewGroup parent, int viewType) { return fastAdapter.getTypeInstance(viewType).getViewHolder(parent); }
public ModelAdapter<Model, Item> addInternal(List<Item> items) { if (mUseIdDistributor) { getIdDistributor().checkIds(items); } FastAdapter<Item> fastAdapter = getFastAdapter(); if (fastAdapter != null) { mItems.addAll(items, fastAdapter.getPreItemCountByOrder(getOrder())); } else { mItems.addAll(items, 0); } mapPossibleTypes(items); return this; }
public ModelAdapter<Model, Item> setInternal(int position, Item item) { if (mUseIdDistributor) { getIdDistributor().checkId(item); } mItems.set(position, item, getFastAdapter().getPreItemCount(position)); mFastAdapter.registerTypeInstance(item); return this; }
/** * make sure we return the count from the FastAdapter so we retrieve the count from all adapters * * @return */ @Override public int getItemCount() { return mFastAdapter.getItemCount(); }
/** * check if the item is within the bounds of the list * * @param position * @param includeOffset * @return */ protected boolean checkDrawerItem(int position, boolean includeOffset) { return getAdapter().getItem(position) != null; }
/** * register a new type into the TypeInstances to be able to efficiently create thew ViewHolders * * @param item an IItem which will be shown in the list */ @SuppressWarnings("unchecked") public void registerTypeInstance(Item item) { if (getTypeInstanceCache().register(item)) { //check if the item implements hookable when its added for the first time if (item instanceof IHookable) { withEventHooks(((IHookable<Item>) item).getEventHooks()); } } }
/** * overwrite the getItemViewType to correctly return the value from the FastAdapter * * @param position * @return */ @Override public int getItemViewType(int position) { return mFastAdapter.getItemViewType(position); }
/** * define this if you want enable hasStableIds for the adapter which is generated. * WARNING: only use this if you have set an identifer for all of your items else this could cause * many weird things * * @param hasStableIds * @return */ public DrawerBuilder withHasStableIds(boolean hasStableIds) { this.mHasStableIds = hasStableIds; if (mAdapter != null) { mAdapter.setHasStableIds(hasStableIds); } return this; }
/** * Remove a drawerItem at a specific position * * @param position */ public void removeItemByPosition(int position) { if (mDrawerBuilder.checkDrawerItem(position, false)) { mDrawerBuilder.getItemAdapter().remove(position); } }
/** * deselects all selected items */ public void deselect() { getAdapter().deselect(); }
/** * the onCreateViewHolder is managed by the FastAdapter so forward this correctly * * @param parent * @param viewType * @return */ @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return mFastAdapter.onCreateViewHolder(parent, viewType); }
/** * gets the TypeInstance remembered within the FastAdapter for an item * * @param type the int type of the item * @return the Item typeInstance */ public Item getTypeInstance(int type) { return getTypeInstanceCache().get(type); }
/** * clears the internal mapper - be sure, to remap everything before going on */ public void clearTypeInstance() { getTypeInstanceCache().clear(); }
/** * the onAttachedToRecyclerView is managed by the FastAdapter so forward this correctly * * @param recyclerView */ @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { mFastAdapter.onAttachedToRecyclerView(recyclerView); }
/** * overwrite the getItemViewType to correctly return the value from the FastAdapter * * @param position * @return */ @Override public int getItemViewType(int position) { return mFastAdapter.getItemViewType(position); }
/** * deselects the item with the given identifier * * @param identifier the identifier to search for */ public void deselect(long identifier) { getAdapter().deselect(getPosition(identifier)); }
/** * the onCreateViewHolder is managed by the FastAdapter so forward this correctly * * @param parent * @param viewType * @return */ @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return mFastAdapter.onCreateViewHolder(parent, viewType); }
/** * the onAttachedToRecyclerView is managed by the FastAdapter so forward this correctly * * @param recyclerView */ @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { mFastAdapter.onAttachedToRecyclerView(recyclerView); }