private IExpandable getExpandableItem(int position) { T item = getItem(position); if (isExpandable(item)) { return (IExpandable) item; } else { return null; } }
private int recursiveCollapse(@IntRange(from = 0) int position) { T item = getItem(position); if (!isExpandable(item)) { return 0; } IExpandable expandable = (IExpandable) item; int subItemCount = 0; if (expandable.isExpanded()) { List<T> subItems = expandable.getSubItems(); for (int i = subItems.size() - 1; i >= 0; i--) { T subItem = subItems.get(i); int pos = getItemPosition(subItem); if (pos < 0) { continue; } if (subItem instanceof IExpandable) { subItemCount += recursiveCollapse(pos); } mData.remove(pos); subItemCount++; } } return subItemCount; }
public int expandAll(int position, boolean animate, boolean notify) { position -= getHeaderLayoutCount(); T endItem = null; if (position + 1 < this.mData.size()) { endItem = getItem(position + 1); } IExpandable expandable = getExpandableItem(position); if (!hasSubItems(expandable)) { return 0; } int count = expand(position + getHeaderLayoutCount(), false, false); for (int i = position + 1; i < this.mData.size(); i++) { T item = getItem(i); if (item == endItem) { break; } if (isExpandable(item)) { count += expand(i + getHeaderLayoutCount(), false, false); } } if (notify) { if (animate) { notifyItemRangeInserted(position + getHeaderLayoutCount() + 1, count); } else { notifyDataSetChanged(); } } return count; }