make jids appear as monospace in dialogs

This commit is contained in:
Daniel Gultsch 2018-10-06 17:03:12 +02:00
parent fd165e5106
commit 8980a0c631
4 changed files with 36 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
@ -12,6 +13,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.DialogBlockContactBinding; import eu.siacs.conversations.databinding.DialogBlockContactBinding;
import eu.siacs.conversations.entities.Blockable; import eu.siacs.conversations.entities.Blockable;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.ui.util.JidDialog;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public final class BlockContactDialog { public final class BlockContactDialog {
@ -24,23 +26,19 @@ public final class BlockContactDialog {
binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE); binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
builder.setView(binding.getRoot()); builder.setView(binding.getRoot());
String value; final String value;
SpannableString spannable; @StringRes int res;
if (blockable.getJid().getLocal() == null || blockable.getAccount().isBlocked(Jid.ofDomain(blockable.getJid().getDomain()))) { 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); builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
value = Jid.ofDomain(blockable.getJid().getDomain()).toString(); 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 { } else {
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact; 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); builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
value = blockable.getJid().asBareJid().toString(); 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); binding.text.setText(JidDialog.style(xmppActivity, res, value));
if (start >= 0) {
spannable.setSpan(new TypefaceSpan("monospace"), start, start + value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
binding.text.setText(spannable);
builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, (dialog, which) -> { builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, (dialog, which) -> {
if (isBlocked) { if (isBlocked) {
xmppActivity.xmppConnectionService.sendUnblockRequest(blockable); xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);

View File

@ -44,6 +44,7 @@ import eu.siacs.conversations.ui.adapter.MediaAdapter;
import eu.siacs.conversations.ui.interfaces.OnMediaLoaded; import eu.siacs.conversations.ui.interfaces.OnMediaLoaded;
import eu.siacs.conversations.ui.util.Attachment; import eu.siacs.conversations.ui.util.Attachment;
import eu.siacs.conversations.ui.util.GridManager; import eu.siacs.conversations.ui.util.GridManager;
import eu.siacs.conversations.ui.util.JidDialog;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.IrregularUnicodeDetector; import eu.siacs.conversations.utils.IrregularUnicodeDetector;
@ -241,7 +242,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
break; break;
case R.id.action_delete_contact: case R.id.action_delete_contact:
builder.setTitle(getString(R.string.action_delete_contact)) builder.setTitle(getString(R.string.action_delete_contact))
.setMessage(getString(R.string.remove_contact_text, contact.getJid().toString())) .setMessage(JidDialog.style(this, R.string.remove_contact_text, contact.getJid().toEscapedString()))
.setPositiveButton(getString(R.string.delete), .setPositiveButton(getString(R.string.delete),
removeFromRoster).create().show(); removeFromRoster).create().show();
break; break;

View File

@ -71,6 +71,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.ListItemAdapter; import eu.siacs.conversations.ui.adapter.ListItemAdapter;
import eu.siacs.conversations.ui.interfaces.OnBackendConnected; import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
import eu.siacs.conversations.ui.service.EmojiService; import eu.siacs.conversations.ui.service.EmojiService;
import eu.siacs.conversations.ui.util.JidDialog;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
@ -427,7 +428,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.action_delete_contact); 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) -> { builder.setPositiveButton(R.string.delete, (dialog, which) -> {
xmppConnectionService.deleteContactOnServer(contact); xmppConnectionService.deleteContactOnServer(contact);
filter(mSearchEditText.getText().toString()); filter(mSearchEditText.getText().toString());
@ -442,8 +443,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.delete_bookmark); builder.setTitle(R.string.delete_bookmark);
builder.setMessage(getString(R.string.remove_bookmark_text, builder.setMessage(JidDialog.style(this, R.string.remove_bookmark_text, bookmark.getJid().toEscapedString()));
bookmark.getJid()));
builder.setPositiveButton(R.string.delete, (dialog, which) -> { builder.setPositiveButton(R.string.delete, (dialog, which) -> {
bookmark.setConversation(null); bookmark.setConversation(null);
Account account = bookmark.getAccount(); Account account = bookmark.getAccount();
@ -821,13 +821,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
View view = getLayoutInflater().inflate(R.layout.dialog_verify_fingerprints, null); View view = getLayoutInflater().inflate(R.layout.dialog_verify_fingerprints, null);
final CheckBox isTrustedSource = view.findViewById(R.id.trusted_source); final CheckBox isTrustedSource = view.findViewById(R.id.trusted_source);
TextView warning = view.findViewById(R.id.warning); TextView warning = view.findViewById(R.id.warning);
String jid = contact.getJid().asBareJid().toString(); warning.setText(JidDialog.style(this, R.string.verifying_omemo_keys_trusted_source, contact.getJid().asBareJid().toEscapedString(), contact.getDisplayName()));
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);
builder.setView(view); builder.setView(view);
builder.setPositiveButton(R.string.confirm, (dialog, which) -> { builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
if (isTrustedSource.isChecked() && invite.hasFingerprints()) { if (isTrustedSource.isChecked() && invite.hasFingerprints()) {

View File

@ -0,0 +1,23 @@
package eu.siacs.conversations.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;
}
}