Adds persisted backstack

This commit is contained in:
ericdecanini 2022-08-12 11:17:13 +02:00
parent 527bcf2e6f
commit d8115a79a4
2 changed files with 38 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import im.vector.app.core.utils.BehaviorDataSource
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.plan.UserProperties
import im.vector.app.features.session.coroutineScope
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.ui.UiStateRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -52,7 +53,8 @@ class SpaceStateHandlerImpl @Inject constructor(
private val sessionDataSource: ActiveSessionDataSource,
private val uiStateRepository: UiStateRepository,
private val activeSessionHolder: ActiveSessionHolder,
private val analyticsTracker: AnalyticsTracker
private val analyticsTracker: AnalyticsTracker,
private val vectorPreferences: VectorPreferences,
) : SpaceStateHandler {
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
@ -82,7 +84,7 @@ class SpaceStateHandlerImpl @Inject constructor(
}
if (isForwardNavigation) {
spaceBackstack.addLast(currentSpace?.roomId)
addToBackstacks(spaceSummary)
}
if (persistNow) {
@ -104,6 +106,15 @@ class SpaceStateHandlerImpl @Inject constructor(
}
}
private fun addToBackstacks(space: RoomSummary?) {
val spaceId = space?.roomId ?: ROOT_SPACE_ID
spaceBackstack.addLast(spaceId)
val currentPersistedBackstack = vectorPreferences.getPersistedSpaceBackstack().toMutableList()
currentPersistedBackstack.add(spaceId)
vectorPreferences.setPersistedSpaceBackstack(currentPersistedBackstack)
}
private fun observeActiveSession() {
sessionDataSource.stream()
.distinctUntilChanged()
@ -144,4 +155,8 @@ 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"
}
}

View File

@ -25,6 +25,7 @@ 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
@ -77,6 +78,7 @@ class VectorPreferences @Inject constructor(
const val SETTINGS_ALLOW_INTEGRATIONS_KEY = "SETTINGS_ALLOW_INTEGRATIONS_KEY"
const val SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY = "SETTINGS_INTEGRATION_MANAGER_UI_URL_KEY"
const val SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY = "SETTINGS_SECURE_MESSAGE_RECOVERY_PREFERENCE_KEY"
const val SETTINGS_PERSISTED_SPACE_BACKSTACK = "SETTINGS_PERSISTED_SPACE_BACKSTACK"
const val SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT = "SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT"
// const val SETTINGS_SECURE_BACKUP_RESET_PREFERENCE_KEY = "SETTINGS_SECURE_BACKUP_RESET_PREFERENCE_KEY"
@ -1113,6 +1115,25 @@ class VectorPreferences @Inject constructor(
.apply()
}
/**
* Sets the space backstack that is used for up navigation
* This needs to be persisted because navigating up through spaces should work across sessions
*
* Only the IDs of the spaces are stored
*/
fun setPersistedSpaceBackstack(spaceBackstack: List<String>) {
val spaceIdsJoined = spaceBackstack.joinToString(",")
defaultPrefs.edit().putString(SETTINGS_PERSISTED_SPACE_BACKSTACK, spaceIdsJoined).apply()
}
/**
* Gets the space backstack used for up navigation
*/
fun getPersistedSpaceBackstack(): List<String> {
val spaceIdsJoined = defaultPrefs.getString(SETTINGS_PERSISTED_SPACE_BACKSTACK, null)
return spaceIdsJoined?.split(",").orEmpty()
}
fun showLiveSenderInfo(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_TIMELINE_SHOW_LIVE_SENDER_INFO, getDefault(R.bool.settings_timeline_show_live_sender_info_default))
}