From 507ddc2d4a00023201b2d92453d70e2f4a091c49 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 23 Feb 2022 13:02:45 +0100 Subject: [PATCH 01/14] adds forceLoginFallback debug feature --- .../app/features/debug/features/DebugFeaturesStateFactory.kt | 5 +++++ .../app/features/debug/features/DebugVectorFeatures.kt | 3 +++ .../src/main/java/im/vector/app/features/VectorFeatures.kt | 2 ++ 3 files changed, 10 insertions(+) diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt index fb803162a7..46f46ad964 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt @@ -48,6 +48,11 @@ class DebugFeaturesStateFactory @Inject constructor( label = "FTUE Use Case", key = DebugFeatureKeys.onboardingUseCase, factory = VectorFeatures::isOnboardingUseCaseEnabled + ), + createBooleanFeature( + label = "Force login fallback", + key = DebugFeatureKeys.forceLoginFallback, + factory = VectorFeatures::isForceLoginFallbackEnabled ) )) } diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt index 6ca33ca968..396dd02a37 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt @@ -51,6 +51,8 @@ class DebugVectorFeatures( override fun isOnboardingUseCaseEnabled(): Boolean = read(DebugFeatureKeys.onboardingUseCase) ?: vectorFeatures.isOnboardingUseCaseEnabled() + override fun isForceLoginFallbackEnabled(): Boolean = read(DebugFeatureKeys.forceLoginFallback) ?: vectorFeatures.isForceLoginFallbackEnabled() + fun override(value: T?, key: Preferences.Key) = updatePreferences { if (value == null) { it.remove(key) @@ -102,4 +104,5 @@ object DebugFeatureKeys { val onboardingAlreadyHaveAnAccount = booleanPreferencesKey("onboarding-already-have-an-account") val onboardingSplashCarousel = booleanPreferencesKey("onboarding-splash-carousel") val onboardingUseCase = booleanPreferencesKey("onbboarding-splash-carousel") + val forceLoginFallback = booleanPreferencesKey("force-login-fallback") } diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index fe8d58fb51..451ecc4722 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -24,6 +24,7 @@ interface VectorFeatures { fun isOnboardingAlreadyHaveAccountSplashEnabled(): Boolean fun isOnboardingSplashCarouselEnabled(): Boolean fun isOnboardingUseCaseEnabled(): Boolean + fun isForceLoginFallbackEnabled(): Boolean enum class OnboardingVariant { LEGACY, @@ -37,4 +38,5 @@ class DefaultVectorFeatures : VectorFeatures { override fun isOnboardingAlreadyHaveAccountSplashEnabled() = true override fun isOnboardingSplashCarouselEnabled() = true override fun isOnboardingUseCaseEnabled() = true + override fun isForceLoginFallbackEnabled() = false } From 713248805c5c21c402ba9cb867f3c00f9c9dc11f Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 23 Feb 2022 13:25:16 +0100 Subject: [PATCH 02/14] adds feature flag usage to registration flow result --- .../app/features/onboarding/ftueauth/FtueAuthVariant.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 33d57dd95c..e550913e6c 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 @@ -123,8 +123,7 @@ class FtueAuthVariant( private fun handleOnboardingViewEvents(viewEvents: OnboardingViewEvents) { when (viewEvents) { is OnboardingViewEvents.RegistrationFlowResult -> { - // Check that all flows are supported by the application - if (viewEvents.flowResult.missingStages.any { !it.isSupported() }) { + if (registrationShouldFallback(viewEvents)) { // Display a popup to propose use web fallback onRegistrationStageNotSupported() } else { @@ -223,6 +222,12 @@ class FtueAuthVariant( }.exhaustive } + private fun registrationShouldFallback(registrationFlowResult: OnboardingViewEvents.RegistrationFlowResult) = + vectorFeatures.isForceLoginFallbackEnabled() || registrationFlowResult.containsUnsupportedRegistrationFlow() + + private fun OnboardingViewEvents.RegistrationFlowResult.containsUnsupportedRegistrationFlow() = + flowResult.missingStages.any { !it.isSupported() } + private fun updateWithState(viewState: OnboardingViewState) { if (viewState.isUserLogged()) { val intent = HomeActivity.newIntent( From f18808b4d7b689920c8213d819916bbf312736e5 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 23 Feb 2022 16:53:16 +0100 Subject: [PATCH 03/14] refactors FtueAuthVariant with new feature flag on registration and signin --- .../lib/core/utils/extensions/Global.kt | 20 +++ .../onboarding/ftueauth/FtueAuthVariant.kt | 115 ++++++++++-------- 2 files changed, 83 insertions(+), 52 deletions(-) create mode 100644 library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt diff --git a/library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt b/library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt new file mode 100644 index 0000000000..3b508ab7b2 --- /dev/null +++ b/library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.lib.core.utils.extensions + +@Suppress("UNUSED_PARAMETER") +fun doNothing(reason: String = "") = Unit 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 e550913e6c..d08136eb70 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 @@ -52,6 +52,7 @@ import im.vector.app.features.onboarding.OnboardingViewModel import im.vector.app.features.onboarding.OnboardingViewState import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragment import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragmentArgument +import im.vector.lib.core.utils.extensions.doNothing import org.matrix.android.sdk.api.auth.registration.FlowResult import org.matrix.android.sdk.api.auth.registration.Stage import org.matrix.android.sdk.api.extensions.tryOrNull @@ -109,7 +110,7 @@ class FtueAuthVariant( } override fun setIsLoading(isLoading: Boolean) { - // do nothing + doNothing() } private fun addFirstFragment() { @@ -134,11 +135,7 @@ class FtueAuthVariant( // First ask for login and password // I add a tag to indicate that this fragment is a registration stage. // This way it will be automatically popped in when starting the next registration stage - activity.addFragmentToBackstack(views.loginFragmentContainer, - FtueAuthLoginFragment::class.java, - tag = FRAGMENT_REGISTRATION_STAGE_TAG, - option = commonOption - ) + openAuthLoginFragmentWithTag(FRAGMENT_REGISTRATION_STAGE_TAG) } } } @@ -228,6 +225,19 @@ class FtueAuthVariant( private fun OnboardingViewEvents.RegistrationFlowResult.containsUnsupportedRegistrationFlow() = flowResult.missingStages.any { !it.isSupported() } + private fun onRegistrationStageNotSupported() { + MaterialAlertDialogBuilder(activity) + .setTitle(R.string.app_name) + .setMessage(activity.getString(R.string.login_registration_not_supported)) + .setPositiveButton(R.string.yes) { _, _ -> + activity.addFragmentToBackstack(views.loginFragmentContainer, + FtueAuthWebFragment::class.java, + option = commonOption) + } + .setNegativeButton(R.string.no, null) + .show() + } + private fun updateWithState(viewState: OnboardingViewState) { if (viewState.isUserLogged()) { val intent = HomeActivity.newIntent( @@ -270,29 +280,56 @@ class FtueAuthVariant( // state.signMode could not be ready yet. So use value from the ViewEvent when (OnboardingViewEvents.signMode) { SignMode.Unknown -> error("Sign mode has to be set before calling this method") - SignMode.SignUp -> { - // This is managed by the OnboardingViewEvents - } - SignMode.SignIn -> { - // It depends on the LoginMode - when (state.loginMode) { - LoginMode.Unknown, - is LoginMode.Sso -> error("Developer error") - is LoginMode.SsoAndPassword, - LoginMode.Password -> activity.addFragmentToBackstack(views.loginFragmentContainer, - FtueAuthLoginFragment::class.java, - tag = FRAGMENT_LOGIN_TAG, - option = commonOption) - LoginMode.Unsupported -> onLoginModeNotSupported(state.loginModeSupportedTypes) - }.exhaustive - } - SignMode.SignInWithMatrixId -> activity.addFragmentToBackstack(views.loginFragmentContainer, - FtueAuthLoginFragment::class.java, - tag = FRAGMENT_LOGIN_TAG, - option = commonOption) + SignMode.SignUp -> doNothing("This is managed by the OnboardingViewEvents") + SignMode.SignIn -> handleSignInSelected(state) + SignMode.SignInWithMatrixId -> handleSignInWithMatrixId(state) }.exhaustive } + private fun handleSignInSelected(state: OnboardingViewState) { + if (vectorFeatures.isForceLoginFallbackEnabled()) + onLoginModeNotSupported(state.loginModeSupportedTypes) + else + disambiguateLoginMode(state) + } + + private fun disambiguateLoginMode(state: OnboardingViewState) = when (state.loginMode) { + LoginMode.Unknown, + is LoginMode.Sso -> error("Developer error") + is LoginMode.SsoAndPassword, + LoginMode.Password -> openAuthLoginFragmentWithTag(FRAGMENT_LOGIN_TAG) + LoginMode.Unsupported -> onLoginModeNotSupported(state.loginModeSupportedTypes) + }.exhaustive + + private fun openAuthLoginFragmentWithTag(tag: String) { + activity.addFragmentToBackstack(views.loginFragmentContainer, + FtueAuthLoginFragment::class.java, + tag = tag, + option = commonOption) + } + + private fun onLoginModeNotSupported(supportedTypes: List) { + MaterialAlertDialogBuilder(activity) + .setTitle(R.string.app_name) + .setMessage(activity.getString(R.string.login_mode_not_supported, supportedTypes.joinToString { "'$it'" })) + .setPositiveButton(R.string.yes) { _, _ -> openAuthWebFragment() } + .setNegativeButton(R.string.no, null) + .show() + } + + private fun handleSignInWithMatrixId(state: OnboardingViewState) { + if (vectorFeatures.isForceLoginFallbackEnabled()) + onLoginModeNotSupported(state.loginModeSupportedTypes) + else + openAuthLoginFragmentWithTag(FRAGMENT_LOGIN_TAG) + } + + private fun openAuthWebFragment() { + activity.addFragmentToBackstack(views.loginFragmentContainer, + FtueAuthWebFragment::class.java, + option = commonOption) + } + /** * Handle the SSO redirection here */ @@ -302,32 +339,6 @@ class FtueAuthVariant( ?.let { onboardingViewModel.handle(OnboardingAction.LoginWithToken(it)) } } - private fun onRegistrationStageNotSupported() { - MaterialAlertDialogBuilder(activity) - .setTitle(R.string.app_name) - .setMessage(activity.getString(R.string.login_registration_not_supported)) - .setPositiveButton(R.string.yes) { _, _ -> - activity.addFragmentToBackstack(views.loginFragmentContainer, - FtueAuthWebFragment::class.java, - option = commonOption) - } - .setNegativeButton(R.string.no, null) - .show() - } - - private fun onLoginModeNotSupported(supportedTypes: List) { - MaterialAlertDialogBuilder(activity) - .setTitle(R.string.app_name) - .setMessage(activity.getString(R.string.login_mode_not_supported, supportedTypes.joinToString { "'$it'" })) - .setPositiveButton(R.string.yes) { _, _ -> - activity.addFragmentToBackstack(views.loginFragmentContainer, - FtueAuthWebFragment::class.java, - option = commonOption) - } - .setNegativeButton(R.string.no, null) - .show() - } - private fun handleRegistrationNavigation(flowResult: FlowResult) { // Complete all mandatory stages first val mandatoryStage = flowResult.missingStages.firstOrNull { it.mandatory } From 137d804cfa88d02e58e7a8dafe1b028eae44ecec Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 23 Feb 2022 17:26:50 +0100 Subject: [PATCH 04/14] adds changelog file --- changelog.d/5325.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5325.feature diff --git a/changelog.d/5325.feature b/changelog.d/5325.feature new file mode 100644 index 0000000000..23754c790d --- /dev/null +++ b/changelog.d/5325.feature @@ -0,0 +1 @@ +Adds forceLoginFallback feature flag and usages to FTUE login and registration \ No newline at end of file From c89f28ffb201bd32e77d26536549a3f9079846d0 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 23 Feb 2022 17:43:40 +0100 Subject: [PATCH 05/14] adds missing brackets on multiline if statements --- .../features/onboarding/ftueauth/FtueAuthVariant.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 962b40df66..8e168b5d20 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 @@ -286,10 +286,11 @@ class FtueAuthVariant( } private fun handleSignInSelected(state: OnboardingViewState) { - if (vectorFeatures.isForceLoginFallbackEnabled()) + if (vectorFeatures.isForceLoginFallbackEnabled()) { onLoginModeNotSupported(state.loginModeSupportedTypes) - else + } else { disambiguateLoginMode(state) + } } private fun disambiguateLoginMode(state: OnboardingViewState) = when (state.loginMode) { @@ -317,10 +318,11 @@ class FtueAuthVariant( } private fun handleSignInWithMatrixId(state: OnboardingViewState) { - if (vectorFeatures.isForceLoginFallbackEnabled()) + if (vectorFeatures.isForceLoginFallbackEnabled()) { onLoginModeNotSupported(state.loginModeSupportedTypes) - else + } else { openAuthLoginFragmentWithTag(FRAGMENT_LOGIN_TAG) + } } private fun openAuthWebFragment() { From 4ebaa349c31f34275d7967d6cc05636445e252aa Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 14:45:48 +0100 Subject: [PATCH 06/14] Reverts adding force login fallback flag to debug features --- .../app/features/debug/features/DebugFeaturesStateFactory.kt | 5 ----- .../app/features/debug/features/DebugVectorFeatures.kt | 3 --- .../src/main/java/im/vector/app/features/VectorFeatures.kt | 2 -- 3 files changed, 10 deletions(-) diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt index 3fbe80fd98..8702c8d966 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt @@ -54,11 +54,6 @@ class DebugFeaturesStateFactory @Inject constructor( key = DebugFeatureKeys.onboardingPersonalize, factory = VectorFeatures::isOnboardingPersonalizeEnabled ), - createBooleanFeature( - label = "Force login fallback", - key = DebugFeatureKeys.forceLoginFallback, - factory = VectorFeatures::isForceLoginFallbackEnabled - ) )) } diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt index 85d3a501f6..f93e3d96fb 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt @@ -54,8 +54,6 @@ class DebugVectorFeatures( override fun isOnboardingPersonalizeEnabled(): Boolean = read(DebugFeatureKeys.onboardingPersonalize) ?: vectorFeatures.isOnboardingPersonalizeEnabled() - override fun isForceLoginFallbackEnabled(): Boolean = read(DebugFeatureKeys.forceLoginFallback) ?: vectorFeatures.isForceLoginFallbackEnabled() - fun override(value: T?, key: Preferences.Key) = updatePreferences { if (value == null) { it.remove(key) @@ -108,5 +106,4 @@ object DebugFeatureKeys { val onboardingSplashCarousel = booleanPreferencesKey("onboarding-splash-carousel") val onboardingUseCase = booleanPreferencesKey("onbboarding-splash-carousel") val onboardingPersonalize = booleanPreferencesKey("onbboarding-personalize") - val forceLoginFallback = booleanPreferencesKey("force-login-fallback") } diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index 7d8d14b3af..a19b3d9026 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -25,7 +25,6 @@ interface VectorFeatures { fun isOnboardingSplashCarouselEnabled(): Boolean fun isOnboardingUseCaseEnabled(): Boolean fun isOnboardingPersonalizeEnabled(): Boolean - fun isForceLoginFallbackEnabled(): Boolean enum class OnboardingVariant { LEGACY, @@ -40,5 +39,4 @@ class DefaultVectorFeatures : VectorFeatures { override fun isOnboardingSplashCarouselEnabled() = true override fun isOnboardingUseCaseEnabled() = true override fun isOnboardingPersonalizeEnabled() = false - override fun isForceLoginFallbackEnabled() = false } From 2917d4e4d680f590454c153dca5bb154c1a16c32 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:01:18 +0100 Subject: [PATCH 07/14] 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 + } + } } From 092761c1187407f9b66d9ad1e10b42de8e0507b9 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:07:10 +0100 Subject: [PATCH 08/14] Adds forceLoginFallback private setting view --- .../features/debug/settings/DebugPrivateSettingsFragment.kt | 3 +++ .../debug/res/layout/fragment_debug_private_settings.xml | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt index 808c379354..0738af728b 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt @@ -43,6 +43,9 @@ class DebugPrivateSettingsFragment : VectorBaseFragment viewModel.handle(DebugPrivateSettingsViewActions.SetDialPadVisibility(isChecked)) } + views.forceLoginFallback.setOnCheckedChangeListener { _, isChecked -> + viewModel.handle(DebugPrivateSettingsViewActions.SetForceLoginFallbackEnabled(isChecked)) + } } override fun invalidate() = withState(viewModel) { diff --git a/vector/src/debug/res/layout/fragment_debug_private_settings.xml b/vector/src/debug/res/layout/fragment_debug_private_settings.xml index b4186e7bba..6760c68169 100644 --- a/vector/src/debug/res/layout/fragment_debug_private_settings.xml +++ b/vector/src/debug/res/layout/fragment_debug_private_settings.xml @@ -25,6 +25,12 @@ android:layout_height="wrap_content" android:text="Force DialPad tab display" /> + + From 981393fefb5d9b4b78689eba2171000834455dc4 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:27:51 +0100 Subject: [PATCH 09/14] Changes copy value of forceLoginFallback to it --- .../features/debug/settings/DebugPrivateSettingsViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7b64349f47..038b1e6cc7 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 @@ -49,7 +49,7 @@ class DebugPrivateSettingsViewModel @AssistedInject constructor( } vectorDataStore.forceLoginFallbackFlow.setOnEach { - copy(forceLoginFallback = false) + copy(forceLoginFallback = it) } } From 92c6d599846734a10c2b011457952e4502b93f9a Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:28:33 +0100 Subject: [PATCH 10/14] 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 -> From 3d57d72a7eb97c98407d097d2022acaca9ca0c34 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:33:06 +0100 Subject: [PATCH 11/14] Reorders some functions within FtueAuthVariant --- .../onboarding/ftueauth/FtueAuthVariant.kt | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) 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 c5b65508b4..2083d936be 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 @@ -112,10 +112,6 @@ class FtueAuthVariant( } } - override fun setIsLoading(isLoading: Boolean) { - doNothing() - } - private fun addFirstFragment() { val splashFragment = when (vectorFeatures.isOnboardingSplashCarouselEnabled()) { true -> FtueAuthSplashCarouselFragment::class.java @@ -124,6 +120,23 @@ class FtueAuthVariant( activity.addFragment(views.loginFragmentContainer, splashFragment) } + private fun updateWithState(viewState: OnboardingViewState) { + isForceLoginFallbackEnabled = viewState.isForceLoginFallbackEnabled + views.loginLoading.isVisible = shouldShowLoading(viewState) + } + + private fun shouldShowLoading(viewState: OnboardingViewState) = + if (vectorFeatures.isOnboardingPersonalizeEnabled()) { + viewState.isLoading() + } else { + // Keep loading when during success because of the delay when switching to the next Activity + viewState.isLoading() || viewState.isAuthTaskCompleted() + } + + override fun setIsLoading(isLoading: Boolean) { + doNothing() + } + private fun handleOnboardingViewEvents(viewEvents: OnboardingViewEvents) { when (viewEvents) { is OnboardingViewEvents.RegistrationFlowResult -> { @@ -245,17 +258,6 @@ class FtueAuthVariant( .show() } - private fun updateWithState(viewState: OnboardingViewState) { - isForceLoginFallbackEnabled = viewState.isForceLoginFallbackEnabled - - views.loginLoading.isVisible = if (vectorFeatures.isOnboardingPersonalizeEnabled()) { - viewState.isLoading() - } else { - // Keep loading when during success because of the delay when switching to the next Activity - viewState.isLoading() || viewState.isAuthTaskCompleted() - } - } - private fun onWebLoginError(onWebLoginError: OnboardingViewEvents.OnWebLoginError) { // Pop the backstack supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) From 8d0410d961af3d58af3f268c818a051141b7d2c7 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:38:36 +0100 Subject: [PATCH 12/14] Removes Global doNothing function --- .../lib/core/utils/extensions/Global.kt | 20 ------------------- .../onboarding/ftueauth/FtueAuthVariant.kt | 7 ++----- 2 files changed, 2 insertions(+), 25 deletions(-) delete mode 100644 library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt diff --git a/library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt b/library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt deleted file mode 100644 index 3b508ab7b2..0000000000 --- a/library/core-utils/src/main/java/im/vector/lib/core/utils/extensions/Global.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.lib.core.utils.extensions - -@Suppress("UNUSED_PARAMETER") -fun doNothing(reason: String = "") = Unit 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 2083d936be..2b1ada0906 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 @@ -53,7 +53,6 @@ import im.vector.app.features.onboarding.OnboardingViewModel import im.vector.app.features.onboarding.OnboardingViewState import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragment import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragmentArgument -import im.vector.lib.core.utils.extensions.doNothing import org.matrix.android.sdk.api.auth.registration.FlowResult import org.matrix.android.sdk.api.auth.registration.Stage import org.matrix.android.sdk.api.extensions.tryOrNull @@ -133,9 +132,7 @@ class FtueAuthVariant( viewState.isLoading() || viewState.isAuthTaskCompleted() } - override fun setIsLoading(isLoading: Boolean) { - doNothing() - } + override fun setIsLoading(isLoading: Boolean) = Unit private fun handleOnboardingViewEvents(viewEvents: OnboardingViewEvents) { when (viewEvents) { @@ -285,7 +282,7 @@ class FtueAuthVariant( // state.signMode could not be ready yet. So use value from the ViewEvent when (OnboardingViewEvents.signMode) { SignMode.Unknown -> error("Sign mode has to be set before calling this method") - SignMode.SignUp -> doNothing("This is managed by the OnboardingViewEvents") + SignMode.SignUp -> Unit // This case is processed in handleOnboardingViewEvents SignMode.SignIn -> handleSignInSelected(state) SignMode.SignInWithMatrixId -> handleSignInWithMatrixId(state) }.exhaustive From 9f0cef7040fa86822e1a0c83c9d4d1f1f2fd958a Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 15:39:27 +0100 Subject: [PATCH 13/14] Removes unnecessary exhaustive on when statement --- .../vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2b1ada0906..0093cb20ea 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 @@ -302,7 +302,7 @@ class FtueAuthVariant( is LoginMode.SsoAndPassword, LoginMode.Password -> openAuthLoginFragmentWithTag(FRAGMENT_LOGIN_TAG) LoginMode.Unsupported -> onLoginModeNotSupported(state.loginModeSupportedTypes) - }.exhaustive + } private fun openAuthLoginFragmentWithTag(tag: String) { activity.addFragmentToBackstack(views.loginFragmentContainer, From 65242dfb4707ab23402090b10e24ab90e75a1289 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 24 Feb 2022 16:57:04 +0100 Subject: [PATCH 14/14] Adds missing invalidation step to forceLoginFallback checkbox --- .../app/features/debug/settings/DebugPrivateSettingsFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt index 0738af728b..b54d776901 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/settings/DebugPrivateSettingsFragment.kt @@ -50,5 +50,6 @@ class DebugPrivateSettingsFragment : VectorBaseFragment