diff options
Diffstat (limited to 'java/com/android/dialer/calllogutils/CallLogEntryText.java')
-rw-r--r-- | java/com/android/dialer/calllogutils/CallLogEntryText.java | 34 |
1 files changed, 26 insertions, 8 deletions
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<String> 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<String> 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); |