Display contact custom label instead of phone number

Fixes #6211
This commit is contained in:
Audric Ackermann 2017-02-20 16:48:55 +01:00 committed by Moxie Marlinspike
parent dc18f73594
commit 165fae5734
3 changed files with 30 additions and 16 deletions

View File

@ -67,7 +67,10 @@ public class ConversationTitleView extends LinearLayout {
this.subtitle.setVisibility(View.GONE); this.subtitle.setVisibility(View.GONE);
} else { } else {
this.title.setText(recipient.getName()); 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); this.subtitle.setVisibility(View.VISIBLE);
} }
} else { } else {

View File

@ -46,6 +46,7 @@ public class Recipient {
private @NonNull String number; private @NonNull String number;
private @Nullable String name; private @Nullable String name;
private @Nullable String customLabel;
private boolean stale; private boolean stale;
private boolean resolving; private boolean resolving;
@ -70,6 +71,7 @@ public class Recipient {
this.contactUri = stale.contactUri; this.contactUri = stale.contactUri;
this.contactPhoto = stale.contactPhoto; this.contactPhoto = stale.contactPhoto;
this.color = stale.color; this.color = stale.color;
this.customLabel = stale.customLabel;
} }
future.addListener(new FutureTaskListener<RecipientDetails>() { future.addListener(new FutureTaskListener<RecipientDetails>() {
@ -82,6 +84,7 @@ public class Recipient {
Recipient.this.contactUri = result.contactUri; Recipient.this.contactUri = result.contactUri;
Recipient.this.contactPhoto = result.avatar; Recipient.this.contactPhoto = result.avatar;
Recipient.this.color = result.color; Recipient.this.color = result.color;
Recipient.this.customLabel = result.customLabel;
Recipient.this.resolving = false; Recipient.this.resolving = false;
} }
@ -104,6 +107,7 @@ public class Recipient {
this.contactPhoto = details.avatar; this.contactPhoto = details.avatar;
this.color = details.color; this.color = details.color;
this.resolving = false; this.resolving = false;
this.customLabel = details.customLabel;
} }
public synchronized @Nullable Uri getContactUri() { public synchronized @Nullable Uri getContactUri() {
@ -132,6 +136,10 @@ public class Recipient {
return number; return number;
} }
public @Nullable String getCustomLabel() {
return customLabel;
}
public long getRecipientId() { public long getRecipientId() {
return recipientId; return recipientId;
} }
@ -157,7 +165,7 @@ public class Recipient {
} }
public static Recipient getUnknownRecipient() { 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)); ContactPhotoFactory.getDefaultContactPhoto(null), null));
} }

View File

@ -61,11 +61,12 @@ class RecipientProvider {
PhoneLookup.DISPLAY_NAME, PhoneLookup.DISPLAY_NAME,
PhoneLookup.LOOKUP_KEY, PhoneLookup.LOOKUP_KEY,
PhoneLookup._ID, PhoneLookup._ID,
PhoneLookup.NUMBER PhoneLookup.NUMBER,
PhoneLookup.LABEL
}; };
private static final Map<String, RecipientDetails> STATIC_DETAILS = new HashMap<String, RecipientDetails>() {{ private static final Map<String, RecipientDetails> STATIC_DETAILS = new HashMap<String, RecipientDetails>() {{
put("262966", new RecipientDetails("Amazon", "262966", null, put("262966", new RecipientDetails("Amazon", "262966", null, null,
ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_amazon), ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_amazon),
ContactColors.UNKNOWN_COLOR)); ContactColors.UNKNOWN_COLOR));
}}; }};
@ -150,7 +151,7 @@ class RecipientProvider {
Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""), Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""),
name); 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 { } else {
Log.w(TAG, "resultNumber is null"); Log.w(TAG, "resultNumber is null");
} }
@ -161,7 +162,7 @@ class RecipientProvider {
} }
if (STATIC_DETAILS.containsKey(number)) return STATIC_DETAILS.get(number); 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) { private @NonNull RecipientDetails getGroupRecipientDetails(Context context, String groupId) {
@ -177,13 +178,13 @@ class RecipientProvider {
title = context.getString(R.string.RecipientProvider_unnamed_group);; 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) { } catch (IOException e) {
Log.w("RecipientProvider", 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,15 +210,17 @@ class RecipientProvider {
public static class RecipientDetails { public static class RecipientDetails {
@Nullable public final String name; @Nullable public final String name;
@NonNull public final String number; @NonNull public final String number;
@Nullable public final String customLabel;
@NonNull public final ContactPhoto avatar; @NonNull public final ContactPhoto avatar;
@Nullable public final Uri contactUri; @Nullable public final Uri contactUri;
@Nullable public final MaterialColor color; @Nullable public final MaterialColor color;
public RecipientDetails(@Nullable String name, @NonNull String number, public RecipientDetails(@Nullable String name, @NonNull String number,
@Nullable Uri contactUri, @NonNull ContactPhoto avatar, @Nullable String customLabel, @Nullable Uri contactUri,
@Nullable MaterialColor color) @NonNull ContactPhoto avatar, @Nullable MaterialColor color)
{ {
this.name = name; this.name = name;
this.customLabel = customLabel;
this.number = number; this.number = number;
this.avatar = avatar; this.avatar = avatar;
this.contactUri = contactUri; this.contactUri = contactUri;