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.
This commit is contained in:
SpiritCroc 2021-12-12 11:24:45 +01:00
parent b49c30d879
commit f1ee8183e5

View File

@ -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<RoomSummary>?,
private fun buildSubSpace(idPrefix: String,
summaries: List<RoomSummary>?,
expandedStates: Map<String, Boolean>,
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)
}
}
}