From f1ee8183e5df3080cc8d82c6c1af319a5d336529 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 12 Dec 2021 11:24:45 +0100 Subject: [PATCH 1/2] Ensure unique ids for subspaces When you have two root spaces with the same space as subspace, and you expand both root spaces, you end up with two times the same id in the list. This has two problems: - The expand animation is slightly broken, if you expand the second root space first and then the first one - If you select one of these items with same id, the app crashes: java.lang.IllegalStateException: Two different ViewHolders have the same stable ID. Stable IDs in your adapter MUST BE unique and SHOULD NOT change. As solution, just prefix the epoxy item ids with the parent spaces. --- .../app/features/spaces/SpaceSummaryController.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt index a334548cfc9..3d628fbaa45 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt @@ -170,7 +170,7 @@ class SpaceSummaryController @Inject constructor( if (hasChildren && expanded) { // it's expanded subSpaces?.forEach { child -> - buildSubSpace(summaries, expandedStates, selected, child, 1, 3) + buildSubSpace(groupSummary.roomId, summaries, expandedStates, selected, child, 1, 3) } } } @@ -181,7 +181,8 @@ class SpaceSummaryController @Inject constructor( } } - private fun buildSubSpace(summaries: List?, + private fun buildSubSpace(idPrefix: String, + summaries: List?, expandedStates: Map, selected: RoomGroupingMethod, info: SpaceChildInfo, currentDepth: Int, maxDepth: Int) { @@ -195,9 +196,11 @@ class SpaceSummaryController @Inject constructor( val expanded = expandedStates[childSummary.roomId] == true val isSelected = selected is RoomGroupingMethod.BySpace && childSummary.roomId == selected.space()?.roomId + val id = "$idPrefix:${childSummary.roomId}" + subSpaceSummaryItem { avatarRenderer(host.avatarRenderer) - id(childSummary.roomId) + id(id) hasChildren(!subSpaces.isNullOrEmpty()) selected(isSelected) expanded(expanded) @@ -216,7 +219,7 @@ class SpaceSummaryController @Inject constructor( if (expanded) { subSpaces?.forEach { - buildSubSpace(summaries, expandedStates, selected, it, currentDepth + 1, maxDepth) + buildSubSpace(id, summaries, expandedStates, selected, it, currentDepth + 1, maxDepth) } } } From 9a84c45ccd21c28b54135c2952a71f1f64b51cf6 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 12 Dec 2021 12:20:21 +0100 Subject: [PATCH 2/2] Changelog --- changelog.d/4693.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4693.bugfix diff --git a/changelog.d/4693.bugfix b/changelog.d/4693.bugfix new file mode 100644 index 00000000000..2aca848628c --- /dev/null +++ b/changelog.d/4693.bugfix @@ -0,0 +1 @@ +Fix possible crash when having identical subspaces in multiple root spaces