Adds back navigation to spaces
This commit is contained in:
parent
4adaa20f72
commit
93264812c0
@ -72,6 +72,8 @@ class AppStateHandler @Inject constructor(
|
|||||||
|
|
||||||
val selectedRoomGroupingFlow = selectedSpaceDataSource.stream()
|
val selectedRoomGroupingFlow = selectedSpaceDataSource.stream()
|
||||||
|
|
||||||
|
private val spaceBackstack = ArrayDeque<String?>()
|
||||||
|
|
||||||
fun getCurrentRoomGroupingMethod(): RoomGroupingMethod? {
|
fun getCurrentRoomGroupingMethod(): RoomGroupingMethod? {
|
||||||
// XXX we should somehow make it live :/ just a work around
|
// XXX we should somehow make it live :/ just a work around
|
||||||
// For example just after creating a space and switching to it the
|
// 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
|
val uSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
if (selectedSpaceDataSource.currentValue?.orNull() is RoomGroupingMethod.BySpace &&
|
if (currentSpace != null && spaceId == currentSpace.roomId) return
|
||||||
spaceId == selectedSpaceDataSource.currentValue?.orNull()?.space()?.roomId) return
|
|
||||||
val spaceSum = spaceId?.let { uSession.getRoomSummary(spaceId) }
|
val spaceSum = spaceId?.let { uSession.getRoomSummary(spaceId) }
|
||||||
|
|
||||||
|
if (isForwardNavigation) {
|
||||||
|
spaceBackstack.addLast(currentSpace?.roomId)
|
||||||
|
}
|
||||||
|
|
||||||
if (persistNow) {
|
if (persistNow) {
|
||||||
uiStateRepository.storeGroupingMethod(true, uSession.sessionId)
|
uiStateRepository.storeGroupingMethod(true, uSession.sessionId)
|
||||||
uiStateRepository.storeSelectedSpace(spaceSum?.roomId, uSession.sessionId)
|
uiStateRepository.storeSelectedSpace(spaceSum?.roomId, uSession.sessionId)
|
||||||
@ -151,6 +157,8 @@ class AppStateHandler @Inject constructor(
|
|||||||
}.launchIn(session.coroutineScope)
|
}.launchIn(session.coroutineScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSpaceBackstack() = spaceBackstack
|
||||||
|
|
||||||
fun safeActiveSpaceId(): String? {
|
fun safeActiveSpaceId(): String? {
|
||||||
return (selectedSpaceDataSource.currentValue?.orNull() as? RoomGroupingMethod.BySpace)?.spaceSummary?.roomId
|
return (selectedSpaceDataSource.currentValue?.orNull() as? RoomGroupingMethod.BySpace)?.spaceSummary?.roomId
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ class HomeDetailFragment @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
views.groupToolbarNavigateUp.setOnClickListener {
|
views.groupToolbarNavigateUp.setOnClickListener {
|
||||||
navigateUpOneSpace()
|
navigateBack()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.observeViewEvents { viewEvent ->
|
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() {
|
private fun navigateUpOneSpace() {
|
||||||
val parentId = getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
val parentId = getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
||||||
appStateHandler.setCurrentSpace(parentId)
|
setCurrentSpace(parentId)
|
||||||
sharedActionViewModel.post(HomeActivitySharedAction.CloseGroup)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentSpace() = (appStateHandler.getCurrentRoomGroupingMethod() as? RoomGroupingMethod.BySpace)?.spaceSummary
|
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) {
|
override fun onBackPressed(toolbarButton: Boolean) = if (getCurrentSpace() != null) {
|
||||||
navigateUpOneSpace()
|
navigateBack()
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
Loading…
Reference in New Issue
Block a user