From 394e2527771da2b3baa0cdd76f3d09e135af97fe Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 10 Jan 2019 22:09:20 +0100 Subject: [PATCH] support enter/done key in create contact & join dialogs --- .../ui/CreateConferenceDialog.java | 6 ++ .../conversations/ui/EnterJidDialog.java | 74 +++++++++++-------- .../ui/JoinConferenceDialog.java | 6 ++ .../res/layout/create_conference_dialog.xml | 3 +- .../res/layout/dialog_join_conference.xml | 3 +- src/main/res/layout/enter_jid_dialog.xml | 3 +- 6 files changed, 62 insertions(+), 33 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/CreateConferenceDialog.java b/src/main/java/eu/siacs/conversations/ui/CreateConferenceDialog.java index 5ca2222c5..21eee709e 100644 --- a/src/main/java/eu/siacs/conversations/ui/CreateConferenceDialog.java +++ b/src/main/java/eu/siacs/conversations/ui/CreateConferenceDialog.java @@ -8,9 +8,11 @@ import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AlertDialog; +import android.view.KeyEvent; import android.view.View; import android.widget.EditText; import android.widget.Spinner; +import android.widget.TextView; import java.util.ArrayList; import java.util.List; @@ -50,6 +52,10 @@ public class CreateConferenceDialog extends DialogFragment { builder.setPositiveButton(R.string.choose_participants, (dialog, which) -> mListener.onCreateDialogPositiveClick(binding.account, binding.groupChatName.getText().toString().trim())); builder.setNegativeButton(R.string.cancel, null); DelayedHintHelper.setHint(R.string.providing_a_name_is_optional, binding.groupChatName); + binding.groupChatName.setOnEditorActionListener((v, actionId, event) -> { + mListener.onCreateDialogPositiveClick(binding.account, binding.groupChatName.getText().toString().trim()); + return true; + }); return builder.create(); } diff --git a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java index 7d8041968..39be7d987 100644 --- a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java +++ b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java @@ -8,10 +8,12 @@ import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.app.Dialog; import android.util.Log; +import android.view.KeyEvent; import android.view.View; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Spinner; +import android.widget.TextView; import java.util.ArrayList; import java.util.Collection; @@ -103,48 +105,60 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected binding.account.setAdapter(adapter); } + + builder.setView(binding.getRoot()); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(getArguments().getString(POSITIVE_BUTTON_KEY), null); AlertDialog dialog = builder.create(); View.OnClickListener dialogOnClick = v -> { - final Jid accountJid; - if (!binding.account.isEnabled() && account == null) { - return; - } - try { - if (Config.DOMAIN_LOCK != null) { - accountJid = Jid.of((String) binding.account.getSelectedItem(), Config.DOMAIN_LOCK, null); - } else { - accountJid = Jid.of((String) binding.account.getSelectedItem()); - } - } catch (final IllegalArgumentException e) { - return; - } - final Jid contactJid; - try { - contactJid = Jid.of(binding.jid.getText().toString()); - } catch (final IllegalArgumentException e) { - binding.jid.setError(getActivity().getString(R.string.invalid_jid)); - return; - } - - if (mListener != null) { - try { - if (mListener.onEnterJidDialogPositive(accountJid, contactJid)) { - dialog.dismiss(); - } - } catch (JidError error) { - binding.jid.setError(error.toString()); - } - } + handleEnter(binding, account, dialog); }; + + binding.jid.setOnEditorActionListener((v, actionId, event) -> { + handleEnter(binding, account, dialog); + return true; + }); + dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(dialogOnClick); return dialog; } + private void handleEnter(EnterJidDialogBinding binding, String account, Dialog dialog) { + final Jid accountJid; + if (!binding.account.isEnabled() && account == null) { + return; + } + try { + if (Config.DOMAIN_LOCK != null) { + accountJid = Jid.of((String) binding.account.getSelectedItem(), Config.DOMAIN_LOCK, null); + } else { + accountJid = Jid.of((String) binding.account.getSelectedItem()); + } + } catch (final IllegalArgumentException e) { + return; + } + final Jid contactJid; + try { + contactJid = Jid.of(binding.jid.getText().toString()); + } catch (final IllegalArgumentException e) { + binding.jid.setError(getActivity().getString(R.string.invalid_jid)); + return; + } + + if (mListener != null) { + try { + if (mListener.onEnterJidDialogPositive(accountJid, contactJid)) { + dialog.dismiss(); + } + } catch (JidError error) { + binding.jid.setError(error.toString()); + } + } + } + public void setOnEnterJidDialogPositiveListener(OnEnterJidDialogPositiveListener listener) { this.mListener = listener; } diff --git a/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java b/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java index d20a796ab..035e828b6 100644 --- a/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java +++ b/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java @@ -9,8 +9,10 @@ import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AlertDialog; +import android.view.KeyEvent; import android.widget.AutoCompleteTextView; import android.widget.Spinner; +import android.widget.TextView; import java.util.ArrayList; import java.util.Collection; @@ -64,6 +66,10 @@ public class JoinConferenceDialog extends DialogFragment implements OnBackendCon AlertDialog dialog = builder.create(); dialog.show(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(view -> mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked())); + binding.jid.setOnEditorActionListener((v, actionId, event) -> { + mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked()); + return true; + }); return dialog; } diff --git a/src/main/res/layout/create_conference_dialog.xml b/src/main/res/layout/create_conference_dialog.xml index 89811fa07..6680ce246 100644 --- a/src/main/res/layout/create_conference_dialog.xml +++ b/src/main/res/layout/create_conference_dialog.xml @@ -33,7 +33,8 @@ style="@style/Widget.Conversations.EditText" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/create_dialog_group_chat_name"/> + android:hint="@string/create_dialog_group_chat_name" + android:imeOptions="actionNext"/> diff --git a/src/main/res/layout/dialog_join_conference.xml b/src/main/res/layout/dialog_join_conference.xml index cef86eda5..ba78f2682 100644 --- a/src/main/res/layout/dialog_join_conference.xml +++ b/src/main/res/layout/dialog_join_conference.xml @@ -35,7 +35,8 @@ style="@style/Widget.Conversations.EditText" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:inputType="textEmailAddress"/> + android:inputType="textEmailAddress" + android:imeOptions="actionDone"/> + android:inputType="textEmailAddress" + android:imeOptions="actionDone"/>