From 03b13198537df025febb842db7f95794a1faad8f Mon Sep 17 00:00:00 2001 From: zachh Date: Fri, 26 Jan 2018 10:56:46 -0800 Subject: Added number presentation to AnnotatedCallLog. Updated the new call log UI to properly show text based on the presentation. Bug: 70989592 Test: unit PiperOrigin-RevId: 183414195 Change-Id: I2123f37cd3c733060125b6e894c1a80be4193ad6 --- .../dialer/calllogutils/CallLogEntryText.java | 34 +++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'java/com/android/dialer/calllogutils/CallLogEntryText.java') diff --git a/java/com/android/dialer/calllogutils/CallLogEntryText.java b/java/com/android/dialer/calllogutils/CallLogEntryText.java index aa45a697a..49f5e42ca 100644 --- a/java/com/android/dialer/calllogutils/CallLogEntryText.java +++ b/java/com/android/dialer/calllogutils/CallLogEntryText.java @@ -21,6 +21,7 @@ import android.provider.CallLog.Calls; import android.text.TextUtils; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.time.Clock; +import com.google.common.base.Optional; import com.google.common.collect.Collections2; import java.util.ArrayList; import java.util.List; @@ -40,16 +41,25 @@ public final class CallLogEntryText { * following the primary text.) */ public static CharSequence buildPrimaryText(Context context, CoalescedRow row) { - StringBuilder primaryText = new StringBuilder(); + // Always prefer the presentation name, like "Restricted". + Optional presentationName = + PhoneNumberDisplayUtil.getNameForPresentation(context, row.numberPresentation()); + if (presentationName.isPresent()) { + return presentationName.get(); + } + + // Otherwise prefer the name. if (!TextUtils.isEmpty(row.numberAttributes().getName())) { - primaryText.append(row.numberAttributes().getName()); - } else if (!TextUtils.isEmpty(row.formattedNumber())) { - primaryText.append(row.formattedNumber()); - } else { - // TODO(zachh): Handle CallLog.Calls.PRESENTATION_*, including Verizon restricted numbers. - primaryText.append(context.getText(R.string.new_call_log_unknown)); + return row.numberAttributes().getName(); + } + + // Otherwise prefer the formatted number. + if (!TextUtils.isEmpty(row.formattedNumber())) { + return row.formattedNumber(); } - return primaryText.toString(); + + // If there's no formatted number, just return "Unknown". + return context.getText(R.string.new_call_log_unknown); } /** @@ -112,6 +122,14 @@ public final class CallLogEntryText { components.add(getNumberTypeLabel(context, row)); + // If there's a presentation name, we showed it in the primary text and shouldn't show any name + // or number here. + Optional presentationName = + PhoneNumberDisplayUtil.getNameForPresentation(context, row.numberPresentation()); + if (presentationName.isPresent()) { + return joinSecondaryTextComponents(components); + } + if (TextUtils.isEmpty(row.numberAttributes().getName())) { // If the name is empty the number is shown as the primary text and there's nothing to add. return joinSecondaryTextComponents(components); -- cgit v1.2.3