Skip to content

Commit 1a76b4d

Browse files
committed
ordering the ftue onboarding steps to match the design flow
- only applied when the combined register flag is enabled
1 parent 5b01290 commit 1a76b4d

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ class FtueAuthVariant(
239239

240240
private fun onRegistrationFlow(viewEvents: OnboardingViewEvents.RegistrationFlowResult) {
241241
when {
242-
registrationShouldFallback(viewEvents) -> displayFallbackWebDialog()
243-
viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult)
242+
registrationShouldFallback(viewEvents) -> displayFallbackWebDialog()
243+
viewEvents.isRegistrationStarted -> handleRegistrationNavigation(viewEvents.flowResult.orderedStages())
244244
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> openStartCombinedRegister()
245-
else -> {
245+
else -> {
246246
// First ask for login and password
247247
// I add a tag to indicate that this fragment is a registration stage.
248248
// This way it will be automatically popped in when starting the next registration stage
@@ -251,6 +251,20 @@ class FtueAuthVariant(
251251
}
252252
}
253253

254+
private fun FlowResult.orderedStages() = when {
255+
vectorFeatures.isOnboardingCombinedRegisterEnabled() -> missingStages.sortedBy {
256+
when (it) {
257+
is Stage.Email -> 0
258+
is Stage.Msisdn -> 1
259+
is Stage.Terms -> 2
260+
is Stage.ReCaptcha -> 3
261+
is Stage.Other -> 4
262+
is Stage.Dummy -> 5
263+
}
264+
}
265+
else -> missingStages
266+
}
267+
254268
private fun openStartCombinedRegister() {
255269
addRegistrationStageFragmentToBackstack(FtueAuthCombinedRegisterFragment::class.java)
256270
}
@@ -370,15 +384,15 @@ class FtueAuthVariant(
370384
?.let { onboardingViewModel.handle(OnboardingAction.LoginWithToken(it)) }
371385
}
372386

373-
private fun handleRegistrationNavigation(flowResult: FlowResult) {
387+
private fun handleRegistrationNavigation(remainingStages: List<Stage>) {
374388
// Complete all mandatory stages first
375-
val mandatoryStage = flowResult.missingStages.firstOrNull { it.mandatory }
389+
val mandatoryStage = remainingStages.firstOrNull { it.mandatory }
376390

377391
if (mandatoryStage != null) {
378392
doStage(mandatoryStage)
379393
} else {
380394
// Consider optional stages
381-
val optionalStage = flowResult.missingStages.firstOrNull { !it.mandatory && it !is Stage.Dummy }
395+
val optionalStage = remainingStages.firstOrNull { !it.mandatory && it !is Stage.Dummy }
382396
if (optionalStage == null) {
383397
// Should not happen...
384398
} else {

0 commit comments

Comments
 (0)