Add subitem doesn't account for other expanded subitems
See original GitHub issueIn our latest round of testing we’ve found another small bug with regard to adding subitems. Additions work well except in the case that the incoming item is being placed after another subitem that itself is expanded. In this case, the position does not account for the additional flat list positions occupied by the children and the incoming item is placed either between the sub-subitems or in another incorrect position of the list.
I’ve tracked the relevant code down to the following:
private boolean addSubItems(@IntRange(from = 0L) int parentPosition, @IntRange(from = 0L) int subPosition, @NonNull IExpandable parent, @NonNull List<T> subItems, boolean expandParent, @Nullable Object payload) {
boolean added = false;
if(expandParent && !parent.isExpanded()) {
this.expand(parentPosition);
}
if(parent.isExpanded()) {
added = this.addItems(**parentPosition + 1 + Math.max(0, subPosition)**, subItems);
}
if(payload != null) {
this.notifyItemChanged(parentPosition, payload);
}
return added;
}
A similar issue occurs when an expandable item H is expanded followed by the expansion of a subitem and then the collapse of the top expandable item H. The collapse only removes k items where k = the number of direct subitems for the expandable item H. A method to quickly return the total number of visible subitems (recursively counting expansions when present) seems most useful to help handle these cases. Does such a method exist? Perhaps I missed it? If not, I’m happy to try my hand at a version but the modifications will be more significant than my last effort and I appreciate your input with regards to other areas where issues may arise due to this bug.
Thanks!
P.S. I can submit the expansion count bug as a separate issue or append it here if you prefer since they are similar.
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (11 by maintainers)
Top GitHub Comments
Figured it out, was using a recursive call in prepareItemsForUpdate that is unnecessary as that method already traverses through subitems as they expand. Pull request being sent now.
Excellent! That was something we were considering for the future.