From 9b12f295d198d0999175c35b4557dbe45da0db1c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 1 Feb 2022 15:10:01 +0000 Subject: [PATCH 001/229] adding ftue personalize feature flag whilst under development --- .../app/features/debug/features/DebugFeaturesStateFactory.kt | 5 +++++ .../app/features/debug/features/DebugVectorFeatures.kt | 4 ++++ .../src/main/java/im/vector/app/features/VectorFeatures.kt | 2 ++ 3 files changed, 11 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..5cc4bd3bde 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 = "FTUE Personalize profile", + key = DebugFeatureKeys.onboardingPersonalize, + factory = VectorFeatures::isOnboardingPersonalizeEnabled ) )) } 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..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 @@ -51,6 +51,9 @@ class DebugVectorFeatures( override fun isOnboardingUseCaseEnabled(): Boolean = read(DebugFeatureKeys.onboardingUseCase) ?: vectorFeatures.isOnboardingUseCaseEnabled() + override fun isOnboardingPersonalizeEnabled(): Boolean = read(DebugFeatureKeys.onboardingPersonalize) + ?: vectorFeatures.isOnboardingPersonalizeEnabled() + fun override(value: T?, key: Preferences.Key) = updatePreferences { if (value == null) { it.remove(key) @@ -102,4 +105,5 @@ object DebugFeatureKeys { val onboardingAlreadyHaveAnAccount = booleanPreferencesKey("onboarding-already-have-an-account") val onboardingSplashCarousel = booleanPreferencesKey("onboarding-splash-carousel") val onboardingUseCase = booleanPreferencesKey("onbboarding-splash-carousel") + val onboardingPersonalize = booleanPreferencesKey("onbboarding-personalize") } 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..a19b3d9026 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 isOnboardingPersonalizeEnabled(): 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 isOnboardingPersonalizeEnabled() = false } From 8212b7e21910480b2f51aa5ed6a5a9a7154b029a Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 1 Feb 2022 17:20:02 +0000 Subject: [PATCH 002/229] completing the onboarding via dedicated event rather than observing state - allows for greater control of the flow (such as adding new screens inbetween the creation and exit with flags) --- .../onboarding/OnboardingViewEvents.kt | 2 ++ .../onboarding/OnboardingViewModel.kt | 30 +++++++++++-------- .../onboarding/ftueauth/FtueAuthVariant.kt | 26 +++++++++------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt index d6105cda13..463c26578d 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt @@ -48,4 +48,6 @@ sealed class OnboardingViewEvents : VectorViewEvents { data class OnSendMsisdnSuccess(val msisdn: String) : OnboardingViewEvents() data class OnWebLoginError(val errorCode: Int, val description: String, val failingUrl: String) : OnboardingViewEvents() + object OnAccountCreated: OnboardingViewEvents() + object OnAccountSignedIn: OnboardingViewEvents() } 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 8097e90206..f62d5e92b4 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 @@ -244,7 +244,7 @@ class OnboardingViewModel @AssistedInject constructor( } null } - ?.let { onSessionCreated(it) } + ?.let { onSessionCreated(it, isAccountCreated = false) } } } } @@ -314,7 +314,7 @@ class OnboardingViewModel @AssistedInject constructor( } ?.let { data -> when (data) { - is RegistrationResult.Success -> onSessionCreated(data.session) + is RegistrationResult.Success -> onSessionCreated(data.session, isAccountCreated = true) is RegistrationResult.FlowResponse -> onFlowResponse(data.flowResult) } } @@ -615,11 +615,11 @@ class OnboardingViewModel @AssistedInject constructor( } when (data) { is WellknownResult.Prompt -> - onWellknownSuccess(action, data, homeServerConnectionConfig) + directLoginOnWellknownSuccess(action, data, homeServerConnectionConfig) is WellknownResult.FailPrompt -> // Relax on IS discovery if homeserver is valid if (data.homeServerUrl != null && data.wellKnown != null) { - onWellknownSuccess(action, WellknownResult.Prompt(data.homeServerUrl!!, null, data.wellKnown!!), homeServerConnectionConfig) + directLoginOnWellknownSuccess(action, WellknownResult.Prompt(data.homeServerUrl!!, null, data.wellKnown!!), homeServerConnectionConfig) } else { onWellKnownError() } @@ -639,9 +639,9 @@ class OnboardingViewModel @AssistedInject constructor( _viewEvents.post(OnboardingViewEvents.Failure(Exception(stringProvider.getString(R.string.autodiscover_well_known_error)))) } - private suspend fun onWellknownSuccess(action: OnboardingAction.LoginOrRegister, - wellKnownPrompt: WellknownResult.Prompt, - homeServerConnectionConfig: HomeServerConnectionConfig?) { + private suspend fun directLoginOnWellknownSuccess(action: OnboardingAction.LoginOrRegister, + wellKnownPrompt: WellknownResult.Prompt, + homeServerConnectionConfig: HomeServerConnectionConfig?) { val alteredHomeServerConnectionConfig = homeServerConnectionConfig ?.copy( homeServerUriBase = Uri.parse(wellKnownPrompt.homeServerUrl), @@ -663,7 +663,7 @@ class OnboardingViewModel @AssistedInject constructor( onDirectLoginError(failure) return } - onSessionCreated(data) + onSessionCreated(data, isAccountCreated = true) } private fun onDirectLoginError(failure: Throwable) { @@ -721,7 +721,7 @@ class OnboardingViewModel @AssistedInject constructor( } ?.let { reAuthHelper.data = action.password - onSessionCreated(it) + onSessionCreated(it, isAccountCreated = false) } } } @@ -751,8 +751,9 @@ class OnboardingViewModel @AssistedInject constructor( } } - private suspend fun onSessionCreated(session: Session) { - awaitState().useCase?.let { useCase -> + private suspend fun onSessionCreated(session: Session, isAccountCreated: Boolean) { + val state = awaitState() + state.useCase?.let { useCase -> session.vectorStore(applicationContext).setUseCase(useCase) } activeSessionHolder.setActiveSession(session) @@ -764,6 +765,11 @@ class OnboardingViewModel @AssistedInject constructor( asyncLoginAction = Success(Unit) ) } + + when (isAccountCreated) { + true -> _viewEvents.post(OnboardingViewEvents.OnAccountCreated) + false -> _viewEvents.post(OnboardingViewEvents.OnAccountSignedIn) + } } private fun handleWebLoginSuccess(action: OnboardingAction.WebLoginSuccess) = withState { state -> @@ -782,7 +788,7 @@ class OnboardingViewModel @AssistedInject constructor( } null } - ?.let { onSessionCreated(it) } + ?.let { onSessionCreated(it, isAccountCreated = false) } } } } 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..3b3a4d632b 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 @@ -220,20 +220,12 @@ class FtueAuthVariant( FtueAuthUseCaseFragment::class.java, option = commonOption) } + OnboardingViewEvents.OnAccountCreated -> onAccountCreated() + OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn() }.exhaustive } private fun updateWithState(viewState: OnboardingViewState) { - if (viewState.isUserLogged()) { - val intent = HomeActivity.newIntent( - activity, - accountCreation = viewState.signMode == SignMode.SignUp - ) - activity.startActivity(intent) - activity.finish() - return - } - // Loading views.loginLoading.isVisible = viewState.isLoading() } @@ -368,4 +360,18 @@ class FtueAuthVariant( else -> Unit // Should not happen } } + + private fun onAccountSignedIn() { + navigateToHome(createdAccount = false) + } + + private fun onAccountCreated() { + navigateToHome(createdAccount = true) + } + + private fun navigateToHome(createdAccount: Boolean) { + val intent = HomeActivity.newIntent(activity, accountCreation = createdAccount) + activity.startActivity(intent) + activity.finish() + } } From 023b32367bd420835ac97c142af6d1f234e5d996 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Feb 2022 11:54:32 +0000 Subject: [PATCH 003/229] adding post account created screen, going to the personalise next steps are still TODO --- .../im/vector/app/core/di/FragmentModule.kt | 6 + .../features/onboarding/OnboardingAction.kt | 3 + .../onboarding/OnboardingViewEvents.kt | 2 + .../onboarding/OnboardingViewModel.kt | 2 + .../onboarding/OnboardingViewState.kt | 4 +- .../FtueAuthAccountCreatedFragment.kt | 51 +++++++ .../onboarding/ftueauth/FtueAuthVariant.kt | 13 +- .../layout/fragment_ftue_account_created.xml | 127 ++++++++++++++++++ vector/src/main/res/values/donottranslate.xml | 6 + 9 files changed, 210 insertions(+), 4 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthAccountCreatedFragment.kt create mode 100644 vector/src/main/res/layout/fragment_ftue_account_created.xml diff --git a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt index e7aa83ae75..5eb735d22e 100644 --- a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt @@ -97,6 +97,7 @@ import im.vector.app.features.login2.created.AccountCreatedFragment import im.vector.app.features.login2.terms.LoginTermsFragment2 import im.vector.app.features.matrixto.MatrixToRoomSpaceFragment import im.vector.app.features.matrixto.MatrixToUserFragment +import im.vector.app.features.onboarding.ftueauth.FtueAuthAccountCreatedFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthCaptchaFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthGenericTextInputFormFragment import im.vector.app.features.onboarding.ftueauth.FtueAuthLoginFragment @@ -473,6 +474,11 @@ interface FragmentModule { @FragmentKey(FtueAuthTermsFragment::class) fun bindFtueAuthTermsFragment(fragment: FtueAuthTermsFragment): Fragment + @Binds + @IntoMap + @FragmentKey(FtueAuthAccountCreatedFragment::class) + fun bindFtueAuthAccountCreatedFragment(fragment: FtueAuthAccountCreatedFragment): Fragment + @Binds @IntoMap @FragmentKey(UserListFragment::class) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingAction.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingAction.kt index 2ca6a1f2fd..25f681f039 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingAction.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingAction.kt @@ -79,4 +79,7 @@ sealed class OnboardingAction : VectorViewModelAction { data class PostViewEvent(val viewEvent: OnboardingViewEvents) : OnboardingAction() data class UserAcceptCertificate(val fingerprint: Fingerprint) : OnboardingAction() + + object TakeMeHome: OnboardingAction() + object PersonalizeProfile: OnboardingAction() } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt index 463c26578d..a531d21fa6 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewEvents.kt @@ -50,4 +50,6 @@ sealed class OnboardingViewEvents : VectorViewEvents { data class OnWebLoginError(val errorCode: Int, val description: String, val failingUrl: String) : OnboardingViewEvents() object OnAccountCreated: OnboardingViewEvents() object OnAccountSignedIn: OnboardingViewEvents() + object OnTakeMeHome: OnboardingViewEvents() + object OnPersonalizeProfile: OnboardingViewEvents() } 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 f62d5e92b4..a342edbbb4 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 @@ -147,6 +147,8 @@ class OnboardingViewModel @AssistedInject constructor( is OnboardingAction.UserAcceptCertificate -> handleUserAcceptCertificate(action) OnboardingAction.ClearHomeServerHistory -> handleClearHomeServerHistory() is OnboardingAction.PostViewEvent -> _viewEvents.post(action.viewEvent) + OnboardingAction.PersonalizeProfile -> _viewEvents.post(OnboardingViewEvents.OnPersonalizeProfile) + OnboardingAction.TakeMeHome -> _viewEvents.post(OnboardingViewEvents.OnTakeMeHome) }.exhaustive } 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 d05a8294f6..2035977af6 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 @@ -70,9 +70,7 @@ data class OnboardingViewState( asyncHomeServerLoginFlowRequest is Loading || asyncResetPassword is Loading || asyncResetMailConfirmed is Loading || - asyncRegistration is Loading || - // Keep loading when it is success because of the delay to switch to the next Activity - asyncLoginAction is Success + asyncRegistration is Loading } fun isUserLogged(): Boolean { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthAccountCreatedFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthAccountCreatedFragment.kt new file mode 100644 index 0000000000..ff41c648c1 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthAccountCreatedFragment.kt @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 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.app.features.onboarding.ftueauth + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import im.vector.app.R +import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.databinding.FragmentFtueAccountCreatedBinding +import im.vector.app.features.onboarding.OnboardingAction +import javax.inject.Inject + +class FtueAuthAccountCreatedFragment @Inject constructor( + private val activeSessionHolder: ActiveSessionHolder +) : AbstractFtueAuthFragment() { + + override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueAccountCreatedBinding { + return FragmentFtueAccountCreatedBinding.inflate(inflater, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupViews() + } + + private fun setupViews() { + views.accountCreatedSubtitle.text = getString(R.string.ftue_account_created_subtitle, activeSessionHolder.getActiveSession().myUserId) + views.accountCreatedPersonalize.setOnClickListener { viewModel.handle(OnboardingAction.PersonalizeProfile) } + views.accountCreatedTakeMeHome.setOnClickListener { viewModel.handle(OnboardingAction.TakeMeHome) } + } + + override fun resetViewModel() { + // Nothing to do + } +} 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 3b3a4d632b..ef6da462e5 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 @@ -222,6 +222,9 @@ class FtueAuthVariant( } OnboardingViewEvents.OnAccountCreated -> onAccountCreated() OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn() + OnboardingViewEvents.OnPersonalizeProfile -> TODO() + OnboardingViewEvents.OnTakeMeHome -> navigateToHome(createdAccount = true) + }.exhaustive } @@ -366,7 +369,15 @@ class FtueAuthVariant( } private fun onAccountCreated() { - navigateToHome(createdAccount = true) + if (vectorFeatures.isOnboardingPersonalizeEnabled()) { + activity.addFragmentToBackstack( + views.loginFragmentContainer, + FtueAuthAccountCreatedFragment::class.java, + option = commonOption + ) + } else { + navigateToHome(createdAccount = true) + } } private fun navigateToHome(createdAccount: Boolean) { diff --git a/vector/src/main/res/layout/fragment_ftue_account_created.xml b/vector/src/main/res/layout/fragment_ftue_account_created.xml new file mode 100644 index 0000000000..1985af1d5e --- /dev/null +++ b/vector/src/main/res/layout/fragment_ftue_account_created.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + +