Login screens: cleanup the Fragment stack after completing stage

This commit is contained in:
Benoit Marty 2019-11-19 18:09:05 +01:00
parent 6d8e5b892e
commit 3758334824
1 changed files with 16 additions and 8 deletions

View File

@ -222,26 +222,34 @@ class LoginActivity : VectorBaseActivity() {
} }
} }
// TODO Unstack fragment when stage is complete
private fun doStage(stage: Stage) { private fun doStage(stage: Stage) {
// Ensure there is no fragment for registration stage in the backstack
supportFragmentManager.popBackStack(FRAGMENT_REGISTRATION_STAGE_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE)
when (stage) { when (stage) {
is Stage.ReCaptcha -> addFragmentToBackstack(R.id.loginFragmentContainer, is Stage.ReCaptcha -> addFragmentToBackstack(R.id.loginFragmentContainer,
LoginCaptchaFragment::class.java, LoginCaptchaFragmentArgument(stage.publicKey)) LoginCaptchaFragment::class.java,
LoginCaptchaFragmentArgument(stage.publicKey),
tag = FRAGMENT_REGISTRATION_STAGE_TAG)
is Stage.Email -> addFragmentToBackstack(R.id.loginFragmentContainer, is Stage.Email -> addFragmentToBackstack(R.id.loginFragmentContainer,
LoginGenericTextInputFormFragment::class.java, LoginGenericTextInputFormFragment::class.java,
LoginGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.SetEmail, stage.mandatory)) LoginGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.SetEmail, stage.mandatory),
is Stage.Msisdn tag = FRAGMENT_REGISTRATION_STAGE_TAG)
-> addFragmentToBackstack(R.id.loginFragmentContainer, is Stage.Msisdn -> addFragmentToBackstack(R.id.loginFragmentContainer,
LoginGenericTextInputFormFragment::class.java, LoginGenericTextInputFormFragment::class.java,
LoginGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.SetMsisdn, stage.mandatory)) LoginGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.SetMsisdn, stage.mandatory),
tag = FRAGMENT_REGISTRATION_STAGE_TAG)
is Stage.Terms -> addFragmentToBackstack(R.id.loginFragmentContainer, is Stage.Terms -> addFragmentToBackstack(R.id.loginFragmentContainer,
LoginTermsFragment::class.java, LoginTermsFragment::class.java,
LoginTermsFragmentArgument(stage.policies.toLocalizedLoginTerms(getString(R.string.resources_language)))) LoginTermsFragmentArgument(stage.policies.toLocalizedLoginTerms(getString(R.string.resources_language))),
else -> TODO() tag = FRAGMENT_REGISTRATION_STAGE_TAG)
else -> Unit // Should not happen
} }
} }
companion object { companion object {
private const val FRAGMENT_REGISTRATION_STAGE_TAG = "FRAGMENT_REGISTRATION_STAGE_TAG"
private const val EXTRA_CONFIG = "EXTRA_CONFIG" private const val EXTRA_CONFIG = "EXTRA_CONFIG"
fun newIntent(context: Context, loginConfig: LoginConfig?): Intent { fun newIntent(context: Context, loginConfig: LoginConfig?): Intent {