From c9e6653e33676c3df8502eb7a18d5dc24b7e7750 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 12 Jul 2020 08:28:09 +0200 Subject: [PATCH] fixups and code clean up for 'Ctrl+Enter' --- .../conversations/ui/ConversationFragment.java | 14 ++++++++------ .../siacs/conversations/ui/widget/EditMessage.java | 9 +++++---- src/main/res/values/strings.xml | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 05e02c53f..5fa034b20 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -2735,15 +2735,17 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } @Override - public boolean onEnterPressed(KeyEvent event) { - SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getActivity()); - final boolean enterIsSend = p.getBoolean("enter_is_send", getResources().getBoolean(R.bool.enter_is_send)); - if (enterIsSend || event.isCtrlPressed()) { + public boolean onEnterPressed(final boolean isCtrlPressed) { + if (isCtrlPressed || enterIsSend()) { sendMessage(); return true; - } else { - return false; } + return false; + } + + private boolean enterIsSend() { + final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getActivity()); + return p.getBoolean("enter_is_send", getResources().getBoolean(R.bool.enter_is_send)); } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java index 0687b57b9..1a1327ec4 100644 --- a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java +++ b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java @@ -54,13 +54,14 @@ public class EditMessage extends EmojiWrapperEditText { } @Override - public boolean onKeyDown(int keyCode, KeyEvent e) { + public boolean onKeyDown(final int keyCode, final KeyEvent e) { + final boolean isCtrlPressed = e.isCtrlPressed(); if (keyCode == KeyEvent.KEYCODE_ENTER && !e.isShiftPressed()) { lastInputWasTab = false; - if (keyboardListener != null && keyboardListener.onEnterPressed(e)) { + if (keyboardListener != null && keyboardListener.onEnterPressed(isCtrlPressed)) { return true; } - } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !e.isCtrlPressed()) { + } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !isCtrlPressed) { if (keyboardListener != null && keyboardListener.onTabPressed(this.lastInputWasTab)) { lastInputWasTab = true; return true; @@ -191,7 +192,7 @@ public class EditMessage extends EmojiWrapperEditText { } public interface KeyboardListener { - boolean onEnterPressed(KeyEvent event); + boolean onEnterPressed(boolean isCtrlPressed); void onTypingStarted(); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e3b668dfb..1e46347c6 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -401,7 +401,7 @@ Mark as read Input Enter is send - Use enter key to send message. You can always use ctrl+enter to send message, even if this option is disabled. + Use Enter key to send message. You can always use Ctrl+Enter to send message, even if this option is disabled. Show enter key Change the emoticons key to an enter key audio