reusing showFailure from the base fragment instead of resubscribing to the view events

This commit is contained in:
Adam Brown 2022-03-08 12:02:21 +00:00
parent 7d80cfed0b
commit 11cc284bcc

View file

@ -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
*/