Refactor to handle more cases
This commit is contained in:
parent
3ea7b37df3
commit
dc230f1c30
|
@ -107,15 +107,9 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.textInputEditText.isEnabled = enabled
|
holder.textInputEditText.isEnabled = enabled
|
||||||
inputType?.let { holder.textInputEditText.inputType = it }
|
|
||||||
imeOptions?.let { holder.textInputEditText.imeOptions = it }
|
|
||||||
|
|
||||||
if (singleLine) {
|
configureInputType(holder)
|
||||||
holder.textInputEditText.maxLines = 1
|
configureImeOptions(holder)
|
||||||
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.addTextChangedListenerOnce(onTextChangeListener)
|
||||||
holder.textInputEditText.setOnEditorActionListener(editorActionListener)
|
holder.textInputEditText.setOnEditorActionListener(editorActionListener)
|
||||||
|
@ -131,6 +125,32 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
override fun shouldSaveViewState(): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue