From 7a93f1e513c3616cebd88567fc701578cef357f1 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Thu, 13 Feb 2020 08:40:47 -0500 Subject: Add new notification channel --- .../download/DownloadServiceNotification.java | 23 +++++++++++----------- .../core/util/gui/NotificationUtils.java | 12 +++++++++++ core/src/main/res/values/strings.xml | 4 +++- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'core/src/main') 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 811b2374e..153effb57 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 @@ -116,20 +116,19 @@ public class DownloadServiceNotification { if (createReport) { Log.d(TAG, "Creating report"); + // create notification object - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, - NotificationUtils.CHANNEL_ID_ERROR) - .setTicker(context.getString(R.string.download_report_title)) - .setContentTitle(context.getString(R.string.download_report_content_title)) - .setContentText( - String.format( + boolean autoDownloadReport = failedDownloads == 0; + NotificationCompat.Builder builder = new NotificationCompat.Builder( + context, + autoDownloadReport ? NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD : NotificationUtils.CHANNEL_ID_ERROR); + builder.setTicker(context.getString(R.string.download_report_title)) + .setContentTitle(context.getString(R.string.download_report_content_title)) + .setContentText(String.format( context.getString(R.string.download_report_content), - successfulDownloads, failedDownloads) - ) - .setSmallIcon(R.drawable.stat_notify_sync_error) - .setContentIntent( - ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context) - ) + successfulDownloads, failedDownloads)) + .setSmallIcon(autoDownloadReport ? R.drawable.stat_notify_sync : R.drawable.stat_notify_sync_error) + .setContentIntent(ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java index 02e98ba84..665d0fe79 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java @@ -14,6 +14,7 @@ public class NotificationUtils { public static final String CHANNEL_ID_DOWNLOADING = "downloading"; public static final String CHANNEL_ID_PLAYING = "playing"; public static final String CHANNEL_ID_ERROR = "error"; + public static final String CHANNEL_ID_AUTO_DOWNLOAD = "auto_download"; public static void createChannels(Context context) { if (android.os.Build.VERSION.SDK_INT < 26) { @@ -26,6 +27,7 @@ public class NotificationUtils { mNotificationManager.createNotificationChannel(createChannelDownloading(context)); mNotificationManager.createNotificationChannel(createChannelPlaying(context)); mNotificationManager.createNotificationChannel(createChannelError(context)); + mNotificationManager.createNotificationChannel(createChannelAutoDownload(context)); } } @@ -62,4 +64,14 @@ public class NotificationUtils { mChannel.setDescription(c.getString(R.string.notification_channel_error_description)); return mChannel; } + + @RequiresApi(api = Build.VERSION_CODES.O) + private static NotificationChannel createChannelAutoDownload(Context c) { + NotificationChannel mChannel = new NotificationChannel( + CHANNEL_ID_AUTO_DOWNLOAD, + c.getString(R.string.notification_channel_auto_download), + NotificationManager.IMPORTANCE_DEFAULT); + mChannel.setDescription(c.getString(R.string.notification_channel_downloading_description)); + return mChannel; + } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 54b6a9f4d..023bf0310 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -236,7 +236,7 @@ Forbidden Download canceled Download canceled\nDisabled Auto Download for this item - Downloads completed with error(s) + Downloads completed Download Report Malformed URL IO Error @@ -783,6 +783,8 @@ Allows to control playback. This is the main notification you see while playing a podcast. Errors Shown if something went wrong, for example if download or gpodder sync fails. + Auto Downloads + Shown when episodes are automatically downloaded. Widget settings -- cgit v1.2.3