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 e60bedc612..987d3f38a2 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 @@ -701,9 +701,8 @@ class OnboardingViewModel @AssistedInject constructor( private fun onAuthenticationStartError(error: Throwable, trigger: OnboardingAction.HomeServerChange) { when { - error.isHomeserverUnavailable() && applicationContext.inferNoConnectivity(sdkIntProvider) -> _viewEvents.post( - OnboardingViewEvents.Failure(error) - ) + error.isHomeserverUnavailable() && applicationContext.inferNoConnectivity(sdkIntProvider) -> _viewEvents.post(OnboardingViewEvents.Failure(error)) + isUnableToSelectServer(error, trigger) -> handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.EditServerSelection)) deeplinkUrlIsUnavailable(error, trigger) -> _viewEvents.post( OnboardingViewEvents.DeeplinkAuthenticationFailure( retryAction = (trigger as OnboardingAction.HomeServerChange.SelectHomeServer).resetToDefaultUrl() @@ -716,6 +715,9 @@ class OnboardingViewModel @AssistedInject constructor( } } + private fun isUnableToSelectServer(error: Throwable, trigger: OnboardingAction.HomeServerChange) = + trigger is OnboardingAction.HomeServerChange.SelectHomeServer && error.isHomeserverUnavailable() + private fun deeplinkUrlIsUnavailable(error: Throwable, trigger: OnboardingAction.HomeServerChange) = error.isHomeserverUnavailable() && loginConfig != null && trigger is OnboardingAction.HomeServerChange.SelectHomeServer @@ -807,6 +809,8 @@ class OnboardingViewModel @AssistedInject constructor( return loginConfig?.homeServerUrl } + fun getDefaultHomeserverUrl() = defaultHomeserverUrl + fun fetchSsoUrl(redirectUrl: String, deviceId: String?, provider: SsoIdentityProvider?): String? { setState { val authDescription = AuthenticationDescription.Register(provider.toAuthenticationType()) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt index 749aac2898..2563c1d777 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthCombinedServerSelectionFragment.kt @@ -86,7 +86,7 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt ) if (views.chooseServerInput.content().isEmpty()) { - val userUrlInput = state.selectedHomeserver.userFacingUrl?.toReducedUrlKeepingSchemaIfInsecure() + val userUrlInput = state.selectedHomeserver.userFacingUrl?.toReducedUrlKeepingSchemaIfInsecure() ?: viewModel.getDefaultHomeserverUrl() views.chooseServerInput.editText().setText(userUrlInput) } } 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 601d577e02..96a3ed3f65 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 @@ -46,6 +46,7 @@ import im.vector.app.features.login.SignMode import im.vector.app.features.login.TextInputFormFragmentMode import im.vector.app.features.onboarding.OnboardingAction import im.vector.app.features.onboarding.OnboardingActivity +import im.vector.app.features.onboarding.OnboardingFlow import im.vector.app.features.onboarding.OnboardingVariant import im.vector.app.features.onboarding.OnboardingViewEvents import im.vector.app.features.onboarding.OnboardingViewModel @@ -213,7 +214,7 @@ class FtueAuthVariant( option = commonOption ) } - OnboardingViewEvents.OpenCombinedRegister -> openStartCombinedRegister() + OnboardingViewEvents.OpenCombinedRegister -> onStartCombinedRegister() is OnboardingViewEvents.OnAccountCreated -> onAccountCreated() OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn() OnboardingViewEvents.OnChooseDisplayName -> onChooseDisplayName() @@ -229,21 +230,43 @@ class FtueAuthVariant( tag = FRAGMENT_EDIT_HOMESERVER_TAG ) } - OnboardingViewEvents.OnHomeserverEdited -> supportFragmentManager.popBackStack( - FRAGMENT_EDIT_HOMESERVER_TAG, - FragmentManager.POP_BACK_STACK_INCLUSIVE - ) + OnboardingViewEvents.OnHomeserverEdited -> { + supportFragmentManager.popBackStack( + FRAGMENT_EDIT_HOMESERVER_TAG, + FragmentManager.POP_BACK_STACK_INCLUSIVE + ) + ensureEditServerBackstack() + } OnboardingViewEvents.OpenCombinedLogin -> onStartCombinedLogin() is OnboardingViewEvents.DeeplinkAuthenticationFailure -> onDeeplinkedHomeserverUnavailable(viewEvents) OnboardingViewEvents.DisplayRegistrationFallback -> displayFallbackWebDialog() is OnboardingViewEvents.DisplayRegistrationStage -> doStage(viewEvents.stage) OnboardingViewEvents.DisplayStartRegistration -> when { - vectorFeatures.isOnboardingCombinedRegisterEnabled() -> openStartCombinedRegister() + vectorFeatures.isOnboardingCombinedRegisterEnabled() -> onStartCombinedRegister() else -> openAuthLoginFragmentWithTag(FRAGMENT_REGISTRATION_STAGE_TAG) } } } + private fun ensureEditServerBackstack() { + when (activity.supportFragmentManager.findFragmentById(views.loginFragmentContainer.id)) { + is FtueAuthCombinedLoginFragment, + is FtueAuthCombinedRegisterFragment -> { + // do nothing + } + else -> { + withState(onboardingViewModel) { state -> + when (state.onboardingFlow) { + OnboardingFlow.SignIn -> onStartCombinedLogin() + OnboardingFlow.SignUp -> onStartCombinedRegister() + OnboardingFlow.SignInSignUp, + null -> error("${state.onboardingFlow} does not support editing server url") + } + } + } + } + } + private fun onDeeplinkedHomeserverUnavailable(viewEvents: OnboardingViewEvents.DeeplinkAuthenticationFailure) { showHomeserverUnavailableDialog(onboardingViewModel.getInitialHomeServerUrl().orEmpty()) { onboardingViewModel.handle(OnboardingAction.ResetDeeplinkConfig) @@ -264,7 +287,7 @@ class FtueAuthVariant( addRegistrationStageFragmentToBackstack(FtueAuthCombinedLoginFragment::class.java, allowStateLoss = true) } - private fun openStartCombinedRegister() { + private fun onStartCombinedRegister() { addRegistrationStageFragmentToBackstack(FtueAuthCombinedRegisterFragment::class.java, allowStateLoss = true) }