From 1fc432af53ed525104e2a6aa4cb74cead7aa3edc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 22 Jun 2018 17:42:52 +0200 Subject: [PATCH] use TextInputLayout in quickedit dialog --- .../siacs/conversations/entities/Contact.java | 6 +++- .../ui/ConferenceDetailsActivity.java | 4 +-- .../ui/ContactDetailsActivity.java | 2 +- .../siacs/conversations/ui/XmppActivity.java | 29 ++++++++-------- src/main/res/layout/dialog_quickedit.xml | 34 +++++++++++++++++++ src/main/res/layout/quickedit.xml | 19 ----------- src/main/res/values/strings.xml | 2 ++ 7 files changed, 58 insertions(+), 38 deletions(-) create mode 100644 src/main/res/layout/dialog_quickedit.xml delete mode 100644 src/main/res/layout/quickedit.xml diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index 63898b26e..fb221e317 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -493,7 +493,11 @@ public class Contact implements ListItem, Blockable { return this.mLastPresence; } - public final class Options { + public String getServerName() { + return serverName; + } + + public final class Options { public static final int TO = 0; public static final int FROM = 1; public static final int ASKING = 2; diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 80f6bea10..1617fbe62 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -244,12 +244,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers setSupportActionBar((Toolbar) binding.toolbar); configureActionBar(getSupportActionBar()); this.binding.editNickButton.setOnClickListener(v -> quickEdit(mConversation.getMucOptions().getActualNick(), - 0, + R.string.nickname_for_this_group_chat, value -> { if (xmppConnectionService.renameInMuc(mConversation, value, renameCallback)) { return null; } else { - return getString(R.string.invalid_username); + return getString(R.string.invalid_muc_nick); } })); this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false); diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 95cc2bcfd..3c08d8234 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -228,7 +228,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp case R.id.action_edit_contact: Uri systemAccount = contact.getSystemAccount(); if (systemAccount == null) { - quickEdit(contact.getDisplayName(), 0, value -> { + quickEdit(contact.getServerName(), R.string.contact_name, value -> { contact.setServerName(value); ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact); populateView(); diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 08073dfc1..65fcceee7 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -18,6 +18,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.content.res.TypedArray; +import android.databinding.DataBindingUtil; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Point; @@ -34,6 +35,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.annotation.BoolRes; +import android.support.annotation.StringRes; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog.Builder; @@ -48,7 +50,6 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; -import java.io.FileNotFoundException; import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -59,6 +60,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; +import eu.siacs.conversations.databinding.DialogQuickeditBinding; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; @@ -687,11 +689,11 @@ public abstract class XmppActivity extends ActionBarActivity { builder.create().show(); } - protected void quickEdit(String previousValue, int hint, OnValueEdited callback) { + protected void quickEdit(String previousValue, @StringRes int hint, OnValueEdited callback) { quickEdit(previousValue, callback, hint, false, false); } - protected void quickEdit(String previousValue, int hint, OnValueEdited callback, boolean permitEmpty) { + protected void quickEdit(String previousValue, @StringRes int hint, OnValueEdited callback, boolean permitEmpty) { quickEdit(previousValue, callback, hint, false, permitEmpty); } @@ -702,35 +704,32 @@ public abstract class XmppActivity extends ActionBarActivity { @SuppressLint("InflateParams") private void quickEdit(final String previousValue, final OnValueEdited callback, - final int hint, + final @StringRes int hint, boolean password, boolean permitEmpty) { AlertDialog.Builder builder = new AlertDialog.Builder(this); - View view = getLayoutInflater().inflate(R.layout.quickedit, null); - final EditText editor = view.findViewById(R.id.editor); + DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.dialog_quickedit, null, false); if (password) { - editor.setInputType(InputType.TYPE_CLASS_TEXT - | InputType.TYPE_TEXT_VARIATION_PASSWORD); + binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } builder.setPositiveButton(R.string.accept, null); if (hint != 0) { - editor.setHint(hint); + binding.inputLayout.setHint(getString(hint)); } - editor.requestFocus(); - editor.setText(""); + binding.inputEditText.requestFocus(); if (previousValue != null) { - editor.getText().append(previousValue); + binding.inputEditText.getText().append(previousValue); } - builder.setView(view); + builder.setView(binding.getRoot()); builder.setNegativeButton(R.string.cancel, null); final AlertDialog dialog = builder.create(); dialog.show(); View.OnClickListener clickListener = v -> { - String value = editor.getText().toString(); + String value = binding.inputEditText.getText().toString(); if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) { String error = callback.onValueEdited(value); if (error != null) { - editor.setError(error); + binding.inputLayout.setError(error); return; } } diff --git a/src/main/res/layout/dialog_quickedit.xml b/src/main/res/layout/dialog_quickedit.xml new file mode 100644 index 000000000..5dc56613d --- /dev/null +++ b/src/main/res/layout/dialog_quickedit.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/quickedit.xml b/src/main/res/layout/quickedit.xml deleted file mode 100644 index 2042670ea..000000000 --- a/src/main/res/layout/quickedit.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2b4e87b1f..9fa7398fa 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -719,4 +719,6 @@ Group chat avatar Host does not support group chat avatars Only the owner can change group chat avatar + Contact name + Nickname for this group chat