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