ordering the ftue onboarding steps to match the design flow

- only applied when the combined register flag is enabled
This commit is contained in:
Adam Brown 2022-04-19 11:56:13 +01:00
parent 5b01290057
commit 1a76b4d680
1 changed files with 20 additions and 6 deletions

View File

@ -239,10 +239,10 @@ class FtueAuthVariant(
private fun onRegistrationFlow(viewEvents: OnboardingViewEvents.RegistrationFlowResult) {
when {
registrationShouldFallback(viewEvents) -> displayFallbackWebDialog()
viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult)
registrationShouldFallback(viewEvents) -> displayFallbackWebDialog()
viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult.orderedStages())
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> openStartCombinedRegister()
else -> {
else -> {
// 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
@ -251,6 +251,20 @@ class FtueAuthVariant(
}
}
private fun FlowResult.orderedStages() = when {
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> missingStages.sortedBy {
when (it) {
is Stage.Email -> 0
is Stage.Msisdn -> 1
is Stage.Terms -> 2
is Stage.ReCaptcha -> 3
is Stage.Other -> 4
is Stage.Dummy -> 5
}
}
else -> missingStages
}
private fun openStartCombinedRegister() {
addRegistrationStageFragmentToBackstack(FtueAuthCombinedRegisterFragment::class.java)
}
@ -370,15 +384,15 @@ class FtueAuthVariant(
?.let { onboardingViewModel.handle(OnboardingAction.LoginWithToken(it)) }
}
private fun handleRegistrationNavigation(flowResult: FlowResult) {
private fun handleRegistrationNavigation(remainingStages: List<Stage>) {
// Complete all mandatory stages first
val mandatoryStage = flowResult.missingStages.firstOrNull { it.mandatory }
val mandatoryStage = remainingStages.firstOrNull { it.mandatory }
if (mandatoryStage != null) {
doStage(mandatoryStage)
} else {
// Consider optional stages
val optionalStage = flowResult.missingStages.firstOrNull { !it.mandatory && it !is Stage.Dummy }
val optionalStage = remainingStages.firstOrNull { !it.mandatory && it !is Stage.Dummy }
if (optionalStage == null) {
// Should not happen...
} else {