Add own formatDuration() method
DateUtils.formatDuration() is not public, so create our own version.
This commit is contained in:
@@ -88,4 +88,17 @@
|
|||||||
<string name="apply_update_dialog_title">Apply update</string>
|
<string name="apply_update_dialog_title">Apply update</string>
|
||||||
<string name="apply_update_dialog_message">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, 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.</string>
|
<string name="apply_update_dialog_message">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, 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.</string>
|
||||||
<string name="apply_update_dialog_message_ab">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot.</string>
|
<string name="apply_update_dialog_message_ab">You are about to upgrade to <xliff:g id="update_name">%1$s</xliff:g>.\n\nIf you press <xliff:g id="ok">%2$s</xliff:g>, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot.</string>
|
||||||
|
|
||||||
|
<plurals name="duration_seconds">
|
||||||
|
<item quantity="one">1 second</item>
|
||||||
|
<item quantity="other"><xliff:g id="count">%d</xliff:g> seconds</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="duration_minutes">
|
||||||
|
<item quantity="one">1 minute</item>
|
||||||
|
<item quantity="other"><xliff:g id="count">%d</xliff:g> minutes</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="duration_hours">
|
||||||
|
<item quantity="one">1 hour</item>
|
||||||
|
<item quantity="other"><xliff:g id="count">%d</xliff:g> hours</item>
|
||||||
|
</plurals>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -20,7 +20,6 @@ import android.content.DialogInterface;
|
|||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@@ -130,7 +129,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
String total = Formatter.formatShortFileSize(mContext, update.getFileSize());
|
String total = Formatter.formatShortFileSize(mContext, update.getFileSize());
|
||||||
long eta = update.getEta();
|
long eta = update.getEta();
|
||||||
if (eta > 0) {
|
if (eta > 0) {
|
||||||
CharSequence etaString = DateUtils.formatDuration(eta * 1000);
|
CharSequence etaString = StringGenerator.formatDuration(mContext, eta * 1000);
|
||||||
viewHolder.mProgressText.setText(mContext.getString(
|
viewHolder.mProgressText.setText(mContext.getString(
|
||||||
R.string.list_download_progress_eta, downloaded, total, etaString));
|
R.string.list_download_progress_eta, downloaded, total, etaString));
|
||||||
} else {
|
} else {
|
||||||
|
@@ -27,7 +27,6 @@ import android.os.Bundle;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.app.NotificationCompat;
|
import android.support.v7.app.NotificationCompat;
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -337,7 +336,7 @@ public class UpdaterService extends Service {
|
|||||||
setNotificationTitle(update);
|
setNotificationTitle(update);
|
||||||
|
|
||||||
String speed = Formatter.formatFileSize(this, update.getSpeed());
|
String speed = Formatter.formatFileSize(this, update.getSpeed());
|
||||||
CharSequence eta = DateUtils.formatDuration(update.getEta() * 1000);
|
CharSequence eta = StringGenerator.formatDuration(this, update.getEta() * 1000);
|
||||||
mNotificationStyle.bigText(
|
mNotificationStyle.bigText(
|
||||||
getString(R.string.text_download_speed, eta, speed));
|
getString(R.string.text_download_speed, eta, speed));
|
||||||
|
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
package org.lineageos.updater.misc;
|
package org.lineageos.updater.misc;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import org.lineageos.updater.R;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -64,6 +67,23 @@ public final class StringGenerator {
|
|||||||
return String.format(getCurrentLocale(context), "%.0f", bytes / 1024.f / 1024.f);
|
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) {
|
public static Locale getCurrentLocale(Context context) {
|
||||||
return context.getResources().getConfiguration().getLocales()
|
return context.getResources().getConfiguration().getLocales()
|
||||||
.getFirstMatch(context.getResources().getAssets().getLocales());
|
.getFirstMatch(context.getResources().getAssets().getLocales());
|
||||||
|
Reference in New Issue
Block a user