From 8657ebdaa1e4550008078161b0dcd7ffc340497b Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Tue, 1 May 2018 11:54:13 -0700 Subject: Fixed labels for speed dial UI. Bug: 78922118 Test: tap + manual PiperOrigin-RevId: 194971448 Change-Id: I906250cb83c17198fac87f5ad6d3014cc8a34db2 --- .../android/dialer/speeddial/FavoritesViewHolder.java | 13 +++++++++---- .../android/dialer/speeddial/loader/SpeedDialUiItem.java | 16 ++++++++++++++-- .../dialer/speeddial/loader/SpeedDialUiItemMutator.java | 6 +++--- 3 files changed, 26 insertions(+), 9 deletions(-) (limited to 'java/com/android/dialer/speeddial') diff --git a/java/com/android/dialer/speeddial/FavoritesViewHolder.java b/java/com/android/dialer/speeddial/FavoritesViewHolder.java index 474516ef2..f06672d8d 100644 --- a/java/com/android/dialer/speeddial/FavoritesViewHolder.java +++ b/java/com/android/dialer/speeddial/FavoritesViewHolder.java @@ -68,10 +68,15 @@ public class FavoritesViewHolder extends RecyclerView.ViewHolder Assert.checkArgument(speedDialUiItem.isStarred()); nameView.setText(speedDialUiItem.name()); - if (speedDialUiItem.defaultChannel() != null) { - phoneType.setText(speedDialUiItem.defaultChannel().label()); - videoCallIcon.setVisibility( - speedDialUiItem.defaultChannel().isVideoTechnology() ? View.VISIBLE : View.GONE); + + Channel channel = speedDialUiItem.defaultChannel(); + if (channel == null) { + channel = speedDialUiItem.getDefaultVoiceChannel(); + } + + if (channel != null) { + phoneType.setText(channel.label()); + videoCallIcon.setVisibility(channel.isVideoTechnology() ? View.VISIBLE : View.GONE); } else { phoneType.setText(""); videoCallIcon.setVisibility(View.GONE); diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java index 325af238a..731c8c641 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 { *

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 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; } -- cgit v1.2.3