aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-02-08 18:39:24 -0800
committerScott Jackson <daneren2005@gmail.com>2014-02-08 18:39:24 -0800
commit12c277209fb81ba578d59551e1954ddca73cbaaa (patch)
tree43480a8cd81030e6526f8b56765d184faed34d21 /src/github/daneren2005
parent35a56bb221f67d4ae6cfef2eb0e689c00cded96b (diff)
downloaddsub-12c277209fb81ba578d59551e1954ddca73cbaaa.tar.gz
dsub-12c277209fb81ba578d59551e1954ddca73cbaaa.tar.bz2
dsub-12c277209fb81ba578d59551e1954ddca73cbaaa.zip
Add more information to download notification
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/service/DownloadFile.java2
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceImpl.java18
-rw-r--r--src/github/daneren2005/dsub/util/Util.java18
3 files changed, 32 insertions, 6 deletions
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,