diff options
Diffstat (limited to 'java/com/android/dialer/speeddial/loader')
-rw-r--r-- | java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java | 16 | ||||
-rw-r--r-- | java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java | 6 |
2 files changed, 17 insertions, 5 deletions
diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java index f730d12a0..365b88f8c 100644 --- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java +++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java @@ -16,6 +16,7 @@ package com.android.dialer.speeddial.loader; +import android.content.res.Resources; import android.database.Cursor; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; @@ -102,7 +103,7 @@ public abstract class SpeedDialUiItem { * <p>If the cursor started at row X, this method will advance to row Y s.t. rows X, X + 1, ... Y * - 1 all belong to the same contact (that is, share the same contact id and lookup key). */ - public static SpeedDialUiItem fromCursor(Cursor cursor) { + public static SpeedDialUiItem fromCursor(Resources resources, Cursor cursor) { Assert.checkArgument(cursor != null); Assert.checkArgument(cursor.getCount() != 0); String lookupKey = cursor.getString(LOOKUP_KEY); @@ -125,7 +126,7 @@ public abstract class SpeedDialUiItem { Channel.builder() .setNumber(cursor.getString(NUMBER)) .setPhoneType(cursor.getInt(TYPE)) - .setLabel(TextUtils.isEmpty(cursor.getString(LABEL)) ? "" : cursor.getString(LABEL)) + .setLabel(getLabel(resources, cursor)) .setTechnology(Channel.VOICE) .build(); channels.add(channel); @@ -141,6 +142,17 @@ public abstract class SpeedDialUiItem { return builder.build(); } + private static String getLabel(Resources resources, Cursor cursor) { + int numberType = cursor.getInt(TYPE); + String numberLabel = cursor.getString(LABEL); + + // Returns empty label instead of "custom" if the custom label is empty. + if (numberType == Phone.TYPE_CUSTOM && TextUtils.isEmpty(numberLabel)) { + return ""; + } + return (String) Phone.getTypeLabel(resources, numberType, numberLabel); + } + public PhotoInfo getPhotoInfo() { return PhotoInfo.newBuilder() .setPhotoId(photoId()) diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java index 0a2a241b3..1ad37dc2a 100644 --- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java +++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java @@ -205,7 +205,7 @@ public final class SpeedDialUiItemMutator { return loadSpeedDialUiItemsInternal(); } Assert.checkArgument(cursor.moveToFirst(), "Cursor should never be empty"); - SpeedDialUiItem item = SpeedDialUiItem.fromCursor(cursor); + SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor); // Star the contact if it isn't starred already, then return. if (!item.isStarred()) { @@ -410,7 +410,7 @@ public final class SpeedDialUiItemMutator { null)) { Map<SpeedDialEntry, SpeedDialUiItem> map = new ArrayMap<>(); for (cursor.moveToFirst(); !cursor.isAfterLast(); /* Iterate in the loop */ ) { - SpeedDialUiItem item = SpeedDialUiItem.fromCursor(cursor); + SpeedDialUiItem item = SpeedDialUiItem.fromCursor(appContext.getResources(), cursor); for (SpeedDialEntry entry : entries) { if (entry.contactId() == item.contactId()) { // Update the id and pinned position to match it's corresponding SpeedDialEntry. @@ -513,7 +513,7 @@ public final class SpeedDialUiItemMutator { return contacts; } for (cursor.moveToFirst(); !cursor.isAfterLast(); /* Iterate in the loop */ ) { - contacts.add(SpeedDialUiItem.fromCursor(cursor)); + contacts.add(SpeedDialUiItem.fromCursor(appContext.getResources(), cursor)); } return contacts; } |