fixups and code clean up for 'Ctrl+Enter'

This commit is contained in:
Daniel Gultsch 2020-07-12 08:28:09 +02:00
parent e7e04837b6
commit c9e6653e33
3 changed files with 14 additions and 11 deletions

View File

@ -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

View File

@ -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();

View File

@ -401,7 +401,7 @@
<string name="mark_as_read">Mark as read</string>
<string name="pref_input_options">Input</string>
<string name="pref_enter_is_send">Enter is send</string>
<string name="pref_enter_is_send_summary">Use enter key to send message. You can always use ctrl+enter to send message, even if this option is disabled.</string>
<string name="pref_enter_is_send_summary">Use Enter key to send message. You can always use Ctrl+Enter to send message, even if this option is disabled.</string>
<string name="pref_display_enter_key">Show enter key</string>
<string name="pref_display_enter_key_summary">Change the emoticons key to an enter key</string>
<string name="audio">audio</string>