aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-10-20 21:20:34 +0200
committerChristian Schneppe <christian@pix-art.de>2018-10-20 21:20:34 +0200
commitec7963e9bbe8accdcda050f24b06a63c01ac1ae2 (patch)
treed7f116da79a18a99c9ae2fdde1df7e58c0101d2d /src/main/java
parent29c41ec7286b66d813b8c4ff04098b675c3d8718 (diff)
make jids appear as monospace in dialogs
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlockContactDialog.java19
-rw-r--r--src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java9
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java16
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/JidDialog.java22
4 files changed, 38 insertions, 28 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
index f7711ce34..4f768b009 100644
--- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
@@ -1,10 +1,8 @@
package de.pixart.messenger.ui;
import android.databinding.DataBindingUtil;
+import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.style.TypefaceSpan;
import android.view.View;
import android.widget.Toast;
@@ -12,6 +10,7 @@ import de.pixart.messenger.R;
import de.pixart.messenger.databinding.DialogBlockContactBinding;
import de.pixart.messenger.entities.Blockable;
import de.pixart.messenger.entities.Conversation;
+import de.pixart.messenger.ui.util.JidDialog;
import rocks.xmpp.addr.Jid;
public final class BlockContactDialog {
@@ -24,23 +23,19 @@ public final class BlockContactDialog {
binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
builder.setView(binding.getRoot());
- String value;
- SpannableString spannable;
+ final String value;
+ @StringRes int res;
if (blockable.getJid().getLocal() == null || blockable.getAccount().isBlocked(Jid.ofDomain(blockable.getJid().getDomain()))) {
builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
value = Jid.ofDomain(blockable.getJid().getDomain()).toString();
- spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value));
+ res = isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text;
} else {
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
value = blockable.getJid().asBareJid().toString();
- spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value));
+ res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
}
- int start = spannable.toString().indexOf(value);
- if (start >= 0) {
- spannable.setSpan(new TypefaceSpan("monospace"), start, start + value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- binding.text.setText(spannable);
+ binding.text.setText(JidDialog.style(xmppActivity, res, value));
builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, (dialog, which) -> {
if (isBlocked) {
xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
index 147b8b4fe..619c2b3f2 100644
--- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
@@ -51,6 +51,7 @@ import de.pixart.messenger.ui.adapter.MediaAdapter;
import de.pixart.messenger.ui.interfaces.OnMediaLoaded;
import de.pixart.messenger.ui.util.Attachment;
import de.pixart.messenger.ui.util.GridManager;
+import de.pixart.messenger.ui.util.JidDialog;
import de.pixart.messenger.utils.Compatibility;
import de.pixart.messenger.utils.CryptoHelper;
import de.pixart.messenger.utils.EmojiWrapper;
@@ -420,10 +421,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
binding.addContactButton.setOnClickListener(view -> {
final AlertDialog.Builder deleteFromRosterDialog = new AlertDialog.Builder(ContactDetailsActivity.this);
- deleteFromRosterDialog.setNegativeButton(getString(R.string.cancel), null);
- deleteFromRosterDialog.setTitle(getString(R.string.action_delete_contact));
- deleteFromRosterDialog.setMessage(getString(R.string.remove_contact_text, contact.getJid().toString()));
- deleteFromRosterDialog.setPositiveButton(getString(R.string.delete), removeFromRoster).create().show();
+ deleteFromRosterDialog.setNegativeButton(getString(R.string.cancel), null)
+ .setTitle(getString(R.string.action_delete_contact))
+ .setMessage(JidDialog.style(this, R.string.remove_contact_text, contact.getJid().toEscapedString()))
+ .setPositiveButton(getString(R.string.delete), removeFromRoster).create().show();
});
binding.detailsSendPresence.setOnCheckedChangeListener(null);
binding.detailsReceivePresence.setOnCheckedChangeListener(null);
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index efd4d3b8d..10574fab4 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -26,10 +26,7 @@ import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
-import android.text.SpannableString;
-import android.text.Spanned;
import android.text.TextWatcher;
-import android.text.style.TypefaceSpan;
import android.util.Log;
import android.util.Pair;
import android.view.ContextMenu;
@@ -71,6 +68,7 @@ import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate;
import de.pixart.messenger.ui.adapter.ListItemAdapter;
import de.pixart.messenger.ui.interfaces.OnBackendConnected;
+import de.pixart.messenger.ui.util.JidDialog;
import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.ui.util.SoftKeyboardUtils;
import de.pixart.messenger.utils.MenuDoubleTabUtil;
@@ -429,7 +427,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.action_delete_contact);
- builder.setMessage(getString(R.string.remove_contact_text, contact.getJid()));
+ builder.setMessage(JidDialog.style(this, R.string.remove_contact_text, contact.getJid().toEscapedString()));
builder.setPositiveButton(R.string.delete, (dialog, which) -> {
xmppConnectionService.deleteContactOnServer(contact);
filter(mSearchEditText.getText().toString());
@@ -444,7 +442,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.delete_bookmark);
- builder.setMessage(getString(R.string.remove_bookmark_text, bookmark.getJid()));
+ builder.setMessage(JidDialog.style(this, R.string.remove_bookmark_text, bookmark.getJid().toEscapedString()));
builder.setPositiveButton(R.string.delete, (dialog, which) -> {
bookmark.setConversation(null);
Account account = bookmark.getAccount();
@@ -834,13 +832,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
View view = getLayoutInflater().inflate(R.layout.dialog_verify_fingerprints, null);
final CheckBox isTrustedSource = view.findViewById(R.id.trusted_source);
TextView warning = view.findViewById(R.id.warning);
- String jid = contact.getJid().asBareJid().toString();
- SpannableString spannable = new SpannableString(getString(R.string.verifying_omemo_keys_trusted_source, jid, contact.getDisplayName()));
- int start = spannable.toString().indexOf(jid);
- if (start >= 0) {
- spannable.setSpan(new TypefaceSpan("monospace"), start, start + jid.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- warning.setText(spannable);
+ warning.setText(JidDialog.style(this, R.string.verifying_omemo_keys_trusted_source, contact.getJid().asBareJid().toEscapedString(), contact.getDisplayName()));
builder.setView(view);
builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
if (isTrustedSource.isChecked() && invite.hasFingerprints()) {
diff --git a/src/main/java/de/pixart/messenger/ui/util/JidDialog.java b/src/main/java/de/pixart/messenger/ui/util/JidDialog.java
new file mode 100644
index 000000000..291bb873c
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/util/JidDialog.java
@@ -0,0 +1,22 @@
+package de.pixart.messenger.ui.util;
+
+import android.content.Context;
+import android.support.annotation.StringRes;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.style.TypefaceSpan;
+
+public class JidDialog {
+
+ public static SpannableString style(Context context, @StringRes int res, String... args) {
+ SpannableString spannable = new SpannableString(context.getString(res, (Object[]) args));
+ if (args.length >= 1) {
+ final String value = args[0];
+ int start = spannable.toString().indexOf(value);
+ if (start >= 0) {
+ spannable.setSpan(new TypefaceSpan("monospace"), start, start + value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ }
+ return spannable;
+ }
+} \ No newline at end of file