diff options
author | calderwoodra <calderwoodra@google.com> | 2017-09-22 18:12:41 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-09-22 18:12:41 +0000 |
commit | 97533ee1d712878624211db84958f9688d90fe8e (patch) | |
tree | 541354ae99b46b88766a9df7a34d9bc8b2563907 | |
parent | 217080f9e983f88bda207b269b9c9204fe55fc7c (diff) | |
parent | 07b9b300ffea967ef7a483e872418c7480f3b600 (diff) |
Merge "Fixed call duration bug."
am: 07b9b300ff
Change-Id: I8c7038f2df31b954d61c28e238f086f616105b6d
-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) { |