Apply imeOptions to ComposerEditText without overriding previously set options

This commit is contained in:
Tomáš Beňo 2022-09-25 14:42:07 +02:00
parent d2f9ca4cbc
commit e5cf431cc7
2 changed files with 17 additions and 11 deletions

View File

@ -1537,12 +1537,7 @@ class TimelineFragment :
observerUserTyping()
composerEditText.setUseIncognitoKeyboard(vectorPreferences.useIncognitoKeyboard())
if (vectorPreferences.sendMessageWithEnter()) {
// imeOptions="actionSend" only works with single line, so we remove multiline inputType
composerEditText.inputType = composerEditText.inputType and EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE.inv()
composerEditText.imeOptions = EditorInfo.IME_ACTION_SEND
}
composerEditText.setSendMessageWithEnter(vectorPreferences.sendMessageWithEnter())
composerEditText.setOnEditorActionListener { v, actionId, keyEvent ->
val imeActionId = actionId and EditorInfo.IME_MASK_ACTION

View File

@ -81,7 +81,22 @@ class ComposerEditText @JvmOverloads constructor(
/** Set whether the keyboard should disable personalized learning. */
fun setUseIncognitoKeyboard(useIncognitoKeyboard: Boolean) {
imeOptions = if (useIncognitoKeyboard) imeOptions or INCOGNITO_KEYBOARD_IME else imeOptions and INCOGNITO_KEYBOARD_IME.inv()
imeOptions = if (useIncognitoKeyboard) {
imeOptions or EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING
} else {
imeOptions and EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING.inv()
}
}
/** Set whether enter should send the message or add a new line. */
fun setSendMessageWithEnter(sendMessageWithEnter: Boolean) {
if (sendMessageWithEnter) {
inputType = inputType and EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE.inv()
imeOptions = imeOptions or EditorInfo.IME_ACTION_SEND
} else {
inputType = inputType or EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
imeOptions = imeOptions and EditorInfo.IME_ACTION_SEND.inv()
}
}
init {
@ -121,8 +136,4 @@ class ComposerEditText @JvmOverloads constructor(
}
)
}
companion object {
const val INCOGNITO_KEYBOARD_IME = EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING
}
}