From 92c6d599846734a10c2b011457952e4502b93f9a Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:28:33 +0100 Subject: [PATCH] Adds private setting usage to FtueAuthVariant --- .../app/features/onboarding/OnboardingViewModel.kt | 11 ++++++++++- .../app/features/onboarding/OnboardingViewState.kt | 3 ++- .../features/onboarding/ftueauth/FtueAuthVariant.kt | 10 +++++++--- .../vector/app/features/settings/VectorDataStore.kt | 1 - 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt index ca3c3644bd..63f1875235 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt @@ -46,6 +46,7 @@ import im.vector.app.features.login.LoginMode import im.vector.app.features.login.ReAuthHelper import im.vector.app.features.login.ServerType import im.vector.app.features.login.SignMode +import im.vector.app.features.settings.VectorDataStore import kotlinx.coroutines.Job import kotlinx.coroutines.launch import org.matrix.android.sdk.api.MatrixPatterns.getDomain @@ -78,7 +79,8 @@ class OnboardingViewModel @AssistedInject constructor( private val stringProvider: StringProvider, private val homeServerHistoryService: HomeServerHistoryService, private val vectorFeatures: VectorFeatures, - private val analyticsTracker: AnalyticsTracker + private val analyticsTracker: AnalyticsTracker, + private val vectorDataStore: VectorDataStore, ) : VectorViewModel(initialState) { @AssistedFactory @@ -90,6 +92,7 @@ class OnboardingViewModel @AssistedInject constructor( init { getKnownCustomHomeServersUrls() + observeDataStore() } private fun getKnownCustomHomeServersUrls() { @@ -98,6 +101,12 @@ class OnboardingViewModel @AssistedInject constructor( } } + private fun observeDataStore() = viewModelScope.launch { + vectorDataStore.forceLoginFallbackFlow.setOnEach { isForceLoginFallbackEnabled -> + copy(isForceLoginFallbackEnabled = isForceLoginFallbackEnabled) + } + } + // Store the last action, to redo it after user has trusted the untrusted certificate private var lastAction: OnboardingAction? = null private var currentHomeServerConnectionConfig: HomeServerConnectionConfig? = null diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt index 7bad2682a9..39c5094d30 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt @@ -62,7 +62,8 @@ data class OnboardingViewState( // Supported types for the login. We cannot use a sealed class for LoginType because it is not serializable @PersistState val loginModeSupportedTypes: List = emptyList(), - val knownCustomHomeServersUrls: List = emptyList() + val knownCustomHomeServersUrls: List = emptyList(), + val isForceLoginFallbackEnabled: Boolean = false, ) : MavericksState { fun isLoading(): Boolean { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt index 8e168b5d20..c5b65508b4 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt @@ -76,6 +76,8 @@ class FtueAuthVariant( private val popEnterAnim = R.anim.no_anim private val popExitAnim = R.anim.exit_fade_out + private var isForceLoginFallbackEnabled = false + private val topFragment: Fragment? get() = supportFragmentManager.findFragmentById(views.loginFragmentContainer.id) @@ -225,7 +227,7 @@ class FtueAuthVariant( } private fun registrationShouldFallback(registrationFlowResult: OnboardingViewEvents.RegistrationFlowResult) = - vectorFeatures.isForceLoginFallbackEnabled() || registrationFlowResult.containsUnsupportedRegistrationFlow() + isForceLoginFallbackEnabled || registrationFlowResult.containsUnsupportedRegistrationFlow() private fun OnboardingViewEvents.RegistrationFlowResult.containsUnsupportedRegistrationFlow() = flowResult.missingStages.any { !it.isSupported() } @@ -244,6 +246,8 @@ class FtueAuthVariant( } private fun updateWithState(viewState: OnboardingViewState) { + isForceLoginFallbackEnabled = viewState.isForceLoginFallbackEnabled + views.loginLoading.isVisible = if (vectorFeatures.isOnboardingPersonalizeEnabled()) { viewState.isLoading() } else { @@ -286,7 +290,7 @@ class FtueAuthVariant( } private fun handleSignInSelected(state: OnboardingViewState) { - if (vectorFeatures.isForceLoginFallbackEnabled()) { + if (isForceLoginFallbackEnabled) { onLoginModeNotSupported(state.loginModeSupportedTypes) } else { disambiguateLoginMode(state) @@ -318,7 +322,7 @@ class FtueAuthVariant( } private fun handleSignInWithMatrixId(state: OnboardingViewState) { - if (vectorFeatures.isForceLoginFallbackEnabled()) { + if (isForceLoginFallbackEnabled) { onLoginModeNotSupported(state.loginModeSupportedTypes) } else { openAuthLoginFragmentWithTag(FRAGMENT_LOGIN_TAG) 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 f742d93734..a7981a8b2a 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 @@ -60,7 +60,6 @@ class VectorDataStore @Inject constructor( } } - private val forceLoginFallback = booleanPreferencesKey("force_login_fallback") val forceLoginFallbackFlow: Flow = context.dataStore.data.map { preferences ->