/** * Collapse an expandable item that has been expanded.. * * @param position the position of the item, which includes the header layout count. * @param animate collapse with animation or not. * @param notify notify the recyclerView refresh UI or not. * @return the number of subItems collapsed. */ public int collapse(@IntRange(from = 0) int position, boolean animate, boolean notify) { position -= getHeaderLayoutCount(); IExpandable expandable = getExpandableItem(position); if (expandable == null) { return 0; } int subItemCount = recursiveCollapse(position); expandable.setExpanded(false); int parentPos = position + getHeaderLayoutCount(); if (notify) { if (animate) { notifyItemChanged(parentPos); notifyItemRangeRemoved(parentPos + 1, subItemCount); } else { notifyDataSetChanged(); } } return subItemCount; }
position -= getHeaderLayoutCount(); IExpandable expandable = getExpandableItem(position); if (expandable == null) { return 0;
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; }