diff options
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadFile.java | 2 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 18 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/Util.java | 18 |
4 files changed, 35 insertions, 6 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index f1f4a1ca..7abcbd28 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -193,6 +193,9 @@ <string name="download.save_bookmark">Bookmark created</string>
<string name="download.downloading_title">Downloading %1$d songs</string>
<string name="download.downloading_summary">Current: %1$s</string>
+ <string name="download.downloading_summary_expanded">Current: %1$s
+ \nEstimated Size: %2$s
+ \nAverage Speed: %3$s kbps</string>
<string name="sync.title">DSub: New media is available</string>
<string name="sync.new_podcasts">New podcasts: %s</string>
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, |