@Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, @NonNull Item item, int position) { //we do not care about non visible items if (position == -1) { return false; } //this is the entrance parent if (allowedParents.size() > 0 && item instanceof ISubItem) { // Go on until we hit an item with a parent which was not in our expandable hierarchy IItem parent = ((ISubItem) item).getParent(); if (parent == null || !allowedParents.contains(parent)) { return true; } } if (item instanceof IExpandable) { IExpandable expandable = (IExpandable) item; if (expandable.isExpanded()) { expandable.withIsExpanded(false); if (expandable.getSubItems() != null) { expandedItemsCount[0] += expandable.getSubItems().size(); allowedParents.add(item); } } } return false; } }, position, true);
/** * 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); } } } }