summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java42
-rw-r--r--ui/app-start-intent/src/main/res/values/pending_intent.xml1
-rw-r--r--ui/png-icons/src/main/res/drawable/ic_notification_cancel.xml5
3 files changed, 39 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) {
diff --git a/ui/app-start-intent/src/main/res/values/pending_intent.xml b/ui/app-start-intent/src/main/res/values/pending_intent.xml
index c0864046c..30b35d926 100644
--- a/ui/app-start-intent/src/main/res/values/pending_intent.xml
+++ b/ui/app-start-intent/src/main/res/values/pending_intent.xml
@@ -2,6 +2,7 @@
<resources>
<item name="pending_intent_download_service_notification" type="id"/>
<item name="pending_intent_download_service_retry" type="id"/>
+ <item name="pending_intent_download_cancel_all" type="id"/>
<item name="pending_intent_download_service_auth" type="id"/>
<item name="pending_intent_download_service_report" type="id"/>
<item name="pending_intent_download_service_autodownload_report" type="id"/>
diff --git a/ui/png-icons/src/main/res/drawable/ic_notification_cancel.xml b/ui/png-icons/src/main/res/drawable/ic_notification_cancel.xml
new file mode 100644
index 000000000..a5480c71f
--- /dev/null
+++ b/ui/png-icons/src/main/res/drawable/ic_notification_cancel.xml
@@ -0,0 +1,5 @@
+<vector android:height="24dp"
+ android:viewportHeight="24.0" android:viewportWidth="24.0"
+ android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ <path android:fillColor="#FFFFFFFF" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
+</vector>