Unifies back and persisted navigation
This commit is contained in:
parent
06baae04ed
commit
fc301c8a2e
|
@ -60,7 +60,6 @@ class SpaceStateHandlerImpl @Inject constructor(
|
||||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||||
private val selectedSpaceDataSource = BehaviorDataSource<Option<RoomSummary>>(Option.empty())
|
private val selectedSpaceDataSource = BehaviorDataSource<Option<RoomSummary>>(Option.empty())
|
||||||
private val selectedSpaceFlow = selectedSpaceDataSource.stream()
|
private val selectedSpaceFlow = selectedSpaceDataSource.stream()
|
||||||
private val spaceBackstack = ArrayDeque<String?>()
|
|
||||||
|
|
||||||
override fun getCurrentSpace(): RoomSummary? {
|
override fun getCurrentSpace(): RoomSummary? {
|
||||||
return selectedSpaceDataSource.currentValue?.orNull()?.let { spaceSummary ->
|
return selectedSpaceDataSource.currentValue?.orNull()?.let { spaceSummary ->
|
||||||
|
@ -84,7 +83,7 @@ class SpaceStateHandlerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isForwardNavigation) {
|
if (isForwardNavigation) {
|
||||||
addToBackstacks(spaceToLeave, spaceToSet)
|
addToBackstack(spaceToLeave, spaceToSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (persistNow) {
|
if (persistNow) {
|
||||||
|
@ -106,15 +105,13 @@ class SpaceStateHandlerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addToBackstacks(spaceToLeave: RoomSummary?, spaceToSet: RoomSummary?) {
|
private fun addToBackstack(spaceToLeave: RoomSummary?, spaceToSet: RoomSummary?) {
|
||||||
spaceBackstack.addLast(spaceToLeave?.roomId)
|
|
||||||
|
|
||||||
// Only add to the persisted backstack if the space to set is not All Chats, else reset the persisted stack
|
// Only add to the persisted backstack if the space to set is not All Chats, else reset the persisted stack
|
||||||
if (spaceToSet != null && spaceToLeave != null) {
|
if (spaceToSet != null) {
|
||||||
val currentPersistedBackstack = vectorPreferences.getPersistedSpaceBackstack().toMutableList()
|
val currentPersistedBackstack = vectorPreferences.getPersistedSpaceBackstack().toMutableList()
|
||||||
currentPersistedBackstack.add(spaceToLeave.roomId)
|
currentPersistedBackstack.add(spaceToLeave?.roomId)
|
||||||
vectorPreferences.setPersistedSpaceBackstack(currentPersistedBackstack)
|
vectorPreferences.setPersistedSpaceBackstack(currentPersistedBackstack)
|
||||||
} else if (spaceToSet == null) {
|
} else {
|
||||||
vectorPreferences.setPersistedSpaceBackstack(emptyList())
|
vectorPreferences.setPersistedSpaceBackstack(emptyList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,12 +140,11 @@ class SpaceStateHandlerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun popSpaceBackstack(): String? {
|
override fun popSpaceBackstack(): String? {
|
||||||
val poppedSpaceId = spaceBackstack.removeLast()
|
|
||||||
vectorPreferences.getPersistedSpaceBackstack().toMutableList().apply {
|
vectorPreferences.getPersistedSpaceBackstack().toMutableList().apply {
|
||||||
removeLastOrNull()
|
val poppedSpaceId = removeLast()
|
||||||
vectorPreferences.setPersistedSpaceBackstack(this)
|
vectorPreferences.setPersistedSpaceBackstack(this)
|
||||||
|
return poppedSpaceId
|
||||||
}
|
}
|
||||||
return poppedSpaceId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPersistedSpaceBackstack() = vectorPreferences.getPersistedSpaceBackstack()
|
override fun getPersistedSpaceBackstack() = vectorPreferences.getPersistedSpaceBackstack()
|
||||||
|
|
|
@ -38,8 +38,11 @@ abstract class NewSpaceListHeaderItem : VectorEpoxyModel<NewSpaceListHeaderItem.
|
||||||
private fun buildSpaceHeaderText(context: Context): String {
|
private fun buildSpaceHeaderText(context: Context): String {
|
||||||
val allChats = context.getString(R.string.all_chats)
|
val allChats = context.getString(R.string.all_chats)
|
||||||
var spaceHeaderText = allChats
|
var spaceHeaderText = allChats
|
||||||
if (spaceHistory.isNotEmpty()) {
|
|
||||||
spaceHeaderText += " > ${spaceHistory.joinToString(" > ") { it.second }}"
|
val nonRootSpaceHistory = spaceHistory.filter { it.second.isNotEmpty() }
|
||||||
|
|
||||||
|
if (nonRootSpaceHistory.isNotEmpty()) {
|
||||||
|
spaceHeaderText += " > ${nonRootSpaceHistory.joinToString(" > ") { it.second }}"
|
||||||
}
|
}
|
||||||
if (currentSpace != null) {
|
if (currentSpace != null) {
|
||||||
spaceHeaderText += " > $currentSpace"
|
spaceHeaderText += " > $currentSpace"
|
||||||
|
|
Loading…
Reference in New Issue