RoomListFragment: Use proper way to observe space changes

Change-Id: I30d65c3e653eb82f4095ed538aec9a4c8c2de337
This commit is contained in:
SpiritCroc 2022-03-15 20:32:01 +01:00
parent 31c01c98de
commit cd1449d9bb
2 changed files with 6 additions and 10 deletions

View File

@ -63,8 +63,6 @@ class AppStateHandler @Inject constructor(
val selectedRoomGroupingFlow = selectedSpaceDataSource.stream()
var onSwitchSpaceListener: OnSwitchSpaceListener? = null
fun getCurrentRoomGroupingMethod(): RoomGroupingMethod? {
// XXX we should somehow make it live :/ just a work around
// For example just after creating a space and switching to it the
@ -99,7 +97,6 @@ class AppStateHandler @Inject constructor(
}
}
}
onSwitchSpaceListener?.onSwitchSpace(spaceId)
}
fun setCurrentGroup(groupId: String?, session: Session? = null) {
@ -159,8 +156,4 @@ class AppStateHandler @Inject constructor(
}
}
}
interface OnSwitchSpaceListener {
fun onSwitchSpace(spaceId: String?)
}
}

View File

@ -55,6 +55,7 @@ import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedA
import im.vector.app.features.home.room.list.widget.NotifsFabMenuView
import im.vector.app.features.notifications.NotificationDrawerManager
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.space
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.parcelize.Parcelize
@ -81,7 +82,6 @@ class RoomListFragment @Inject constructor(
) : VectorBaseFragment<FragmentRoomListBinding>(),
RoomListListener,
OnBackPressed,
AppStateHandler.OnSwitchSpaceListener,
FilteredRoomFooterItem.Listener,
NotifsFabMenuView.Listener {
@ -157,7 +157,10 @@ class RoomListFragment @Inject constructor(
(it.contentEpoxyController as? RoomSummaryPagedController)?.roomChangeMembershipStates = ms
}
}
appStateHandler.onSwitchSpaceListener = this
roomListViewModel.onEach(RoomListViewState::currentRoomGrouping) {
val spaceId = it.invoke()?.space()?.roomId
onSwitchSpace(spaceId)
}
}
override fun onPause() {
@ -574,7 +577,7 @@ class RoomListFragment @Inject constructor(
const val ROOM_LIST_ROOM_EXPANDED_ANY_PREFIX = "ROOM_LIST_ROOM_EXPANDED"
}
override fun onSwitchSpace(spaceId: String?) {
private fun onSwitchSpace(spaceId: String?) {
if (roomListParams.explicitSpaceId == SPACE_ID_FOLLOW_APP) {
return
}