mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
SoftLogout: epoxy: missing elements
This commit is contained in:
parent
907fa35547
commit
e609f4a57e
6 changed files with 40 additions and 4 deletions
|
@ -20,6 +20,7 @@ import im.vector.riotx.core.platform.VectorViewModelAction
|
|||
|
||||
sealed class SoftLogoutAction : VectorViewModelAction {
|
||||
object RetryLoginFlow : SoftLogoutAction()
|
||||
data class PasswordChanged(val password: String) : SoftLogoutAction()
|
||||
object TogglePassword : SoftLogoutAction()
|
||||
|
||||
data class SignInAgain(val password: String) : SoftLogoutAction()
|
||||
|
|
|
@ -104,6 +104,8 @@ class SoftLogoutController @Inject constructor(
|
|||
id("passwordForm")
|
||||
stringProvider(stringProvider)
|
||||
passwordShown(state.passwordShown)
|
||||
submitEnabled(state.submitEnabled)
|
||||
onPasswordEdited { listener?.passwordEdited(it) }
|
||||
errorText((state.asyncLoginAction as? Fail)?.error?.let { errorFormatter.toHumanReadable(it) })
|
||||
passwordRevealClickListener { listener?.revealPasswordClicked() }
|
||||
forgetPasswordClickListener { listener?.forgetPasswordClicked() }
|
||||
|
@ -141,6 +143,7 @@ class SoftLogoutController @Inject constructor(
|
|||
|
||||
interface Listener {
|
||||
fun retry()
|
||||
fun passwordEdited(password: String)
|
||||
fun submit(password: String)
|
||||
fun ssoSubmit()
|
||||
fun clearData()
|
||||
|
|
|
@ -72,6 +72,10 @@ class SoftLogoutFragment @Inject constructor(
|
|||
softLogoutViewModel.handle(SoftLogoutAction.RetryLoginFlow)
|
||||
}
|
||||
|
||||
override fun passwordEdited(password: String) {
|
||||
softLogoutViewModel.handle(SoftLogoutAction.PasswordChanged(password))
|
||||
}
|
||||
|
||||
override fun submit(password: String) {
|
||||
cleanupUi()
|
||||
softLogoutViewModel.handle(SoftLogoutAction.SignInAgain(password))
|
||||
|
|
|
@ -143,9 +143,19 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
|
||||
override fun handle(action: SoftLogoutAction) {
|
||||
when (action) {
|
||||
is SoftLogoutAction.RetryLoginFlow -> getSupportedLoginFlow()
|
||||
is SoftLogoutAction.SignInAgain -> handleSignInAgain(action)
|
||||
is SoftLogoutAction.TogglePassword -> handleTogglePassword()
|
||||
is SoftLogoutAction.RetryLoginFlow -> getSupportedLoginFlow()
|
||||
is SoftLogoutAction.SignInAgain -> handleSignInAgain(action)
|
||||
is SoftLogoutAction.PasswordChanged -> handlePasswordChange(action)
|
||||
is SoftLogoutAction.TogglePassword -> handleTogglePassword()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlePasswordChange(action: SoftLogoutAction.PasswordChanged) {
|
||||
setState {
|
||||
copy(
|
||||
asyncLoginAction = Uninitialized,
|
||||
submitEnabled = action.password.isNotBlank()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ data class SoftLogoutViewState(
|
|||
val userId: String,
|
||||
val userDisplayName: String,
|
||||
val hasUnsavedKeys: Boolean,
|
||||
val passwordShown: Boolean = false
|
||||
val passwordShown: Boolean = false,
|
||||
val submitEnabled: Boolean = false
|
||||
) : MvRxState {
|
||||
|
||||
fun isLoading(): Boolean {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package im.vector.riotx.features.signout.epoxy
|
||||
|
||||
import android.os.Build
|
||||
import android.text.Editable
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import androidx.autofill.HintConstants
|
||||
|
@ -28,17 +29,26 @@ import im.vector.riotx.R
|
|||
import im.vector.riotx.core.epoxy.VectorEpoxyHolder
|
||||
import im.vector.riotx.core.epoxy.VectorEpoxyModel
|
||||
import im.vector.riotx.core.extensions.showPassword
|
||||
import im.vector.riotx.core.platform.SimpleTextWatcher
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
|
||||
@EpoxyModelClass(layout = R.layout.item_login_password_form)
|
||||
abstract class LoginPasswordFormItem : VectorEpoxyModel<LoginPasswordFormItem.Holder>() {
|
||||
|
||||
@EpoxyAttribute var passwordShown: Boolean = false
|
||||
@EpoxyAttribute var submitEnabled: Boolean = false
|
||||
@EpoxyAttribute var errorText: String? = null
|
||||
@EpoxyAttribute lateinit var stringProvider: StringProvider
|
||||
@EpoxyAttribute var passwordRevealClickListener: (() -> Unit)? = null
|
||||
@EpoxyAttribute var forgetPasswordClickListener: (() -> Unit)? = null
|
||||
@EpoxyAttribute var submitClickListener: ((String) -> Unit)? = null
|
||||
@EpoxyAttribute var onPasswordEdited: ((String) -> Unit)? = null
|
||||
|
||||
private val textChangeListener = object : SimpleTextWatcher() {
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
onPasswordEdited?.invoke(s.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
|
@ -48,7 +58,14 @@ abstract class LoginPasswordFormItem : VectorEpoxyModel<LoginPasswordFormItem.Ho
|
|||
renderPasswordField(holder)
|
||||
holder.passwordReveal.setOnClickListener { passwordRevealClickListener?.invoke() }
|
||||
holder.forgetPassword.setOnClickListener { forgetPasswordClickListener?.invoke() }
|
||||
holder.submit.isEnabled = submitEnabled
|
||||
holder.submit.setOnClickListener { submitClickListener?.invoke(holder.passwordField.text.toString()) }
|
||||
holder.passwordField.addTextChangedListener(textChangeListener)
|
||||
}
|
||||
|
||||
override fun unbind(holder: Holder) {
|
||||
super.unbind(holder)
|
||||
holder.passwordField.removeTextChangedListener(textChangeListener)
|
||||
}
|
||||
|
||||
private fun setupAutoFill(holder: Holder) {
|
||||
|
|
Loading…
Reference in a new issue