Adds back button implementation of navigating up spaces

This commit is contained in:
ericdecanini 2022-05-17 11:28:37 +02:00
parent e706c5a3c8
commit bc500a567a
1 changed files with 16 additions and 14 deletions

View File

@ -33,6 +33,7 @@ import im.vector.app.R
import im.vector.app.RoomGroupingMethod import im.vector.app.RoomGroupingMethod
import im.vector.app.core.extensions.commitTransaction import im.vector.app.core.extensions.commitTransaction
import im.vector.app.core.extensions.toMvRxBundle import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.ColorProvider
@ -60,11 +61,6 @@ import org.matrix.android.sdk.api.session.group.model.GroupSummary
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject import javax.inject.Inject
/*
* TODO:
* 1) Change the hamburger menu to a back button when in a space
* 2) Make the back navigation button follow the same behaviour
*/
class HomeDetailFragment @Inject constructor( class HomeDetailFragment @Inject constructor(
private val avatarRenderer: AvatarRenderer, private val avatarRenderer: AvatarRenderer,
private val colorProvider: ColorProvider, private val colorProvider: ColorProvider,
@ -74,7 +70,8 @@ class HomeDetailFragment @Inject constructor(
private val appStateHandler: AppStateHandler private val appStateHandler: AppStateHandler
) : VectorBaseFragment<FragmentHomeDetailBinding>(), ) : VectorBaseFragment<FragmentHomeDetailBinding>(),
KeysBackupBanner.Delegate, KeysBackupBanner.Delegate,
CurrentCallsView.Callback { CurrentCallsView.Callback,
OnBackPressed {
private val viewModel: HomeDetailViewModel by fragmentViewModel() private val viewModel: HomeDetailViewModel by fragmentViewModel()
private val unknownDeviceDetectorSharedViewModel: UnknownDeviceDetectorSharedViewModel by activityViewModel() private val unknownDeviceDetectorSharedViewModel: UnknownDeviceDetectorSharedViewModel by activityViewModel()
@ -149,7 +146,7 @@ class HomeDetailFragment @Inject constructor(
} }
views.groupToolbarNavigateUp.setOnClickListener { views.groupToolbarNavigateUp.setOnClickListener {
navigateUpOneParentSpace() navigateUpOneSpace()
} }
viewModel.observeViewEvents { viewEvent -> viewModel.observeViewEvents { viewEvent ->
@ -194,15 +191,14 @@ class HomeDetailFragment @Inject constructor(
} }
} }
private fun navigateUpOneParentSpace() = with(appStateHandler) { private fun navigateUpOneSpace() {
val parentId = when (val roomGroupingMethod = getCurrentRoomGroupingMethod()) { val parentId = getCurrentSpace()?.flattenParentIds?.lastOrNull()
is RoomGroupingMethod.BySpace -> roomGroupingMethod.spaceSummary?.flattenParentIds?.firstOrNull { it.isNotBlank() } appStateHandler.setCurrentSpace(parentId)
else -> null
}
setCurrentSpace(parentId)
sharedActionViewModel.post(HomeActivitySharedAction.CloseGroup) sharedActionViewModel.post(HomeActivitySharedAction.CloseGroup)
} }
private fun getCurrentSpace() = (appStateHandler.getCurrentRoomGroupingMethod() as? RoomGroupingMethod.BySpace)?.spaceSummary
private fun handleCallStarted() { private fun handleCallStarted() {
dismissLoadingDialog() dismissLoadingDialog()
val fragmentTag = HomeTab.DialPad.toFragmentTag() val fragmentTag = HomeTab.DialPad.toFragmentTag()
@ -438,7 +434,6 @@ class HomeDetailFragment @Inject constructor(
} }
override fun invalidate() = withState(viewModel) { override fun invalidate() = withState(viewModel) {
// Timber.v(it.toString())
views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_people).render(it.notificationCountPeople, it.notificationHighlightPeople) views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_people).render(it.notificationCountPeople, it.notificationHighlightPeople)
views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_rooms).render(it.notificationCountRooms, it.notificationHighlightRooms) views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_rooms).render(it.notificationCountRooms, it.notificationHighlightRooms)
views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_notification).render(it.notificationCountCatchup, it.notificationHighlightCatchup) views.bottomNavigationView.getOrCreateBadge(R.id.bottom_action_notification).render(it.notificationCountCatchup, it.notificationHighlightCatchup)
@ -498,4 +493,11 @@ class HomeDetailFragment @Inject constructor(
} }
return this return this
} }
override fun onBackPressed(toolbarButton: Boolean) = if (getCurrentSpace() != null) {
navigateUpOneSpace()
true
} else {
false
}
} }