diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-10-24 22:41:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-10-24 22:41:00 +0000 |
commit | daa1c44c00f3c598223639c9b80a52cf41db51ba (patch) | |
tree | e4c88a1862b157dc858abe73e52b077bf7b96948 /java/com/android/dialer/voicemail/listui/VoicemailEntryText.java | |
parent | ef7338cf787301c573fde8129bf8880d7faba040 (diff) | |
parent | 938468da6f5c225ebb161a68bd949c9cf3261892 (diff) |
Merge "Rename the new bubble package name from "bubble" to "newbubble"."
Diffstat (limited to 'java/com/android/dialer/voicemail/listui/VoicemailEntryText.java')
-rw-r--r-- | java/com/android/dialer/voicemail/listui/VoicemailEntryText.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java b/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java index cf2fef253..f59220105 100644 --- a/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java +++ b/java/com/android/dialer/voicemail/listui/VoicemailEntryText.java @@ -18,7 +18,11 @@ package com.android.dialer.voicemail.listui; import android.content.Context; import android.text.TextUtils; +import com.android.dialer.calllogutils.CallLogDates; +import com.android.dialer.common.LogUtil; +import com.android.dialer.time.Clock; import com.android.dialer.voicemail.model.VoicemailEntry; +import java.util.concurrent.TimeUnit; /** * Computes the primary text for voicemail entries. @@ -39,4 +43,66 @@ public class VoicemailEntryText { } return primaryText.toString(); } + + /** + * Uses the new date and location formatting rules to format the location and date in the new + * voicemail tab. + * + * <p>Rules: $Location • Date + * + * <p>Examples: + * + * <p>Jun 20 San Francisco • Now + * + * <p>Markham, ON • Jul 27 + * + * <p>Toledo, OH • 12:15 PM + * + * <p>Date rules: if < 1 minute ago: "Now"; else if today: HH:MM(am|pm); else if < 3 days: day; + * else: MON D * + * + * @return $Location • Date + */ + public static String buildSecondaryVoicemailText( + Context context, Clock clock, VoicemailEntry voicemailEntry) { + return secondaryTextPrefix(context, clock, voicemailEntry); + } + + private static String secondaryTextPrefix( + Context context, Clock clock, VoicemailEntry voicemailEntry) { + StringBuilder secondaryText = new StringBuilder(); + String location = voicemailEntry.geocodedLocation(); + if (!TextUtils.isEmpty(location)) { + secondaryText.append(location); + } + if (secondaryText.length() > 0) { + secondaryText.append(" • "); + } + secondaryText.append( + CallLogDates.newCallLogTimestampLabel( + context, clock.currentTimeMillis(), voicemailEntry.timestamp())); + + long duration = voicemailEntry.duration(); + if (duration >= 0) { + secondaryText.append(" • "); + String formattedDuration = getVoicemailDuration(context, voicemailEntry); + secondaryText.append(formattedDuration); + } + return secondaryText.toString(); + } + + private static String getVoicemailDuration(Context context, VoicemailEntry voicemailEntry) { + long minutes = TimeUnit.SECONDS.toMinutes(voicemailEntry.duration()); + long seconds = voicemailEntry.duration() - TimeUnit.MINUTES.toSeconds(minutes); + + // The format for duration is "MM:SS" and we never expect the duration to be > 5 minutes + // However an incorrect duration could be set by the framework/someone to be >99, and in that + // case cap it at 99, for the UI to still be able to display it in "MM:SS" format. + if (minutes > 99) { + LogUtil.w( + "VoicemailEntryText.getVoicemailDuration", "Duration was %d", voicemailEntry.duration()); + minutes = 99; + } + return context.getString(R.string.voicemailDurationFormat, minutes, seconds); + } } |