Fixes back navigation
This commit is contained in:
parent
d8115a79a4
commit
7ee58ccc88
@ -77,14 +77,14 @@ class SpaceStateHandlerImpl @Inject constructor(
|
|||||||
val activeSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
val activeSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
val currentSpace = selectedSpaceDataSource.currentValue?.orNull()
|
val currentSpace = selectedSpaceDataSource.currentValue?.orNull()
|
||||||
val spaceSummary = spaceId?.let { activeSession.getRoomSummary(spaceId) }
|
val spaceSummary = spaceId?.let { activeSession.getRoomSummary(spaceId) }
|
||||||
val sameSpaceSelected = currentSpace != null && spaceId == currentSpace.roomId
|
val sameSpaceSelected = spaceId == currentSpace?.roomId
|
||||||
|
|
||||||
if (sameSpaceSelected) {
|
if (sameSpaceSelected) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isForwardNavigation) {
|
if (isForwardNavigation) {
|
||||||
addToBackstacks(spaceSummary)
|
addToBackstacks(currentSpace)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (persistNow) {
|
if (persistNow) {
|
||||||
@ -107,7 +107,7 @@ class SpaceStateHandlerImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addToBackstacks(space: RoomSummary?) {
|
private fun addToBackstacks(space: RoomSummary?) {
|
||||||
val spaceId = space?.roomId ?: ROOT_SPACE_ID
|
val spaceId = space?.roomId
|
||||||
spaceBackstack.addLast(spaceId)
|
spaceBackstack.addLast(spaceId)
|
||||||
|
|
||||||
val currentPersistedBackstack = vectorPreferences.getPersistedSpaceBackstack().toMutableList()
|
val currentPersistedBackstack = vectorPreferences.getPersistedSpaceBackstack().toMutableList()
|
||||||
@ -155,8 +155,4 @@ class SpaceStateHandlerImpl @Inject constructor(
|
|||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
uiStateRepository.storeSelectedSpace(selectedSpaceDataSource.currentValue?.orNull()?.roomId, session.sessionId)
|
uiStateRepository.storeSelectedSpace(selectedSpaceDataSource.currentValue?.orNull()?.roomId, session.sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val ROOT_SPACE_ID = "ROOT"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -178,14 +178,18 @@ class NewHomeDetailFragment @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun navigateBack() {
|
private fun navigateBack() {
|
||||||
val previousSpaceId = spaceStateHandler.getSpaceBackstack().removeLastOrNull()
|
val spaceBackstack = spaceStateHandler.getSpaceBackstack()
|
||||||
val parentSpaceId = spaceStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
|
||||||
setCurrentSpace(previousSpaceId ?: parentSpaceId)
|
try {
|
||||||
|
val previousSpaceId = spaceBackstack.removeLast()
|
||||||
|
setCurrentSpace(previousSpaceId)
|
||||||
|
} catch (e: NoSuchElementException) {
|
||||||
|
requireActivity().finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setCurrentSpace(spaceId: String?) {
|
private fun setCurrentSpace(spaceId: String?) {
|
||||||
spaceStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false)
|
spaceStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false)
|
||||||
sharedActionViewModel.post(HomeActivitySharedAction.OnCloseSpace)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleCallStarted() {
|
private fun handleCallStarted() {
|
||||||
@ -452,10 +456,8 @@ class NewHomeDetailFragment @Inject constructor(
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(toolbarButton: Boolean) = if (spaceStateHandler.getCurrentSpace() != null) {
|
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
||||||
navigateBack()
|
navigateBack()
|
||||||
true
|
return true
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import androidx.core.content.edit
|
|||||||
import com.squareup.seismic.ShakeDetector
|
import com.squareup.seismic.ShakeDetector
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.DefaultSharedPreferences
|
import im.vector.app.core.di.DefaultSharedPreferences
|
||||||
import im.vector.app.core.extensions.join
|
|
||||||
import im.vector.app.core.resources.BuildMeta
|
import im.vector.app.core.resources.BuildMeta
|
||||||
import im.vector.app.core.time.Clock
|
import im.vector.app.core.time.Clock
|
||||||
import im.vector.app.features.disclaimer.SHARED_PREF_KEY
|
import im.vector.app.features.disclaimer.SHARED_PREF_KEY
|
||||||
@ -1121,7 +1120,7 @@ class VectorPreferences @Inject constructor(
|
|||||||
*
|
*
|
||||||
* Only the IDs of the spaces are stored
|
* Only the IDs of the spaces are stored
|
||||||
*/
|
*/
|
||||||
fun setPersistedSpaceBackstack(spaceBackstack: List<String>) {
|
fun setPersistedSpaceBackstack(spaceBackstack: List<String?>) {
|
||||||
val spaceIdsJoined = spaceBackstack.joinToString(",")
|
val spaceIdsJoined = spaceBackstack.joinToString(",")
|
||||||
defaultPrefs.edit().putString(SETTINGS_PERSISTED_SPACE_BACKSTACK, spaceIdsJoined).apply()
|
defaultPrefs.edit().putString(SETTINGS_PERSISTED_SPACE_BACKSTACK, spaceIdsJoined).apply()
|
||||||
}
|
}
|
||||||
@ -1129,7 +1128,7 @@ class VectorPreferences @Inject constructor(
|
|||||||
/**
|
/**
|
||||||
* Gets the space backstack used for up navigation
|
* Gets the space backstack used for up navigation
|
||||||
*/
|
*/
|
||||||
fun getPersistedSpaceBackstack(): List<String> {
|
fun getPersistedSpaceBackstack(): List<String?> {
|
||||||
val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null)
|
val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null)
|
||||||
return spaceIdsJoined?.split(",").orEmpty()
|
return spaceIdsJoined?.split(",").orEmpty()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user