diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-09-22 18:04:50 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-09-22 18:04:50 +0000 |
commit | 07b9b300ffea967ef7a483e872418c7480f3b600 (patch) | |
tree | 63c324d398ddcf1a5063d0f8141c2d53c9ef36c0 | |
parent | 6ffaa6d5c0284c73f49b82ba7b4422f5c375e890 (diff) | |
parent | aaa5e15697535032a842d1a8c976b4a831b4f415 (diff) |
Merge "Fixed call duration bug."
-rw-r--r-- | java/com/android/dialer/calllogutils/CallLogDurations.java | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/java/com/android/dialer/calllogutils/CallLogDurations.java b/java/com/android/dialer/calllogutils/CallLogDurations.java index 20998deb4..9ed8a93fe 100644 --- a/java/com/android/dialer/calllogutils/CallLogDurations.java +++ b/java/com/android/dialer/calllogutils/CallLogDurations.java @@ -20,9 +20,7 @@ import android.content.Context; import android.content.res.Resources; import android.text.format.Formatter; import com.android.dialer.util.DialerUtils; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; @@ -30,6 +28,10 @@ import java.util.concurrent.TimeUnit; public class CallLogDurations { private static CharSequence formatDuration(Context context, long elapsedSeconds) { + // Getting this method into a good state took a bunch of work between eng, i18n team and + // translators. If at all possible, the strings should not be changed or updated. + long minutes = TimeUnit.SECONDS.toMinutes(elapsedSeconds); + long seconds = elapsedSeconds - TimeUnit.MINUTES.toSeconds(minutes); Resources res = context.getResources(); String formatPattern; if (elapsedSeconds >= 60) { @@ -38,35 +40,22 @@ public class CallLogDurations { // example output: "1m 1s" formatPattern = context.getString( - R.string.call_duration_format_pattern, "m", minutesString, "s", secondsString); + R.string.call_duration_format_pattern, + Long.toString(minutes), + minutesString, + Long.toString(seconds), + secondsString); } else { String secondsString = res.getString(R.string.call_details_seconds_abbreviation); // example output: "1s" formatPattern = - context.getString(R.string.call_duration_short_format_pattern, "s", secondsString); - - // Temporary work around for a broken Hebrew(iw) translation. - if (formatPattern.endsWith("\'\'")) { - formatPattern = formatPattern.substring(0, formatPattern.length() - 1); - } + context.getString( + R.string.call_duration_short_format_pattern, Long.toString(seconds), secondsString); } - // If new translation issues arise, we should catch them here to prevent crashes. - try { - Date date = new Date(TimeUnit.SECONDS.toMillis(elapsedSeconds)); - SimpleDateFormat format = new SimpleDateFormat(formatPattern); - String duration = format.format(date); - - // SimpleDateFormat cannot display more than 59 minutes, instead it displays MINUTES % 60. - // Here we check for that value and replace it with the correct value. - if (elapsedSeconds >= TimeUnit.MINUTES.toSeconds(60)) { - int minutes = (int) (elapsedSeconds / 60); - duration = duration.replaceFirst(Integer.toString(minutes % 60), Integer.toString(minutes)); - } - return duration; - } catch (Exception e) { - return ""; - } + // Since we don't want to update the strings.xml, we need to remove the quotations from the + // previous implementation. + return formatPattern.replace("\'", ""); } private static CharSequence formatDurationA11y(Context context, long elapsedSeconds) { |