From 11cc284bccbf1d370f4e5efdbffe96ea5246b210 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 8 Mar 2022 12:02:21 +0000 Subject: [PATCH] reusing showFailure from the base fragment instead of resubscribing to the view events --- .../ftueauth/FtueAuthLoginFragment.kt | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt index a5536b1dcd..60912f754e 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthLoginFragment.kt @@ -72,33 +72,6 @@ class FtueAuthLoginFragment @Inject constructor() : AbstractSSOFtueAuthFragment< override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - viewModel.viewEvents - .stream() - .onEach { - when (it) { - is OnboardingViewEvents.Failure -> { - if (it.throwable is Failure.ServerError && - it.throwable.error.code == MatrixError.M_FORBIDDEN && - it.throwable.error.message.isEmpty()) { - // Login with email, but email unknown - views.loginFieldTil.error = getString(R.string.login_login_with_email_error) - } else { - // Trick to display the error without text. - views.loginFieldTil.error = " " - if (it.throwable.isInvalidPassword() && spaceInPassword()) { - views.passwordFieldTil.error = getString(R.string.auth_invalid_login_param_space_in_password) - } else { - views.passwordFieldTil.error = errorFormatter.toHumanReadable(it.throwable) - } - } - } - else -> { - // do nothing - } - } - } - .launchIn(lifecycleScope) - setupSubmitButton() setupForgottenPasswordButton() @@ -305,6 +278,23 @@ class FtueAuthLoginFragment @Inject constructor() : AbstractSSOFtueAuthFragment< } } + override fun showFailure(throwable: Throwable) { + if (throwable is Failure.ServerError && + throwable.error.code == MatrixError.M_FORBIDDEN && + throwable.error.message.isEmpty()) { + // Login with email, but email unknown + views.loginFieldTil.error = getString(R.string.login_login_with_email_error) + } else { + // Trick to display the error without text. + views.loginFieldTil.error = " " + if (throwable.isInvalidPassword() && spaceInPassword()) { + views.passwordFieldTil.error = getString(R.string.auth_invalid_login_param_space_in_password) + } else { + views.passwordFieldTil.error = errorFormatter.toHumanReadable(throwable) + } + } + } + /** * Detect if password ends or starts with spaces */