From 12c277209fb81ba578d59551e1954ddca73cbaaa Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 8 Feb 2014 18:39:24 -0800 Subject: Add more information to download notification --- src/github/daneren2005/dsub/service/DownloadFile.java | 2 +- .../daneren2005/dsub/service/DownloadServiceImpl.java | 18 ++++++++++++++++-- src/github/daneren2005/dsub/util/Util.java | 18 +++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java index fb5122ba..9ecfe0ad 100644 --- a/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/src/github/daneren2005/dsub/service/DownloadFile.java @@ -135,7 +135,7 @@ public class DownloadFile { } else if(song.getDuration() == null) { return 0; } else { - int br = getBitRate(); + int br = (getBitRate() * 1024) / 8; int duration = song.getDuration(); return br * duration; } diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index d67d53bf..19e7625c 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -121,6 +121,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { private int cachedPosition = 0; private long downloadRevision; private boolean downloadOngoing = false; + private DownloadFile lastDownloaded = null; private static boolean equalizerAvailable; private static boolean visualizerAvailable; @@ -1526,13 +1527,26 @@ public class DownloadServiceImpl extends Service implements DownloadService { } } - if(!backgroundDownloadList.isEmpty() && downloadRevision != revision) { - Util.showDownloadingNotification(this, currentDownloading, backgroundDownloadList.size()); + if(!backgroundDownloadList.isEmpty()) { + DownloadFile speedFile = null; + // Updating existing notification + if(downloadOngoing) { + // Changing download, use speed of last DownloadFile + if(revision != downloadRevision && lastDownloaded != null) { + speedFile = lastDownloaded; + } else { + // Updated mid-download + speedFile = currentDownloading; + } + } + Util.showDownloadingNotification(this, currentDownloading, backgroundDownloadList.size(), speedFile); downloadRevision = revision; + lastDownloaded = currentDownloading; downloadOngoing = true; } else if(backgroundDownloadList.isEmpty() && downloadOngoing) { Util.hideDownloadingNotification(this); downloadOngoing = false; + lastDownloaded = null; } // Delete obsolete .partial and .complete files. diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index 5b79e2f2..e2f2d02f 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -1108,12 +1108,24 @@ public final class Util { DSubWidgetProvider.notifyInstances(context, downloadService, false); } - public static void showDownloadingNotification(final Context context, DownloadFile file, int size) { + public static void showDownloadingNotification(final Context context, DownloadFile file, int size, DownloadFile speedFile) { Intent cancelIntent = new Intent(context, DownloadServiceImpl.class); cancelIntent.setAction(DownloadServiceImpl.CANCEL_DOWNLOADS); PendingIntent cancelPI = PendingIntent.getService(context, 0, cancelIntent, 0); - String currentDownloading = (file != null) ? file.getSong().getTitle() : "none"; + String currentDownloading, currentSize, speed; + if(file != null) { + currentDownloading = file.getSong().getTitle(); + currentSize = Util.formatBytes(file.getEstimatedSize()); + } else { + currentDownloading = "none"; + currentSize = "0"; + } + if(speedFile != null) { + speed = Long.toString(speedFile.getBytesPerSecond() / 1024); + } else { + speed = "0"; + } NotificationCompat.Builder builder; builder = new NotificationCompat.Builder(context) @@ -1121,7 +1133,7 @@ public final class Util { .setContentTitle(context.getResources().getString(R.string.download_downloading_title, size)) .setContentText(context.getResources().getString(R.string.download_downloading_summary, currentDownloading)) .setStyle(new NotificationCompat.BigTextStyle() - .bigText(context.getResources().getString(R.string.download_downloading_summary, currentDownloading))) + .bigText(context.getResources().getString(R.string.download_downloading_summary_expanded, currentDownloading, currentSize, speed))) .setProgress(10, 5, true) .setOngoing(true) .addAction(R.drawable.notification_close, -- cgit v1.2.3