mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
Fixes back navigation
This commit is contained in:
parent
d8115a79a4
commit
7ee58ccc88
3 changed files with 15 additions and 18 deletions
|
@ -77,14 +77,14 @@ class SpaceStateHandlerImpl @Inject constructor(
|
|||
val activeSession = session ?: activeSessionHolder.getSafeActiveSession() ?: return
|
||||
val currentSpace = selectedSpaceDataSource.currentValue?.orNull()
|
||||
val spaceSummary = spaceId?.let { activeSession.getRoomSummary(spaceId) }
|
||||
val sameSpaceSelected = currentSpace != null && spaceId == currentSpace.roomId
|
||||
val sameSpaceSelected = spaceId == currentSpace?.roomId
|
||||
|
||||
if (sameSpaceSelected) {
|
||||
return
|
||||
}
|
||||
|
||||
if (isForwardNavigation) {
|
||||
addToBackstacks(spaceSummary)
|
||||
addToBackstacks(currentSpace)
|
||||
}
|
||||
|
||||
if (persistNow) {
|
||||
|
@ -107,7 +107,7 @@ class SpaceStateHandlerImpl @Inject constructor(
|
|||
}
|
||||
|
||||
private fun addToBackstacks(space: RoomSummary?) {
|
||||
val spaceId = space?.roomId ?: ROOT_SPACE_ID
|
||||
val spaceId = space?.roomId
|
||||
spaceBackstack.addLast(spaceId)
|
||||
|
||||
val currentPersistedBackstack = vectorPreferences.getPersistedSpaceBackstack().toMutableList()
|
||||
|
@ -155,8 +155,4 @@ class SpaceStateHandlerImpl @Inject constructor(
|
|||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||
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() {
|
||||
val previousSpaceId = spaceStateHandler.getSpaceBackstack().removeLastOrNull()
|
||||
val parentSpaceId = spaceStateHandler.getCurrentSpace()?.flattenParentIds?.lastOrNull()
|
||||
setCurrentSpace(previousSpaceId ?: parentSpaceId)
|
||||
val spaceBackstack = spaceStateHandler.getSpaceBackstack()
|
||||
|
||||
try {
|
||||
val previousSpaceId = spaceBackstack.removeLast()
|
||||
setCurrentSpace(previousSpaceId)
|
||||
} catch (e: NoSuchElementException) {
|
||||
requireActivity().finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setCurrentSpace(spaceId: String?) {
|
||||
spaceStateHandler.setCurrentSpace(spaceId, isForwardNavigation = false)
|
||||
sharedActionViewModel.post(HomeActivitySharedAction.OnCloseSpace)
|
||||
}
|
||||
|
||||
private fun handleCallStarted() {
|
||||
|
@ -452,10 +456,8 @@ class NewHomeDetailFragment @Inject constructor(
|
|||
return this
|
||||
}
|
||||
|
||||
override fun onBackPressed(toolbarButton: Boolean) = if (spaceStateHandler.getCurrentSpace() != null) {
|
||||
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
||||
navigateBack()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import androidx.core.content.edit
|
|||
import com.squareup.seismic.ShakeDetector
|
||||
import im.vector.app.R
|
||||
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.time.Clock
|
||||
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
|
||||
*/
|
||||
fun setPersistedSpaceBackstack(spaceBackstack: List<String>) {
|
||||
fun setPersistedSpaceBackstack(spaceBackstack: List<String?>) {
|
||||
val spaceIdsJoined = spaceBackstack.joinToString(",")
|
||||
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
|
||||
*/
|
||||
fun getPersistedSpaceBackstack(): List<String> {
|
||||
fun getPersistedSpaceBackstack(): List<String?> {
|
||||
val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null)
|
||||
return spaceIdsJoined?.split(",").orEmpty()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue