/** * 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; }
/** * 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> setInternal(int position, Item item) { if (mUseIdDistributor) { getIdDistributor().checkId(item); } mItems.set(position, item, getFastAdapter().getPreItemCount(position)); mFastAdapter.registerTypeInstance(item); return this; }
@Test public void getPreItemCount() throws Exception { List<TestItem> items = TestDataGenerator.genTestItemList(100); itemAdapter.set(items); assertThat(adapter.getPreItemCount(40)).isEqualTo(0); }
@Test public void getPreItemCount() throws Exception { List<TestItem> items = TestDataGenerator.genTestItemList(100); itemAdapter.set(items); assertThat(adapter.getPreItemCount(40)).isEqualTo(0); }
/** * 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); } }