From cd1449d9bb6962fd27b2a627b9c427dbca818ecc Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 15 Mar 2022 20:32:01 +0100 Subject: [PATCH] RoomListFragment: Use proper way to observe space changes Change-Id: I30d65c3e653eb82f4095ed538aec9a4c8c2de337 --- vector/src/main/java/im/vector/app/AppStateHandler.kt | 7 ------- .../app/features/home/room/list/RoomListFragment.kt | 9 ++++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/vector/src/main/java/im/vector/app/AppStateHandler.kt b/vector/src/main/java/im/vector/app/AppStateHandler.kt index 902021d5a4..1ff3d97576 100644 --- a/vector/src/main/java/im/vector/app/AppStateHandler.kt +++ b/vector/src/main/java/im/vector/app/AppStateHandler.kt @@ -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?) - } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 2376725418..e8a0643b64 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -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(), 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 }