/** * wraps notifyItemRemoved * * @param position the global position */ public void notifyAdapterItemRemoved(int position) { notifyAdapterItemRangeRemoved(position, 1); }
@Override public void removeRange(int position, int itemCount, int preItemCount) { //global position to relative int length = mItems.size(); //make sure we do not delete to many items int saveItemCount = Math.min(itemCount, length - position + preItemCount); for (int i = 0; i < saveItemCount; i++) { mItems.remove(position - preItemCount); } if (getFastAdapter() != null) { getFastAdapter().notifyAdapterItemRangeRemoved(position, saveItemCount); } }
@Override public void clear(int preItemCount) { int size = mItems.size(); mItems.clear(); if (getFastAdapter() != null) { getFastAdapter().notifyAdapterItemRangeRemoved(preItemCount, size); } }
@Override public boolean notify(FastAdapter fastAdapter, int newItemsCount, int previousItemsCount, int itemsBeforeThisAdapter) { //now properly notify the adapter about the changes if (newItemsCount > previousItemsCount) { if (previousItemsCount > 0) { fastAdapter.notifyAdapterItemRangeChanged(itemsBeforeThisAdapter, previousItemsCount); } fastAdapter.notifyAdapterItemRangeInserted(itemsBeforeThisAdapter + previousItemsCount, newItemsCount - previousItemsCount); } else if (newItemsCount > 0 && newItemsCount < previousItemsCount) { fastAdapter.notifyAdapterItemRangeChanged(itemsBeforeThisAdapter, newItemsCount); fastAdapter.notifyAdapterItemRangeRemoved(itemsBeforeThisAdapter + newItemsCount, previousItemsCount - newItemsCount); } else if (newItemsCount == 0) { fastAdapter.notifyAdapterItemRangeRemoved(itemsBeforeThisAdapter, previousItemsCount); } else { //this condition should practically never happen fastAdapter.notifyAdapterDataSetChanged(); } return false; } };
@Override public boolean notify(FastAdapter fastAdapter, int newItemsCount, int previousItemsCount, int itemsBeforeThisAdapter) { //now properly notify the adapter about the changes if (newItemsCount > previousItemsCount) { if (previousItemsCount > 0) { fastAdapter.notifyAdapterItemRangeChanged(itemsBeforeThisAdapter, previousItemsCount); } fastAdapter.notifyAdapterItemRangeInserted(itemsBeforeThisAdapter + previousItemsCount, newItemsCount - previousItemsCount); } else if (newItemsCount > 0) { fastAdapter.notifyAdapterItemRangeChanged(itemsBeforeThisAdapter, newItemsCount); if (newItemsCount < previousItemsCount) { fastAdapter.notifyAdapterItemRangeRemoved(itemsBeforeThisAdapter + newItemsCount, previousItemsCount - newItemsCount); } } else if (newItemsCount == 0) { fastAdapter.notifyAdapterItemRangeRemoved(itemsBeforeThisAdapter, previousItemsCount); } else { //this condition should practically never happen fastAdapter.notifyAdapterDataSetChanged(); } return false; } };
@Override public void onRemoved(int position, int count) { adapter.getFastAdapter().notifyAdapterItemRangeRemoved(adapter.getFastAdapter().getPreItemCountByOrder(adapter.getOrder()) + position, count); }