diff --git a/vector/src/main/java/im/vector/app/core/epoxy/VectorEpoxyFormExt.kt b/vector/src/main/java/im/vector/app/core/epoxy/VectorEpoxyFormExt.kt index f93b07a98d..4bc40ce557 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/VectorEpoxyFormExt.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/VectorEpoxyFormExt.kt @@ -16,7 +16,9 @@ package im.vector.app.core.epoxy +import android.text.TextWatcher import android.widget.CompoundButton +import android.widget.TextView import com.google.android.material.switchmaterial.SwitchMaterial import com.google.android.material.textfield.TextInputEditText @@ -39,3 +41,9 @@ fun VectorEpoxyHolder.setValueOnce(switchView: SwitchMaterial, switchChecked: Bo switchView.setOnCheckedChangeListener(listener) } } + +fun TextView.addTextChangedListenerOnce(textWatcher: TextWatcher) { + // Ensure the watcher is not added multiple times + removeTextChangedListener(textWatcher) + addTextChangedListener(textWatcher) +} diff --git a/vector/src/main/java/im/vector/app/features/form/FormEditTextItem.kt b/vector/src/main/java/im/vector/app/features/form/FormEditTextItem.kt index 8e9b72d2d8..b66c023c6e 100644 --- a/vector/src/main/java/im/vector/app/features/form/FormEditTextItem.kt +++ b/vector/src/main/java/im/vector/app/features/form/FormEditTextItem.kt @@ -28,6 +28,7 @@ import com.google.android.material.textfield.TextInputLayout import im.vector.app.R 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.setValueOnce import im.vector.app.core.platform.SimpleTextWatcher @@ -61,11 +62,10 @@ abstract class FormEditTextItem : VectorEpoxyModel() { @EpoxyAttribute var endIconMode: Int? = null - // FIXME restore EpoxyAttribute.Option.DoNotHash and fix that properly - @EpoxyAttribute + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onTextChange: ((String) -> Unit)? = null - @EpoxyAttribute + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var editorActionListener: TextView.OnEditorActionListener? = null private val onTextChangeListener = object : SimpleTextWatcher() { @@ -88,7 +88,7 @@ abstract class FormEditTextItem : VectorEpoxyModel() { holder.textInputEditText.isSingleLine = singleLine holder.textInputEditText.imeOptions = imeOptions ?: EditorInfo.IME_ACTION_NONE - holder.textInputEditText.addTextChangedListener(onTextChangeListener) + holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener) holder.textInputEditText.setOnEditorActionListener(editorActionListener) holder.bottomSeparator.isVisible = showBottomSeparator } diff --git a/vector/src/main/java/im/vector/app/features/form/FormEditTextWithButtonItem.kt b/vector/src/main/java/im/vector/app/features/form/FormEditTextWithButtonItem.kt index 133800e6b5..c61caf541f 100644 --- a/vector/src/main/java/im/vector/app/features/form/FormEditTextWithButtonItem.kt +++ b/vector/src/main/java/im/vector/app/features/form/FormEditTextWithButtonItem.kt @@ -26,6 +26,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.ClickListener 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.platform.SimpleTextWatcher @@ -45,7 +46,7 @@ abstract class FormEditTextWithButtonItem : VectorEpoxyModel Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) @@ -66,7 +67,7 @@ abstract class FormEditTextWithButtonItem : VectorEpoxyModel() @EpoxyAttribute var enabled: Boolean = true - @EpoxyAttribute + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onTextChange: ((String) -> Unit)? = null private val onTextChangeListener = object : SimpleTextWatcher() { @@ -64,7 +65,7 @@ abstract class RoomAliasEditItem : VectorEpoxyModel() holder.setValueOnce(holder.textInputEditText, value) holder.textInputEditText.isEnabled = enabled - holder.textInputEditText.addTextChangedListener(onTextChangeListener) + holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener) holder.homeServerText.text = homeServer holder.bottomSeparator.isVisible = showBottomSeparator } diff --git a/vector/src/main/java/im/vector/app/features/signout/soft/epoxy/LoginPasswordFormItem.kt b/vector/src/main/java/im/vector/app/features/signout/soft/epoxy/LoginPasswordFormItem.kt index 79ab18942b..872fa5391d 100644 --- a/vector/src/main/java/im/vector/app/features/signout/soft/epoxy/LoginPasswordFormItem.kt +++ b/vector/src/main/java/im/vector/app/features/signout/soft/epoxy/LoginPasswordFormItem.kt @@ -27,6 +27,7 @@ import com.google.android.material.textfield.TextInputLayout import im.vector.app.R 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.extensions.showPassword import im.vector.app.core.platform.SimpleTextWatcher import im.vector.app.core.resources.StringProvider @@ -42,7 +43,7 @@ abstract class LoginPasswordFormItem : VectorEpoxyModel Unit)? = null @EpoxyAttribute var forgetPasswordClickListener: (() -> Unit)? = null @EpoxyAttribute var submitClickListener: ((String) -> Unit)? = null - @EpoxyAttribute var onPasswordEdited: ((String) -> Unit)? = null + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onPasswordEdited: ((String) -> Unit)? = null private val textChangeListener = object : SimpleTextWatcher() { override fun afterTextChanged(s: Editable) { @@ -60,7 +61,7 @@ abstract class LoginPasswordFormItem : VectorEpoxyModel