From 165fae5734e7a6d0ea3252ee2a325d4c771e25b7 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 20 Feb 2017 16:48:55 +0100 Subject: [PATCH] Display contact custom label instead of phone number Fixes #6211 --- .../securesms/ConversationTitleView.java | 5 ++- .../securesms/recipients/Recipient.java | 10 +++++- .../recipients/RecipientProvider.java | 31 ++++++++++--------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationTitleView.java b/src/org/thoughtcrime/securesms/ConversationTitleView.java index 7b6536b16a..64e593b98a 100644 --- a/src/org/thoughtcrime/securesms/ConversationTitleView.java +++ b/src/org/thoughtcrime/securesms/ConversationTitleView.java @@ -67,7 +67,10 @@ public class ConversationTitleView extends LinearLayout { this.subtitle.setVisibility(View.GONE); } else { this.title.setText(recipient.getName()); - this.subtitle.setText(recipient.getNumber()); + + if (recipient.getCustomLabel() != null) this.subtitle.setText(recipient.getCustomLabel()); + else this.subtitle.setText(recipient.getNumber()); + this.subtitle.setVisibility(View.VISIBLE); } } else { diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index 01eac8e059..65f55981a9 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -46,6 +46,7 @@ public class Recipient { private @NonNull String number; private @Nullable String name; + private @Nullable String customLabel; private boolean stale; private boolean resolving; @@ -70,6 +71,7 @@ public class Recipient { this.contactUri = stale.contactUri; this.contactPhoto = stale.contactPhoto; this.color = stale.color; + this.customLabel = stale.customLabel; } future.addListener(new FutureTaskListener() { @@ -82,6 +84,7 @@ public class Recipient { Recipient.this.contactUri = result.contactUri; Recipient.this.contactPhoto = result.avatar; Recipient.this.color = result.color; + Recipient.this.customLabel = result.customLabel; Recipient.this.resolving = false; } @@ -104,6 +107,7 @@ public class Recipient { this.contactPhoto = details.avatar; this.color = details.color; this.resolving = false; + this.customLabel = details.customLabel; } public synchronized @Nullable Uri getContactUri() { @@ -132,6 +136,10 @@ public class Recipient { return number; } + public @Nullable String getCustomLabel() { + return customLabel; + } + public long getRecipientId() { return recipientId; } @@ -157,7 +165,7 @@ public class Recipient { } public static Recipient getUnknownRecipient() { - return new Recipient(-1, new RecipientDetails("Unknown", "Unknown", null, + return new Recipient(-1, new RecipientDetails("Unknown", "Unknown", null, null, ContactPhotoFactory.getDefaultContactPhoto(null), null)); } diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java index de023827fc..8238cff6cf 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java @@ -61,11 +61,12 @@ class RecipientProvider { PhoneLookup.DISPLAY_NAME, PhoneLookup.LOOKUP_KEY, PhoneLookup._ID, - PhoneLookup.NUMBER + PhoneLookup.NUMBER, + PhoneLookup.LABEL }; private static final Map STATIC_DETAILS = new HashMap() {{ - put("262966", new RecipientDetails("Amazon", "262966", null, + put("262966", new RecipientDetails("Amazon", "262966", null, null, ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_amazon), ContactColors.UNKNOWN_COLOR)); }}; @@ -150,7 +151,7 @@ class RecipientProvider { Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""), name); - return new RecipientDetails(cursor.getString(0), resultNumber, contactUri, contactPhoto, color); + return new RecipientDetails(cursor.getString(0), resultNumber, cursor.getString(4), contactUri, contactPhoto, color); } else { Log.w(TAG, "resultNumber is null"); } @@ -161,7 +162,7 @@ class RecipientProvider { } if (STATIC_DETAILS.containsKey(number)) return STATIC_DETAILS.get(number); - else return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color); + else return new RecipientDetails(null, number, null, null, ContactPhotoFactory.getDefaultContactPhoto(null), color); } private @NonNull RecipientDetails getGroupRecipientDetails(Context context, String groupId) { @@ -177,13 +178,13 @@ class RecipientProvider { title = context.getString(R.string.RecipientProvider_unnamed_group);; } - return new RecipientDetails(title, groupId, null, contactPhoto, null); + return new RecipientDetails(title, groupId, null, null, contactPhoto, null); } - return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null); + return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, null, ContactPhotoFactory.getDefaultGroupPhoto(), null); } catch (IOException e) { Log.w("RecipientProvider", e); - return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null); + return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), groupId, null, null, ContactPhotoFactory.getDefaultGroupPhoto(), null); } } @@ -209,19 +210,21 @@ class RecipientProvider { public static class RecipientDetails { @Nullable public final String name; @NonNull public final String number; + @Nullable public final String customLabel; @NonNull public final ContactPhoto avatar; @Nullable public final Uri contactUri; @Nullable public final MaterialColor color; public RecipientDetails(@Nullable String name, @NonNull String number, - @Nullable Uri contactUri, @NonNull ContactPhoto avatar, - @Nullable MaterialColor color) + @Nullable String customLabel, @Nullable Uri contactUri, + @NonNull ContactPhoto avatar, @Nullable MaterialColor color) { - this.name = name; - this.number = number; - this.avatar = avatar; - this.contactUri = contactUri; - this.color = color; + this.name = name; + this.customLabel = customLabel; + this.number = number; + this.avatar = avatar; + this.contactUri = contactUri; + this.color = color; } }