Cleanup up this screen

This commit is contained in:
Benoit Marty 2021-05-31 17:13:29 +02:00
parent 9724c1b8ce
commit acd5b656d2
5 changed files with 13 additions and 9 deletions

View file

@ -113,13 +113,14 @@ class SoftLogoutController @Inject constructor(
loginPasswordFormItem {
id("passwordForm")
stringProvider(host.stringProvider)
passwordValue(state.enteredPassword)
passwordShown(state.passwordShown)
submitEnabled(state.submitEnabled)
submitEnabled(state.enteredPassword.isNotEmpty())
onPasswordEdited { host.listener?.passwordEdited(it) }
errorText((state.asyncLoginAction as? Fail)?.error?.let { host.errorFormatter.toHumanReadable(it) })
passwordRevealClickListener { host.listener?.revealPasswordClicked() }
forgetPasswordClickListener { host.listener?.forgetPasswordClicked() }
submitClickListener { password -> host.listener?.signinSubmit(password) }
submitClickListener { host.listener?.submit() }
}
}
is LoginMode.Sso -> {
@ -164,7 +165,7 @@ class SoftLogoutController @Inject constructor(
interface Listener {
fun retry()
fun passwordEdited(password: String)
fun signinSubmit(password: String)
fun submit()
fun signinFallbackSubmit()
fun clearData()
fun forgetPasswordClicked()

View file

@ -107,9 +107,9 @@ class SoftLogoutFragment @Inject constructor(
softLogoutViewModel.handle(SoftLogoutAction.PasswordChanged(password))
}
override fun signinSubmit(password: String) {
override fun submit() = withState(softLogoutViewModel) { state ->
cleanupUi()
softLogoutViewModel.handle(SoftLogoutAction.SignInAgain(password))
softLogoutViewModel.handle(SoftLogoutAction.SignInAgain(state.enteredPassword))
}
override fun signinFallbackSubmit() = withState(loginViewModel) { state ->

View file

@ -138,7 +138,7 @@ class SoftLogoutViewModel @AssistedInject constructor(
setState {
copy(
asyncLoginAction = Uninitialized,
submitEnabled = action.password.isNotBlank()
enteredPassword = action.password
)
}
}

View file

@ -32,7 +32,7 @@ data class SoftLogoutViewState(
val userDisplayName: String,
val hasUnsavedKeys: Boolean,
val passwordShown: Boolean = false,
val submitEnabled: Boolean = false
val enteredPassword: String = ""
) : MvRxState {
fun isLoading(): Boolean {

View file

@ -31,6 +31,7 @@ import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.addTextChangedListenerOnce
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.epoxy.setValueOnce
import im.vector.app.core.extensions.showPassword
import im.vector.app.core.platform.SimpleTextWatcher
import im.vector.app.core.resources.StringProvider
@ -39,13 +40,14 @@ import im.vector.app.core.ui.views.RevealPasswordImageView
@EpoxyModelClass(layout = R.layout.item_login_password_form)
abstract class LoginPasswordFormItem : VectorEpoxyModel<LoginPasswordFormItem.Holder>() {
@EpoxyAttribute var passwordValue: String = ""
@EpoxyAttribute var passwordShown: Boolean = false
@EpoxyAttribute var submitEnabled: Boolean = false
@EpoxyAttribute var errorText: String? = null
@EpoxyAttribute lateinit var stringProvider: StringProvider
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var passwordRevealClickListener: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var forgetPasswordClickListener: ClickListener? = null
@EpoxyAttribute var submitClickListener: ((String) -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var submitClickListener: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onPasswordEdited: TextListener? = null
private val textChangeListener = object : SimpleTextWatcher() {
@ -63,7 +65,8 @@ abstract class LoginPasswordFormItem : VectorEpoxyModel<LoginPasswordFormItem.Ho
holder.passwordReveal.onClick(passwordRevealClickListener)
holder.forgetPassword.onClick(forgetPasswordClickListener)
holder.submit.isEnabled = submitEnabled
holder.submit.setOnClickListener { submitClickListener?.invoke(holder.passwordField.text.toString()) }
holder.submit.onClick(submitClickListener)
holder.setValueOnce(holder.passwordField, passwordValue)
holder.passwordField.addTextChangedListenerOnce(textChangeListener)
}