@Override public void onNewItems(@NonNull List<Model> newItems, int page) { int size = newItems.size(); List<Item> iitems = new ArrayList<>(size); for (int i = 0; i < size; i++) { iitems.add(mItemFactory.intercept(newItems.get(i))); } mItemAdapter.addInternal(iitems); } }
private void undoChange() { if (mHistory != null) { if (mHistory.action == ACTION_REMOVE) { for (int i = 0, size = mHistory.items.size(); i < size; i++) { FastAdapter.RelativeInfo<Item> relativeInfo = mHistory.items.get(i); if (relativeInfo.adapter instanceof IItemAdapter) { IItemAdapter<?, Item> adapter = (IItemAdapter<?, Item>) relativeInfo.adapter; adapter.addInternal(relativeInfo.position, asList(relativeInfo.item)); if (relativeInfo.item.isSelected()) { mAdapter.select(relativeInfo.position); } } } } } mHistory = null; }
/** * opens the expandable item at the given position * * @param position the global position * @param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false */ public void expand(int position, boolean notifyItemChanged) { Item item = mFastAdapter.getItem(position); if (item != null && item instanceof IExpandable) { IExpandable expandable = (IExpandable) item; //if this item is not already expanded and has sub items we go on if (!expandable.isExpanded() && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) { IAdapter<Item> adapter = mFastAdapter.getAdapter(position); if (adapter != null && adapter instanceof IItemAdapter) { ((IItemAdapter<?, Item>) adapter).addInternal(position + 1, expandable.getSubItems()); } //remember that this item is now opened (not collapsed) expandable.withIsExpanded(true); //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { mFastAdapter.notifyItemChanged(position); } } } }