summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/calllogutils
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2017-09-21 17:29:28 -0700
committerEric Erfanian <erfanian@google.com>2017-09-22 16:02:27 +0000
commitaaa5e15697535032a842d1a8c976b4a831b4f415 (patch)
tree63c324d398ddcf1a5063d0f8141c2d53c9ef36c0 /java/com/android/dialer/calllogutils
parent7b28abc0f919395a971f48d8add255e1a0303ec2 (diff)
Fixed call duration bug.
SimpleDateFormatter just wasn't working. This CL simplifies this method to something similar to what we had before the call details rewrite. To avoid going through the trouble of having the strings retranslated through the i18n coordinator, I've left them as is and worked around it. screenshots: before: http://screen/eJqs5EijCYe after: http://screen/AbrLFn0caL0 Bug: 63370483 Test: existing PiperOrigin-RevId: 169626011 Change-Id: I160529e276db2fc098a29b005db104e7ac601f15
Diffstat (limited to 'java/com/android/dialer/calllogutils')
-rw-r--r--java/com/android/dialer/calllogutils/CallLogDurations.java39
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) {