mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-05 21:43:40 +01:00
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:
parent
b49c30d879
commit
f1ee8183e5
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user