diff --git a/vector/src/main/java/im/vector/app/SpaceStateHandlerImpl.kt b/vector/src/main/java/im/vector/app/SpaceStateHandlerImpl.kt index 53e2ebd1b5..6c70c3266a 100644 --- a/vector/src/main/java/im/vector/app/SpaceStateHandlerImpl.kt +++ b/vector/src/main/java/im/vector/app/SpaceStateHandlerImpl.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt index 09617a8dd8..4e429c4bf9 100644 --- a/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/NewHomeDetailFragment.kt @@ -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 } }