Merge pull request #4963 from a1291762/develop
Avoid the stuck download notification
This commit is contained in:
commit
c4f036c06c
@ -172,8 +172,7 @@ public class DownloadService extends Service {
|
|||||||
setupNotificationUpdaterIfNecessary();
|
setupNotificationUpdaterIfNecessary();
|
||||||
syncExecutor.execute(() -> onDownloadQueued(intent));
|
syncExecutor.execute(() -> onDownloadQueued(intent));
|
||||||
} else if (numberOfDownloads.get() == 0) {
|
} else if (numberOfDownloads.get() == 0) {
|
||||||
stopForeground(true);
|
shutdown();
|
||||||
stopSelf();
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "onStartCommand: Unknown intent");
|
Log.d(TAG, "onStartCommand: Unknown intent");
|
||||||
}
|
}
|
||||||
@ -227,10 +226,6 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
unregisterReceiver(cancelDownloadReceiver);
|
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,
|
// if this was the initial gpodder sync, i.e. we just synced the feeds successfully,
|
||||||
// it is now time to sync the episode actions
|
// it is now time to sync the episode actions
|
||||||
SyncService.sync(this);
|
SyncService.sync(this);
|
||||||
@ -550,14 +545,7 @@ public class DownloadService extends Service {
|
|||||||
|
|
||||||
if (numberOfDownloads.get() <= 0 && DownloadRequester.getInstance().hasNoDownloads()) {
|
if (numberOfDownloads.get() <= 0 && DownloadRequester.getInstance().hasNoDownloads()) {
|
||||||
Log.d(TAG, "Attempting shutdown");
|
Log.d(TAG, "Attempting shutdown");
|
||||||
stopForeground(true);
|
shutdown();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,4 +635,14 @@ public class DownloadService extends Service {
|
|||||||
new PostDownloaderTask(downloads), 1, 1, TimeUnit.SECONDS);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class DownloadServiceNotification {
|
|||||||
String contentTitle = context.getString(R.string.download_notification_title);
|
String contentTitle = context.getString(R.string.download_notification_title);
|
||||||
String downloadsLeft = (numDownloads > 0)
|
String downloadsLeft = (numDownloads > 0)
|
||||||
? context.getResources().getQuantityString(R.plurals.downloads_left, numDownloads, numDownloads)
|
? 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);
|
String bigText = compileNotificationString(downloads);
|
||||||
|
|
||||||
notificationCompatBuilder.setContentTitle(contentTitle);
|
notificationCompatBuilder.setContentTitle(contentTitle);
|
||||||
|
@ -270,7 +270,7 @@
|
|||||||
<item quantity="one">%d download left</item>
|
<item quantity="one">%d download left</item>
|
||||||
<item quantity="other">%d downloads left</item>
|
<item quantity="other">%d downloads left</item>
|
||||||
</plurals>
|
</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>
|
<string name="download_notification_title">Downloading podcast data</string>
|
||||||
<plurals name="download_report_content">
|
<plurals name="download_report_content">
|
||||||
<item quantity="one">%d download succeeded, %d failed</item>
|
<item quantity="one">%d download succeeded, %d failed</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user