diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2021-03-01 10:09:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 10:09:28 +0100 |
commit | c4f036c06c72682efa0b0ff8b511dbc33e090b91 (patch) | |
tree | d7f91fb0b78f591a14293d028f2aa51a83223c36 /core/src/main | |
parent | 47a0336c3e5cb4c370ad2612de3e8ba6605f6871 (diff) | |
parent | 8755a54e9945ec6b96009798e2f77e47aa6f0ee4 (diff) | |
download | AntennaPod-c4f036c06c72682efa0b0ff8b511dbc33e090b91.zip |
Merge pull request #4963 from a1291762/develop
Avoid the stuck download notification
Diffstat (limited to 'core/src/main')
3 files changed, 14 insertions, 16 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 4a17fbbda..44b673a4d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -172,8 +172,7 @@ public class DownloadService extends Service { setupNotificationUpdaterIfNecessary(); syncExecutor.execute(() -> onDownloadQueued(intent)); } else if (numberOfDownloads.get() == 0) { - stopForeground(true); - stopSelf(); + shutdown(); } else { Log.d(TAG, "onStartCommand: Unknown intent"); } @@ -227,10 +226,6 @@ public class DownloadService extends Service { } unregisterReceiver(cancelDownloadReceiver); - stopForeground(true); - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - nm.cancel(R.id.notification_downloading); - // if this was the initial gpodder sync, i.e. we just synced the feeds successfully, // it is now time to sync the episode actions SyncService.sync(this); @@ -550,14 +545,7 @@ public class DownloadService extends Service { if (numberOfDownloads.get() <= 0 && DownloadRequester.getInstance().hasNoDownloads()) { Log.d(TAG, "Attempting shutdown"); - stopForeground(true); - stopSelf(); - - // Trick to hide the notification more quickly when the service is stopped - // Without this, the second-last update of the notification stays for 3 seconds after onDestroy returns - notificationUpdater.run(); - NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - nm.cancel(R.id.notification_downloading); + shutdown(); } } @@ -647,4 +635,14 @@ public class DownloadService extends Service { new PostDownloaderTask(downloads), 1, 1, TimeUnit.SECONDS); } } + + private void shutdown() { + // If the service was run for a very short time, the system may delay closing + // the notification. Set the notification text now so that a misleading message + // is not left on the notification. + notificationUpdater.run(); + cancelNotificationUpdater(); + stopForeground(true); + stopSelf(); + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index 64ed85cf3..7c8fe9452 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -53,7 +53,7 @@ public class DownloadServiceNotification { String contentTitle = context.getString(R.string.download_notification_title); String downloadsLeft = (numDownloads > 0) ? context.getResources().getQuantityString(R.plurals.downloads_left, numDownloads, numDownloads) - : context.getString(R.string.downloads_processing); + : context.getString(R.string.service_shutting_down); String bigText = compileNotificationString(downloads); notificationCompatBuilder.setContentTitle(contentTitle); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index e9c1d8fcd..8e15d60d7 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -270,7 +270,7 @@ <item quantity="one">%d download left</item> <item quantity="other">%d downloads left</item> </plurals> - <string name="downloads_processing">Processing downloads</string> + <string name="service_shutting_down">Service shutting down</string> <string name="download_notification_title">Downloading podcast data</string> <plurals name="download_report_content"> <item quantity="one">%d download succeeded, %d failed</item> |