From b3f6b5e14257a841bc5b06755d040839c504946e Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Thu, 21 Oct 2021 01:44:08 +0300 Subject: [PATCH 1/4] Fix Broken EditText when using FromEditTextItem --- changelog.d/4276.bugfix | 1 + .../im/vector/app/features/form/FormEditTextItem.kt | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelog.d/4276.bugfix diff --git a/changelog.d/4276.bugfix b/changelog.d/4276.bugfix new file mode 100644 index 0000000000..8cb2ed6977 --- /dev/null +++ b/changelog.d/4276.bugfix @@ -0,0 +1 @@ +Fix Broken EditText when using FromEditTextItem 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 cda1623c88..c9a640e51a 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 @@ -18,6 +18,7 @@ package im.vector.app.features.form import android.text.Editable import android.text.InputFilter +import android.text.InputType import android.view.View import android.view.inputmethod.EditorInfo import android.widget.TextView @@ -107,8 +108,13 @@ abstract class FormEditTextItem : VectorEpoxyModel() { holder.textInputEditText.isEnabled = enabled inputType?.let { holder.textInputEditText.inputType = it } - holder.textInputEditText.isSingleLine = singleLine - holder.textInputEditText.imeOptions = imeOptions ?: EditorInfo.IME_ACTION_NONE + + if (singleLine) { + holder.textInputEditText.maxLines = 1 + holder.textInputEditText.minLines = 1 + imeOptions ?: run { holder.textInputEditText.imeOptions = EditorInfo.IME_ACTION_NEXT } + inputType ?: run { holder.textInputEditText.setRawInputType(InputType.TYPE_CLASS_TEXT) } + } holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener) holder.textInputEditText.setOnEditorActionListener(editorActionListener) From 3ea7b37df30ff8ee7093d301d1a20c3f571f29ca Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Thu, 21 Oct 2021 01:54:45 +0300 Subject: [PATCH 2/4] Improve imeOptions --- .../main/java/im/vector/app/features/form/FormEditTextItem.kt | 1 + 1 file changed, 1 insertion(+) 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 c9a640e51a..328385049b 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 @@ -108,6 +108,7 @@ abstract class FormEditTextItem : VectorEpoxyModel() { holder.textInputEditText.isEnabled = enabled inputType?.let { holder.textInputEditText.inputType = it } + imeOptions?.let { holder.textInputEditText.imeOptions = it } if (singleLine) { holder.textInputEditText.maxLines = 1 From dc230f1c300102ac9ad5ead77d694651228ba4e4 Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Thu, 21 Oct 2021 14:31:50 +0300 Subject: [PATCH 3/4] Refactor to handle more cases --- .../app/features/form/FormEditTextItem.kt | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) 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 328385049b..e23a076485 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 @@ -107,15 +107,9 @@ abstract class FormEditTextItem : VectorEpoxyModel() { } holder.textInputEditText.isEnabled = enabled - inputType?.let { holder.textInputEditText.inputType = it } - imeOptions?.let { holder.textInputEditText.imeOptions = it } - if (singleLine) { - holder.textInputEditText.maxLines = 1 - holder.textInputEditText.minLines = 1 - imeOptions ?: run { holder.textInputEditText.imeOptions = EditorInfo.IME_ACTION_NEXT } - inputType ?: run { holder.textInputEditText.setRawInputType(InputType.TYPE_CLASS_TEXT) } - } + configureInputType(holder) + configureImeOptions(holder) holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener) holder.textInputEditText.setOnEditorActionListener(editorActionListener) @@ -131,6 +125,32 @@ abstract class FormEditTextItem : VectorEpoxyModel() { } } + /** + * Configure the inputType of the EditText, input type should be always defined + * especially when we want to use a single line, we set the InputType to InputType.TYPE_CLASS_TEXT + * while the default for the EditText is InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE + */ + private fun configureInputType(holder: Holder) = + inputType?.let { + holder.textInputEditText.setRawInputType(it) + } ?: when (singleLine) { + true -> holder.textInputEditText.setRawInputType(InputType.TYPE_CLASS_TEXT) + false -> holder.textInputEditText.setRawInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) + } + + /** + * Configure the imeOptions of the EditText, when imeOptions are not defined by user + * EditorInfo.IME_ACTION_NEXT will be used for singleLine EditTexts to disable "new line" + * while EditorInfo.IME_ACTION_NONE will be used for all the other cases + */ + private fun configureImeOptions(holder: Holder) = + imeOptions?.let { + holder.textInputEditText.imeOptions = it + } ?: when (singleLine) { + true -> holder.textInputEditText.imeOptions = EditorInfo.IME_ACTION_NEXT + false -> holder.textInputEditText.imeOptions = EditorInfo.IME_ACTION_NONE + } + override fun shouldSaveViewState(): Boolean { return false } From beab9ab8f197812eb422f952b9fb7b95feb86149 Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Thu, 21 Oct 2021 17:43:01 +0300 Subject: [PATCH 4/4] Refactored for clarity --- .../app/features/form/FormEditTextItem.kt | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) 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 e23a076485..93973c1bdf 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 @@ -130,26 +130,25 @@ abstract class FormEditTextItem : VectorEpoxyModel() { * especially when we want to use a single line, we set the InputType to InputType.TYPE_CLASS_TEXT * while the default for the EditText is InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE */ - private fun configureInputType(holder: Holder) = - inputType?.let { - holder.textInputEditText.setRawInputType(it) - } ?: when (singleLine) { - true -> holder.textInputEditText.setRawInputType(InputType.TYPE_CLASS_TEXT) - false -> holder.textInputEditText.setRawInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) + private fun configureInputType(holder: Holder) = holder.textInputEditText.setRawInputType( + inputType ?: when (singleLine) { + true -> InputType.TYPE_CLASS_TEXT + false -> InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE } + ) /** - * Configure the imeOptions of the EditText, when imeOptions are not defined by user + * Configure the imeOptions of the EditText, when imeOptions are not defined by the developer * EditorInfo.IME_ACTION_NEXT will be used for singleLine EditTexts to disable "new line" * while EditorInfo.IME_ACTION_NONE will be used for all the other cases */ - private fun configureImeOptions(holder: Holder) = - imeOptions?.let { - holder.textInputEditText.imeOptions = it - } ?: when (singleLine) { - true -> holder.textInputEditText.imeOptions = EditorInfo.IME_ACTION_NEXT - false -> holder.textInputEditText.imeOptions = EditorInfo.IME_ACTION_NONE - } + private fun configureImeOptions(holder: Holder) { + holder.textInputEditText.imeOptions = + imeOptions ?: when (singleLine) { + true -> EditorInfo.IME_ACTION_NEXT + false -> EditorInfo.IME_ACTION_NONE + } + } override fun shouldSaveViewState(): Boolean { return false