From a149ce54dbed8110736f660e1a8e283373030308 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Fri, 22 Apr 2016 23:13:36 +1000 Subject: [PATCH] Always stop notifications at the conclusion of a download. Without this, if the first download in the queue is downloaded, the notification will persist with details of that first download until the next download begins. With this change, the notification is remoived immediately after cancelling the download. --- .../fdroid/fdroid/net/DownloaderService.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java index dd21c623d..2b951b892 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -146,10 +146,6 @@ public class DownloaderService extends Service { stopForeground(true); } } else if (ACTION_QUEUE.equals(intent.getAction())) { - if (Preferences.get().isUpdateNotificationEnabled()) { - Notification notification = createNotification(intent.getDataString(), getPackageNameFromIntent(intent)).build(); - startForeground(NOTIFY_DOWNLOADING, notification); - } Log.i(TAG, "Queued " + intent); Message msg = serviceHandler.obtainMessage(); msg.arg1 = startId; @@ -261,6 +257,12 @@ public class DownloaderService extends Service { final SanitizedFile localFile = new SanitizedFile(downloadDir, uri.getLastPathSegment()); final String packageName = getPackageNameFromIntent(intent); sendBroadcast(uri, Downloader.ACTION_STARTED, localFile); + + if (Preferences.get().isUpdateNotificationEnabled()) { + Notification notification = createNotification(intent.getDataString(), getPackageNameFromIntent(intent)).build(); + startForeground(NOTIFY_DOWNLOADING, notification); + } + try { downloader = DownloaderFactory.create(this, uri, localFile); downloader.setListener(new Downloader.DownloaderProgressListener() { @@ -273,11 +275,13 @@ public class DownloaderService extends Service { intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes); localBroadcastManager.sendBroadcast(intent); - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - Notification notification = createNotification(uri.toString(), packageName) - .setProgress(totalBytes, bytesRead, false) - .build(); - nm.notify(NOTIFY_DOWNLOADING, notification); + if (Preferences.get().isUpdateNotificationEnabled()) { + NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + Notification notification = createNotification(uri.toString(), packageName) + .setProgress(totalBytes, bytesRead, false) + .build(); + nm.notify(NOTIFY_DOWNLOADING, notification); + } } } }); @@ -297,6 +301,7 @@ public class DownloaderService extends Service { // May have already been removed in response to a cancel intent, but that wont cause // problems if we ask to remove it again. QUEUE_WHATS.remove(uri.toString()); + stopForeground(true); } downloader = null; }