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);
} 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 {

View file

@ -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<RecipientDetails>() {
@ -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));
}

View file

@ -61,11 +61,12 @@ class RecipientProvider {
PhoneLookup.DISPLAY_NAME,
PhoneLookup.LOOKUP_KEY,
PhoneLookup._ID,
PhoneLookup.NUMBER
PhoneLookup.NUMBER,
PhoneLookup.LABEL
};
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),
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;
}
}