Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space list crash fix #5924

Merged
merged 4 commits into from
May 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import javax.inject.Inject
class SpaceSummaryController @Inject constructor(
private val avatarRenderer: AvatarRenderer,
private val colorProvider: ColorProvider,
private val stringProvider: StringProvider) : EpoxyController() {
private val stringProvider: StringProvider,
) : EpoxyController() {

var callback: Callback? = null
private var viewState: SpaceListViewState? = null
Expand All @@ -62,7 +63,8 @@ class SpaceSummaryController @Inject constructor(
nonNullViewState.selectedGroupingMethod,
nonNullViewState.rootSpacesOrdered,
nonNullViewState.expandedStates,
nonNullViewState.homeAggregateCount)
nonNullViewState.homeAggregateCount
)

if (!nonNullViewState.legacyGroups.isNullOrEmpty()) {
genericFooterItem {
Expand All @@ -82,8 +84,10 @@ class SpaceSummaryController @Inject constructor(
avatarRenderer(host.avatarRenderer)
id("all_communities")
matrixItem(mxItem.copy(displayName = host.stringProvider.getString(R.string.group_all_communities)))
selected(nonNullViewState.selectedGroupingMethod is RoomGroupingMethod.ByLegacyGroup &&
nonNullViewState.selectedGroupingMethod.group() == null)
selected(
nonNullViewState.selectedGroupingMethod is RoomGroupingMethod.ByLegacyGroup &&
nonNullViewState.selectedGroupingMethod.group() == null
)
listener { host.callback?.onGroupSelected(null) }
}
}
Expand All @@ -93,8 +97,10 @@ class SpaceSummaryController @Inject constructor(
avatarRenderer(host.avatarRenderer)
id(groupSummary.groupId)
matrixItem(groupSummary.toMatrixItem())
selected(nonNullViewState.selectedGroupingMethod is RoomGroupingMethod.ByLegacyGroup &&
nonNullViewState.selectedGroupingMethod.group()?.groupId == groupSummary.groupId)
selected(
nonNullViewState.selectedGroupingMethod is RoomGroupingMethod.ByLegacyGroup &&
nonNullViewState.selectedGroupingMethod.group()?.groupId == groupSummary.groupId
)
listener { host.callback?.onGroupSelected(groupSummary) }
}
}
Expand All @@ -112,12 +118,12 @@ class SpaceSummaryController @Inject constructor(
}

// show invites on top

summaries?.filter { it.membership == Membership.INVITE }
summaries
?.filter { it.membership == Membership.INVITE }
?.forEach { roomSummary ->
spaceSummaryItem {
avatarRenderer(host.avatarRenderer)
id(roomSummary.roomId)
id("invite_${roomSummary.roomId}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a unique id for the invite makes sense to me to fix the crash, we can iterate on the proper UX (whether two spaces with the same id should be present in the spaces list...)

matrixItem(roomSummary.toMatrixItem())
countState(UnreadCounterBadgeView.State(1, true))
selected(false)
Expand All @@ -135,41 +141,42 @@ class SpaceSummaryController @Inject constructor(
}

rootSpaces
?.forEach { groupSummary ->
val isSelected = selected is RoomGroupingMethod.BySpace && groupSummary.roomId == selected.space()?.roomId
?.filter { it.membership != Membership.INVITE }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

?.forEach { roomSummary ->
val isSelected = selected is RoomGroupingMethod.BySpace && roomSummary.roomId == selected.space()?.roomId
// does it have children?
val subSpaces = groupSummary.spaceChildren?.filter { childInfo ->
val subSpaces = roomSummary.spaceChildren?.filter { childInfo ->
summaries?.any { it.roomId == childInfo.childRoomId }.orFalse()
}?.sortedWith(subSpaceComparator)
val hasChildren = (subSpaces?.size ?: 0) > 0
val expanded = expandedStates[groupSummary.roomId] == true
val expanded = expandedStates[roomSummary.roomId] == true

spaceSummaryItem {
avatarRenderer(host.avatarRenderer)
id(groupSummary.roomId)
id(roomSummary.roomId)
hasChildren(hasChildren)
expanded(expanded)
// to debug order
// matrixItem(groupSummary.copy(displayName = "${groupSummary.displayName} / ${spaceOrderInfo?.get(groupSummary.roomId)}")
// .toMatrixItem())
matrixItem(groupSummary.toMatrixItem())
matrixItem(roomSummary.toMatrixItem())
selected(isSelected)
canDrag(true)
onMore { host.callback?.onSpaceSettings(groupSummary) }
listener { host.callback?.onSpaceSelected(groupSummary) }
toggleExpand { host.callback?.onToggleExpand(groupSummary) }
onMore { host.callback?.onSpaceSettings(roomSummary) }
listener { host.callback?.onSpaceSelected(roomSummary) }
toggleExpand { host.callback?.onToggleExpand(roomSummary) }
countState(
UnreadCounterBadgeView.State(
groupSummary.notificationCount,
groupSummary.highlightCount > 0
roomSummary.notificationCount,
roomSummary.highlightCount > 0
)
)
}

if (hasChildren && expanded) {
// it's expanded
subSpaces?.forEach { child ->
buildSubSpace(groupSummary.roomId, summaries, expandedStates, selected, child, 1, 3)
buildSubSpace(roomSummary.roomId, summaries, expandedStates, selected, child, 1, 3)
}
}
}
Expand Down