From a115392c0f78f7323a68af56fa5d1e33b9f59dde Mon Sep 17 00:00:00 2001 From: Andre Kirchhoff Date: Sun, 28 Nov 2021 16:14:34 -0300 Subject: [PATCH] fix local IME Action call --- .../geeksville/mesh/ui/MessagesFragment.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt index d71958286..28db58802 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt @@ -30,8 +30,6 @@ import java.util.* // Allows usage like email.on(EditorInfo.IME_ACTION_NEXT, { confirm() }) fun EditText.on(actionId: Int, func: () -> Unit) { - setImeOptions(EditorInfo.IME_ACTION_SEND) // Force "SEND" IME Action - setRawInputType(InputType.TYPE_CLASS_TEXT) // Suppress ENTER but allow textMultiLine setOnEditorActionListener { _, receivedActionId, _ -> if (actionId == receivedActionId) { @@ -50,6 +48,20 @@ class MessagesFragment : ScreenFragment("Messages"), Logging { private val binding get() = _binding!! private val model: UIViewModel by activityViewModels() + + // Allows textMultiline with IME_ACTION_SEND + fun EditText.onActionSend(func: () -> Unit) { + setImeOptions(EditorInfo.IME_ACTION_SEND) + setRawInputType(InputType.TYPE_CLASS_TEXT) + setOnEditorActionListener { _, actionId, _ -> + + if (actionId == EditorInfo.IME_ACTION_SEND) { + func() + } + + true + } + } private val dateTimeFormat: DateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) @@ -244,7 +256,7 @@ class MessagesFragment : ScreenFragment("Messages"), Logging { // requireActivity().hideKeyboard() } - binding.messageInputText.on(EditorInfo.IME_ACTION_SEND) { + binding.messageInputText.onActionSend { debug("did IME action") val str = binding.messageInputText.text.toString().trim() @@ -291,4 +303,3 @@ class MessagesFragment : ScreenFragment("Messages"), Logging { } } -