diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3516ad6..2c9aebc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -88,4 +88,17 @@
Apply update
You are about to upgrade to %1$s.\n\nIf you press %2$s, the device will restart itself in recovery mode to install the update.\n\nNote: This feature requires a compatible Recovery or updates will need to be installed manually.
You are about to upgrade to %1$s.\n\nIf you press %2$s, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot.
+
+
+ - 1 second
+ - %d seconds
+
+
+ - 1 minute
+ - %d minutes
+
+
+ - 1 hour
+ - %d hours
+
diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java
index f7f756d..9a98784 100644
--- a/src/org/lineageos/updater/UpdatesListAdapter.java
+++ b/src/org/lineageos/updater/UpdatesListAdapter.java
@@ -20,7 +20,6 @@ import android.content.DialogInterface;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
-import android.text.format.DateUtils;
import android.text.format.Formatter;
import android.util.Log;
import android.util.TypedValue;
@@ -130,7 +129,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter 0) {
- CharSequence etaString = DateUtils.formatDuration(eta * 1000);
+ CharSequence etaString = StringGenerator.formatDuration(mContext, eta * 1000);
viewHolder.mProgressText.setText(mContext.getString(
R.string.list_download_progress_eta, downloaded, total, etaString));
} else {
diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java
index 9c50aed..f6eea33 100644
--- a/src/org/lineageos/updater/controller/UpdaterService.java
+++ b/src/org/lineageos/updater/controller/UpdaterService.java
@@ -27,7 +27,6 @@ import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
-import android.text.format.DateUtils;
import android.text.format.Formatter;
import android.util.Log;
@@ -337,7 +336,7 @@ public class UpdaterService extends Service {
setNotificationTitle(update);
String speed = Formatter.formatFileSize(this, update.getSpeed());
- CharSequence eta = DateUtils.formatDuration(update.getEta() * 1000);
+ CharSequence eta = StringGenerator.formatDuration(this, update.getEta() * 1000);
mNotificationStyle.bigText(
getString(R.string.text_download_speed, eta, speed));
diff --git a/src/org/lineageos/updater/misc/StringGenerator.java b/src/org/lineageos/updater/misc/StringGenerator.java
index a29f30c..712738a 100644
--- a/src/org/lineageos/updater/misc/StringGenerator.java
+++ b/src/org/lineageos/updater/misc/StringGenerator.java
@@ -16,6 +16,9 @@
package org.lineageos.updater.misc;
import android.content.Context;
+import android.content.res.Resources;
+
+import org.lineageos.updater.R;
import java.text.DateFormat;
import java.util.Date;
@@ -64,6 +67,23 @@ public final class StringGenerator {
return String.format(getCurrentLocale(context), "%.0f", bytes / 1024.f / 1024.f);
}
+ public static String formatDuration(Context context, long millis) {
+ final long SECOND_IN_MILLIS = 1000;
+ final long MINUTE_IN_MILLIS = SECOND_IN_MILLIS * 60;
+ final long HOUR_IN_MILLIS = MINUTE_IN_MILLIS * 60;
+ Resources res = context.getResources();
+ if (millis >= HOUR_IN_MILLIS) {
+ final int hours = (int) ((millis + 1800000) / HOUR_IN_MILLIS);
+ return res.getQuantityString(R.plurals.duration_hours, hours, hours);
+ } else if (millis >= MINUTE_IN_MILLIS) {
+ final int minutes = (int) ((millis + 30000) / MINUTE_IN_MILLIS);
+ return res.getQuantityString(R.plurals.duration_minutes, minutes, minutes);
+ } else {
+ final int seconds = (int) ((millis + 500) / SECOND_IN_MILLIS);
+ return res.getQuantityString(R.plurals.duration_seconds, seconds, seconds);
+ }
+ }
+
public static Locale getCurrentLocale(Context context) {
return context.getResources().getConfiguration().getLocales()
.getFirstMatch(context.getResources().getAssets().getLocales());