summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2023-02-25 16:30:58 +0100
committerGitHub <noreply@github.com>2023-02-25 16:30:58 +0100
commit3e077e5653d1c1be266d2bb5add85902c93e616e (patch)
tree72035f4808f39f390c153fa4755f67fb91a4d0f5 /core
parent34553475d9a28f7eba1b0570370ab3370ce87fc0 (diff)
downloadAntennaPod-3e077e5653d1c1be266d2bb5add85902c93e616e.zip
Add cancel action to download notification (#6353)
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java42
1 files changed, 33 insertions, 9 deletions
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 6ba8348d6..b9846c06c 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
@@ -39,9 +39,8 @@ public class DownloadServiceNotification {
.setOnlyAlertOnce(true)
.setShowWhen(false)
.setContentIntent(getNotificationContentIntent(context))
- .setSmallIcon(R.drawable.ic_notification_sync);
- notificationCompatBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
-
+ .setSmallIcon(R.drawable.ic_notification_sync)
+ .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
Log.d(TAG, "Notification set up");
}
@@ -62,12 +61,27 @@ public class DownloadServiceNotification {
} else {
contentTitle = context.getString(R.string.download_notification_title);
}
- String contentText = (downloads.size() > 0)
- ? context.getResources().getQuantityString(R.plurals.downloads_left, downloads.size(), downloads.size())
- : context.getString(R.string.completing);
- String bigText = compileNotificationString(downloads);
- if (!bigText.contains("\n")) {
- contentText = bigText;
+
+ int numDownloads = getNumberOfRunningDownloads(downloads);
+ String contentText = context.getString(R.string.completing);
+ String bigText = context.getString(R.string.completing);
+ notificationCompatBuilder.clearActions();
+ if (numDownloads > 0) {
+ bigText = compileNotificationString(downloads);
+ if (numDownloads == 1) {
+ contentText = bigText;
+ } else {
+ contentText = context.getResources().getQuantityString(R.plurals.downloads_left,
+ numDownloads, numDownloads);
+ }
+
+ Intent cancelDownloadsIntent = new Intent(DownloadService.ACTION_CANCEL_ALL_DOWNLOADS);
+ cancelDownloadsIntent.setPackage(context.getPackageName());
+ PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(context,
+ R.id.pending_intent_download_cancel_all, cancelDownloadsIntent, PendingIntent.FLAG_UPDATE_CURRENT
+ | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
+ notificationCompatBuilder.addAction(new NotificationCompat.Action(
+ R.drawable.ic_notification_cancel, context.getString(R.string.cancel_label), cancelPendingIntent));
}
notificationCompatBuilder.setContentTitle(contentTitle);
@@ -76,6 +90,16 @@ public class DownloadServiceNotification {
return notificationCompatBuilder.build();
}
+ private int getNumberOfRunningDownloads(List<Downloader> downloads) {
+ int running = 0;
+ for (Downloader downloader : downloads) {
+ if (!downloader.cancelled && !downloader.isFinished()) {
+ running++;
+ }
+ }
+ return running;
+ }
+
private boolean typeIsOnly(List<Downloader> downloads, int feedFileType) {
for (Downloader downloader : downloads) {
if (downloader.cancelled) {