mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Adds back navigation to spaces
This commit is contained in:
parent
4adaa20f72
commit
93264812c0
2 changed files with 28 additions and 7 deletions
|
@ -72,6 +72,8 @@ class AppStateHandler @Inject constructor(
|
|||
|
||||
val selectedRoomGroupingFlow = selectedSpaceDataSource.stream()
|
||||
|
||||
private val spaceBackstack = ArrayDeque<String?>()
|
||||
|
||||
fun getCurrentRoomGroupingMethod(): RoomGroupingMethod? {
|
||||
// XXX we should somehow make it live :/ just a work around
|
||||
// For example just after creating a space and switching to it the
|
||||
|
@ -87,12 +89,16 @@ class AppStateHandler @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun setCurrentSpace(spaceId: String?, session: Session? = null, persistNow: Boolean = false) {
|
||||
fun setCurrentSpace(spaceId: String?, session: Session? = null, persistNow: Boolean = false, isForwardNavigation: Boolean = true) {
|
||||
val currentSpace = (selectedSpaceDataSource.currentValue?.orNull() as? RoomGroupingMethod.BySpace)?.space()
|
||||
val uSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||
if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.BySpace &&
|
||||
spaceId == selectedSpaceDataSource.currentValue?.orNull()?.space()?.roomId) return
|
||||
if (currentSpace != null && spaceId == currentSpace.roomId) return
|
||||
val spaceSum = spaceId?.let { uSession.getRoomSummary(spaceId) }
|
||||
|
||||
if (isForwardNavigation) {
|
||||
spaceBackstack.addLast(currentSpace?.roomId)
|
||||
}
|
||||
|
||||
if (persistNow) {
|
||||
uiStateRepository.storeGroupingMethod(true, uSession.sessionId)
|
||||
uiStateRepository.storeSelectedSpace(spaceSum?.roomId, uSession.sessionId)
|
||||
|
@ -151,6 +157,8 @@ class AppStateHandler @Inject constructor(
|
|||
}.launchIn(session.coroutineScope)
|
||||
}
|
||||
|
||||
fun getSpaceBackstack() = spaceBackstack
|
||||
|
||||
fun safeActiveSpaceId(): String? {
|
||||
return (selectedSpaceDataSource.currentValue?.orNull() as? RoomGroupingMethod.BySpace)?.spaceSummary?.roomId
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ class HomeDetailFragment @Inject constructor(
|
|||
}
|
||||
|
||||
views.groupToolbarNavigateUp.setOnClickListener {
|
||||
navigateUpOneSpace()
|
||||
navigateBack()
|
||||
}
|
||||
|
||||
viewModel.observeViewEvents { viewEvent ->
|
||||
|
@ -191,10 +191,23 @@ class HomeDetailFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun navigateBack() {
|
||||
try {
|
||||
val lastSpace = appStateHandler.getSpaceBackstack().removeLast()
|
||||
setCurrentSpace(lastSpace)
|
||||
} catch (e: NoSuchElementException) {
|
||||
navigateUpOneSpace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setCurrentSpace(spaceId: String?) {
|
||||
appStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false)
|
||||
sharedActionViewModel.post(HomeActivitySharedAction.CloseGroup)
|
||||
}
|
||||
|
||||
private fun navigateUpOneSpace() {
|
||||
val parentId = getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
||||
appStateHandler.setCurrentSpace(parentId)
|
||||
sharedActionViewModel.post(HomeActivitySharedAction.CloseGroup)
|
||||
setCurrentSpace(parentId)
|
||||
}
|
||||
|
||||
private fun getCurrentSpace() = (appStateHandler.getCurrentRoomGroupingMethod() as? RoomGroupingMethod.BySpace)?.spaceSummary
|
||||
|
@ -495,7 +508,7 @@ class HomeDetailFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onBackPressed(toolbarButton: Boolean) = if (getCurrentSpace() != null) {
|
||||
navigateUpOneSpace()
|
||||
navigateBack()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
Loading…
Reference in a new issue