Refactors space backstack handling

This commit is contained in:
ericdecanini 2022-08-12 13:28:01 +02:00
parent 7ee58ccc88
commit 5012f37e6f
4 changed files with 13 additions and 8 deletions

View File

@ -51,11 +51,11 @@ interface SpaceStateHandler : DefaultLifecycleObserver {
) )
/** /**
* Gets the current backstack of spaces (via their id). * Gets the Space ID of the space on top of the backstack
* *
* null may be an entry in the ArrayDeque to indicate the root space (All Chats) * May return null to indicate the All Chats space
*/ */
fun getSpaceBackstack(): ArrayDeque<String?> fun popSpaceBackstack(): String?
/** /**
* Gets a flow of the selected space for clients to react immediately to space changes. * Gets a flow of the selected space for clients to react immediately to space changes.

View File

@ -138,7 +138,14 @@ class SpaceStateHandlerImpl @Inject constructor(
}.launchIn(session.coroutineScope) }.launchIn(session.coroutineScope)
} }
override fun getSpaceBackstack() = spaceBackstack override fun popSpaceBackstack(): String? {
val poppedSpaceId = spaceBackstack.removeLast()
vectorPreferences.getPersistedSpaceBackstack().toMutableList().apply {
removeLast()
vectorPreferences.setPersistedSpaceBackstack(this)
}
return poppedSpaceId
}
override fun getSelectedSpaceFlow() = selectedSpaceFlow override fun getSelectedSpaceFlow() = selectedSpaceFlow

View File

@ -183,7 +183,7 @@ class HomeDetailFragment @Inject constructor(
} }
private fun navigateBack() { private fun navigateBack() {
val previousSpaceId = spaceStateHandler.getSpaceBackstack().removeLastOrNull() val previousSpaceId = spaceStateHandler.popSpaceBackstack()
val parentSpaceId = spaceStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull() val parentSpaceId = spaceStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull()
setCurrentSpace(previousSpaceId ?: parentSpaceId) setCurrentSpace(previousSpaceId ?: parentSpaceId)
} }

View File

@ -178,10 +178,8 @@ class NewHomeDetailFragment @Inject constructor(
} }
private fun navigateBack() { private fun navigateBack() {
val spaceBackstack = spaceStateHandler.getSpaceBackstack()
try { try {
val previousSpaceId = spaceBackstack.removeLast() val previousSpaceId = spaceStateHandler.popSpaceBackstack()
setCurrentSpace(previousSpaceId) setCurrentSpace(previousSpaceId)
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
requireActivity().finish() requireActivity().finish()