From 2917d4e4d680f590454c153dca5bb154c1a16c32 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:01:18 +0100 Subject: [PATCH] Adds forceLoginFallback private setting --- .../settings/DebugPrivateSettingsViewActions.kt | 1 + .../settings/DebugPrivateSettingsViewModel.kt | 17 +++++++++++++---- .../settings/DebugPrivateSettingsViewState.kt | 3 ++- .../app/features/settings/VectorDataStore.kt | 13 +++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt index ecbb241387..1c76cf6fb2 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewActions.kt @@ -20,4 +20,5 @@ import im.vector.app.core.platform.VectorViewModelAction sealed class DebugPrivateSettingsViewActions : VectorViewModelAction { data class SetDialPadVisibility(val force: Boolean) : DebugPrivateSettingsViewActions() + data class SetForceLoginFallbackEnabled(val force: Boolean) : DebugPrivateSettingsViewActions() } diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt index 624c46556a..7b64349f47 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewModel.kt @@ -45,15 +45,18 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor( private fun observeVectorDataStore() { vectorDataStore.forceDialPadDisplayFlow.setOnEach { - copy( - dialPadVisible = it - ) + copy(dialPadVisible = it) + } + + vectorDataStore.forceLoginFallbackFlow.setOnEach { + copy(forceLoginFallback = false) } } override fun handle(action: DebugPrivateSettingsViewActions) { when (action) { - is DebugPrivateSettingsViewActions.SetDialPadVisibility -> handleSetDialPadVisibility(action) + is DebugPrivateSettingsViewActions.SetDialPadVisibility -> handleSetDialPadVisibility(action) + is DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled -> handleSetForceLoginFallbackEnabled(action) } } @@ -62,4 +65,10 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor( vectorDataStore.setForceDialPadDisplay(action.force) } } + + private fun handleSetForceLoginFallbackEnabled(action: DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled) { + viewModelScope.launch { + vectorDataStore.setForceLoginFallbackFlow(action.force) + } + } } diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt index 0ad4b185ec..7fca29af8c 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsViewState.kt @@ -19,5 +19,6 @@ package im.vector.app.features.debug.settings import com.airbnb.mvrx.MavericksState data class DebugPrivateSettingsViewState( - val dialPadVisible: Boolean = false + val dialPadVisible: Boolean = false, + val forceLoginFallback: Boolean = false, ) : MavericksState diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorDataStore.kt b/vector/src/main/java/im/vector/app/features/settings/VectorDataStore.kt index 6a5ef0ac99..f742d93734 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorDataStore.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorDataStore.kt @@ -59,4 +59,17 @@ class VectorDataStore @Inject constructor( settings[forceDialPadDisplay] = force } } + + + private val forceLoginFallback = booleanPreferencesKey("force_login_fallback") + + val forceLoginFallbackFlow: Flow = context.dataStore.data.map { preferences -> + preferences[forceLoginFallback].orFalse() + } + + suspend fun setForceLoginFallbackFlow(force: Boolean) { + context.dataStore.edit { settings -> + settings[forceLoginFallback] = force + } + } }