Adds working back navigation

This commit is contained in:
ericdecanini 2022-08-16 10:59:32 +02:00
parent 894d4f700e
commit 06baae04ed
2 changed files with 7 additions and 33 deletions

View file

@ -85,8 +85,6 @@ class SpaceStateHandlerImpl @Inject constructor(
if (isForwardNavigation) {
addToBackstacks(spaceToLeave, spaceToSet)
} else {
popBackstackUntil(spaceToSet)
}
if (persistNow) {
@ -121,19 +119,6 @@ class SpaceStateHandlerImpl @Inject constructor(
}
}
private fun popBackstackUntil(space: RoomSummary?) {
val spaceId = space?.roomId
while (spaceBackstack.last() != spaceId) {
spaceBackstack.removeLast()
}
val currentPersistedBackstack = vectorPreferences.getPersistedSpaceBackstack().toMutableList()
while (currentPersistedBackstack.last() != spaceId) {
currentPersistedBackstack.removeLast()
}
vectorPreferences.setPersistedSpaceBackstack(currentPersistedBackstack)
}
private fun observeActiveSession() {
sessionDataSource.stream()
.distinctUntilChanged()
@ -160,7 +145,7 @@ class SpaceStateHandlerImpl @Inject constructor(
override fun popSpaceBackstack(): String? {
val poppedSpaceId = spaceBackstack.removeLast()
vectorPreferences.getPersistedSpaceBackstack().toMutableList().apply {
removeLast()
removeLastOrNull()
vectorPreferences.setPersistedSpaceBackstack(this)
}
return poppedSpaceId

View file

@ -79,7 +79,6 @@ class NewHomeDetailFragment @Inject constructor(
private val viewModel: HomeDetailViewModel by fragmentViewModel()
private val unknownDeviceDetectorSharedViewModel: UnknownDeviceDetectorSharedViewModel by activityViewModel()
private val unreadMessagesSharedViewModel: UnreadMessagesSharedViewModel by activityViewModel()
private val serverBackupStatusViewModel: ServerBackupStatusViewModel by activityViewModel()
private lateinit var sharedActionViewModel: HomeSharedActionViewModel
@ -177,19 +176,6 @@ class NewHomeDetailFragment @Inject constructor(
}
}
private fun navigateBack() {
try {
val previousSpaceId = spaceStateHandler.popSpaceBackstack()
setCurrentSpace(previousSpaceId)
} catch (e: NoSuchElementException) {
requireActivity().finish()
}
}
private fun setCurrentSpace(spaceId: String?) {
spaceStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false)
}
private fun handleCallStarted() {
dismissLoadingDialog()
val fragmentTag = HomeTab.DialPad.toFragmentTag()
@ -454,8 +440,11 @@ class NewHomeDetailFragment @Inject constructor(
return this
}
override fun onBackPressed(toolbarButton: Boolean): Boolean {
navigateBack()
return true
override fun onBackPressed(toolbarButton: Boolean) = try {
val lastSpace = spaceStateHandler.popSpaceBackstack()
spaceStateHandler.setCurrentSpace(lastSpace, isForwardNavigation = false)
true
} catch (e: NoSuchElementException) {
false
}
}