mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Refactors space backstack handling
This commit is contained in:
parent
7ee58ccc88
commit
5012f37e6f
@ -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.
|
||||
|
@ -138,7 +138,14 @@ class SpaceStateHandlerImpl @Inject constructor(
|
||||
}.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
|
||||
|
||||
|
@ -183,7 +183,7 @@ class HomeDetailFragment @Inject constructor(
|
||||
}
|
||||
|
||||
private fun navigateBack() {
|
||||
val previousSpaceId = spaceStateHandler.getSpaceBackstack().removeLastOrNull()
|
||||
val previousSpaceId = spaceStateHandler.popSpaceBackstack()
|
||||
val parentSpaceId = spaceStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
||||
setCurrentSpace(previousSpaceId ?: parentSpaceId)
|
||||
}
|
||||
|
@ -178,10 +178,8 @@ class NewHomeDetailFragment @Inject constructor(
|
||||
}
|
||||
|
||||
private fun navigateBack() {
|
||||
val spaceBackstack = spaceStateHandler.getSpaceBackstack()
|
||||
|
||||
try {
|
||||
val previousSpaceId = spaceBackstack.removeLast()
|
||||
val previousSpaceId = spaceStateHandler.popSpaceBackstack()
|
||||
setCurrentSpace(previousSpaceId)
|
||||
} catch (e: NoSuchElementException) {
|
||||
requireActivity().finish()
|
||||
|
Loading…
Reference in New Issue
Block a user