@Override public void onChanged(int position, int count, Object payload) { adapter.getFastAdapter().notifyAdapterItemRangeChanged(adapter.getFastAdapter().getPreItemCountByOrder(adapter.getOrder()) + position, count, payload); } }
@Override public void onRemoved(int position, int count) { adapter.getFastAdapter().notifyAdapterItemRangeRemoved(adapter.getFastAdapter().getPreItemCountByOrder(adapter.getOrder()) + position, count); }
@Override public void onMoved(int fromPosition, int toPosition) { adapter.getFastAdapter().notifyAdapterItemMoved(adapter.getFastAdapter().getPreItemCountByOrder(adapter.getOrder()) + fromPosition, toPosition); }
@Override public void onInserted(int position, int count) { adapter.getFastAdapter().notifyAdapterItemRangeInserted(adapter.getFastAdapter().getPreItemCountByOrder(adapter.getOrder()) + position, count); }
/** * helper method to get all selections from the ItemAdapter's original item list * * @return a Set with the selected items out of all items in this itemAdapter (not the listed ones) */ public Set<Item> getSelectedItems() { if (mOriginalItems != null) { Set<Item> selections = new HashSet<>(); for (int i = 0, size = mOriginalItems.size(); i < size; i++) { Item item = mOriginalItems.get(i); if (item.isSelected()) { selections.add(item); } } return selections; } else { return mItemAdapter.getFastAdapter().getSelectedItems(); } }
/** * returns the global position if the relative position within this adapter was given * * @param position the relative position * @return the global position */ public int getGlobalPosition(int position) { return position + getFastAdapter().getPreItemCountByOrder(getOrder()); }
/** * moves an item within the list from a position to a position * * @param fromPosition the position global from which we want to move * @param toPosition the global position to which to move * @return this */ public ModelAdapter<Model, Item> move(int fromPosition, int toPosition) { mItems.move(fromPosition, toPosition, getFastAdapter().getPreItemCount(fromPosition)); return this; }
/** * removes an item at the given position within the existing icons * * @param position the global position */ public ModelAdapter<Model, Item> remove(int position) { mItems.remove(position, getFastAdapter().getPreItemCount(position)); return this; }
/** * removes a range of items starting with the given position within the existing icons * * @param position the global position * @param itemCount the count of items which were removed */ public ModelAdapter<Model, Item> removeRange(int position, int itemCount) { mItems.removeRange(position, itemCount, getFastAdapter().getPreItemCount(position)); return this; }
/** * helper method to get all selections from the ItemAdapter's original item list * * @return a Set with the global positions of all selected Items */ public Set<Integer> getSelections() { if (mOriginalItems != null) { Set<Integer> selections = new HashSet<>(); int adapterOffset = mItemAdapter.getFastAdapter().getPreItemCountByOrder(mItemAdapter.getOrder()); for (int i = 0, size = mOriginalItems.size(); i < size; i++) { Item item = mOriginalItems.get(i); if (item.isSelected()) { selections.add(i + adapterOffset); } } return selections; } else { return mItemAdapter.getFastAdapter().getSelections(); } }
/** * forces to remap all possible types for the RecyclerView */ public void remapMappedTypes() { getFastAdapter().clearTypeInstance(); mapPossibleTypes(mItems.getItems()); }
/** * removes all items of this adapter */ public ModelAdapter<Model, Item> clear() { mItems.clear(getFastAdapter().getPreItemCountByOrder(getOrder())); return this; }
/** * removes a range of items starting with the given position within the existing icons * * @param position the global position * @param itemCount the count of items which were removed */ public ModelAdapter<?, Item> removeRange(int position, int itemCount) { if (mOriginalItems != null) { //global position to relative int length = mOriginalItems.size(); int preItemCount = mItemAdapter.getFastAdapter().getPreItemCount(position); //make sure we do not delete to many items int saveItemCount = Math.min(itemCount, length - position + preItemCount); for (int i = 0; i < saveItemCount; i++) { mOriginalItems.remove(position - preItemCount); } publishResults(mConstraint, performFiltering(mConstraint)); return mItemAdapter; } else { return mItemAdapter.removeRange(position, itemCount); } }
/** * moves an item within the list from a position to a position * * @param fromPosition the position global from which we want to move * @param toPosition the global position to which to move * @return this */ public ModelAdapter<?, Item> move(int fromPosition, int toPosition) { if (mOriginalItems != null) { int preItemCount = mItemAdapter.getFastAdapter().getPreItemCount(fromPosition); int adjustedFrom = getAdapterPosition(mItemAdapter.getAdapterItems().get(fromPosition)); int adjustedTo = getAdapterPosition(mItemAdapter.getAdapterItems().get(toPosition)); Item item = mOriginalItems.get(adjustedFrom - preItemCount); mOriginalItems.remove(adjustedFrom - preItemCount); mOriginalItems.add(adjustedTo - preItemCount, item); performFiltering(mConstraint); return mItemAdapter; } else { return mItemAdapter.move(fromPosition, toPosition); } }
/** * removes an item at the given position within the existing icons * * @param position the global position */ public ModelAdapter<?, Item> remove(int position) { if (mOriginalItems != null) { mOriginalItems.remove(getAdapterPosition(mItemAdapter.getAdapterItems().get(position)) - mItemAdapter.getFastAdapter().getPreItemCount(position)); publishResults(mConstraint, performFiltering(mConstraint)); return mItemAdapter; } else { return mItemAdapter.remove(position); } }
public ModelAdapter<Model, Item> addInternal(int position, List<Item> items) { if (mUseIdDistributor) { getIdDistributor().checkIds(items); } if (items.size() > 0) { mItems.addAll(position, items, getFastAdapter().getPreItemCountByOrder(getOrder())); 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; }
/** * add a list of items at the given position within the existing items * * @param position the global position * @param items the items to add */ public ModelAdapter<?, Item> add(int position, List<Item> items) { if (mOriginalItems != null && items.size() > 0) { if (mItemAdapter.isUseIdDistributor()) { mItemAdapter.getIdDistributor().checkIds(items); } mOriginalItems.addAll(getAdapterPosition(mItemAdapter.getAdapterItems().get(position)) - mItemAdapter.getFastAdapter().getPreItemCount(position), items); publishResults(mConstraint, performFiltering(mConstraint)); return mItemAdapter; } else { return mItemAdapter.addInternal(position, items); } }
/** * sets an item at the given position, overwriting the previous item * * @param position the global position * @param item the item to set */ public ModelAdapter<?, Item> set(int position, Item item) { if (mOriginalItems != null) { if (mItemAdapter.isUseIdDistributor()) { mItemAdapter.getIdDistributor().checkId(item); } mOriginalItems.set(getAdapterPosition(mItemAdapter.getAdapterItems().get(position)) - mItemAdapter.getFastAdapter().getPreItemCount(position), item); publishResults(mConstraint, performFiltering(mConstraint)); return mItemAdapter; } else { return mItemAdapter.setInternal(position, item); } }
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; }