summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2018-01-10 21:50:29 +0100
committerByteHamster <info@bytehamster.com>2018-05-03 19:11:28 +0200
commit7ad176ce299bb2abfa3698ce64ffc69b16cfdc8b (patch)
tree1fd6ff204c0c51b307c3ce6351c25c2eb707c669 /core
parent1d0459b126d7d219a0d10ec4d8c8b2fbd48fd8fa (diff)
downloadAntennaPod-7ad176ce299bb2abfa3698ce64ffc69b16cfdc8b.zip
Added notification categories
Android treats IMPORTANCE_DEFAULT as IMPORTANCE_HIGH https://issuetracker.google.com/issues/65108694
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java3
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java7
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/NotificationUtils.java62
-rw-r--r--core/src/main/res/values/strings.xml10
6 files changed, 84 insertions, 8 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java
index 5bd65f4e9..627e601bd 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java
@@ -10,6 +10,7 @@ import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
+import de.danoeh.antennapod.core.util.NotificationUtils;
import org.shredzone.flattr4j.exception.FlattrException;
import java.util.LinkedList;
@@ -175,7 +176,7 @@ public class FlattrClickWorker extends AsyncTask<Void, Integer, FlattrClickWorke
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
ClientConfig.flattrCallbacks.getFlattrAuthenticationActivityIntent(context), 0);
- Notification notification = new NotificationCompat.Builder(context)
+ Notification notification = new NotificationCompat.Builder(context, NotificationUtils.CHANNEL_ID_ERROR)
.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.no_flattr_token_notification_msg)))
.setContentIntent(contentIntent)
.setContentTitle(context.getString(R.string.no_flattr_token_title))
@@ -208,7 +209,7 @@ public class FlattrClickWorker extends AsyncTask<Void, Integer, FlattrClickWorke
+ context.getString(R.string.flattr_click_failure_count, failed);
}
- Notification notification = new NotificationCompat.Builder(context)
+ Notification notification = new NotificationCompat.Builder(context, NotificationUtils.CHANNEL_ID_ERROR)
.setStyle(new NotificationCompat.BigTextStyle().bigText(subtext))
.setContentIntent(contentIntent)
.setContentTitle(title)
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java b/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
index a723097a2..d022dbf02 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
@@ -37,6 +37,7 @@ import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.NetworkUtils;
+import de.danoeh.antennapod.core.util.NotificationUtils;
/**
* Synchronizes local subscriptions with gpodder.net service. The service should be started with ACTION_SYNC as an action argument.
@@ -319,7 +320,7 @@ public class GpodnetSyncService extends Service {
}
PendingIntent activityIntent = ClientConfig.gpodnetCallbacks.getGpodnetSyncServiceErrorNotificationPendingIntent(this);
- Notification notification = new NotificationCompat.Builder(this)
+ Notification notification = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_ERROR)
.setContentTitle(title)
.setContentText(description)
.setContentIntent(activityIntent)
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 a62c9d8bf..24be93415 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
@@ -22,6 +22,7 @@ import android.util.Log;
import android.util.Pair;
import android.webkit.URLUtil;
+import de.danoeh.antennapod.core.util.NotificationUtils;
import org.apache.commons.io.FileUtils;
import org.xml.sax.SAXException;
@@ -339,7 +340,7 @@ public class DownloadService extends Service {
}
private void setupNotificationBuilders() {
- notificationCompatBuilder = new NotificationCompat.Builder(this)
+ notificationCompatBuilder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_DOWNLOADING)
.setOngoing(true)
.setContentIntent(ClientConfig.downloadServiceCallbacks.getNotificationContentIntent(this))
.setSmallIcon(R.drawable.stat_notify_sync);
@@ -499,7 +500,7 @@ public class DownloadService extends Service {
if (createReport) {
Log.d(TAG, "Creating report");
// create notification object
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_ERROR)
.setTicker(getString(R.string.download_report_title))
.setContentTitle(getString(R.string.download_report_content_title))
.setContentText(
@@ -551,7 +552,7 @@ public class DownloadService extends Service {
final String resourceTitle = (downloadRequest.getTitle() != null) ?
downloadRequest.getTitle() : downloadRequest.getSource();
- NotificationCompat.Builder builder = new NotificationCompat.Builder(DownloadService.this);
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(DownloadService.this, NotificationUtils.CHANNEL_ID_USER_ACTION);
builder.setTicker(getText(R.string.authentication_notification_title))
.setContentTitle(getText(R.string.authentication_notification_title))
.setContentText(getText(R.string.authentication_notification_msg))
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index 3479c3368..03beec06a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -65,6 +65,7 @@ import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.FeedSearcher;
import de.danoeh.antennapod.core.util.IntList;
+import de.danoeh.antennapod.core.util.NotificationUtils;
import de.danoeh.antennapod.core.util.QueueAccess;
import de.danoeh.antennapod.core.util.playback.ExternalMedia;
import de.danoeh.antennapod.core.util.playback.Playable;
@@ -1216,8 +1217,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Notification notification;
// Builder is v7, even if some not overwritten methods return its parent's v4 interface
- NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(
- PlaybackService.this)
+ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
+ PlaybackService.this, NotificationUtils.CHANNEL_ID_PLAYING)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setOngoing(false)
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NotificationUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/NotificationUtils.java
new file mode 100644
index 000000000..f3824294f
--- /dev/null
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/NotificationUtils.java
@@ -0,0 +1,62 @@
+package de.danoeh.antennapod.core.util;
+
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.support.annotation.RequiresApi;
+import de.danoeh.antennapod.core.R;
+
+public class NotificationUtils {
+ public static final String CHANNEL_ID_USER_ACTION = "user_action";
+ 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 void createChannels(Context context) {
+ if (android.os.Build.VERSION.SDK_INT < 26) {
+ return;
+ }
+ NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+
+ if (mNotificationManager != null) {
+ mNotificationManager.createNotificationChannel(createChannelUserAction(context));
+ mNotificationManager.createNotificationChannel(createChannelDownloading(context));
+ mNotificationManager.createNotificationChannel(createChannelPlaying(context));
+ mNotificationManager.createNotificationChannel(createChannelError(context));
+ }
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ private static NotificationChannel createChannelUserAction(Context c) {
+ NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_USER_ACTION,
+ c.getString(R.string.notification_channel_user_action), NotificationManager.IMPORTANCE_HIGH);
+ mChannel.setDescription(c.getString(R.string.notification_channel_user_action_description));
+ return mChannel;
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ private static NotificationChannel createChannelDownloading(Context c) {
+ NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_DOWNLOADING,
+ c.getString(R.string.notification_channel_downloading), NotificationManager.IMPORTANCE_LOW);
+ mChannel.setDescription(c.getString(R.string.notification_channel_downloading_description));
+ return mChannel;
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ private static NotificationChannel createChannelPlaying(Context c) {
+ NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_PLAYING,
+ c.getString(R.string.notification_channel_playing), NotificationManager.IMPORTANCE_LOW);
+ mChannel.setDescription(c.getString(R.string.notification_channel_playing_description));
+ return mChannel;
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ private static NotificationChannel createChannelError(Context c) {
+ NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_ERROR,
+ c.getString(R.string.notification_channel_error), NotificationManager.IMPORTANCE_HIGH);
+ mChannel.setDescription(c.getString(R.string.notification_channel_error_description));
+ return mChannel;
+ }
+}
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 46bac68c9..2e7cc7149 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -709,4 +709,14 @@
<string name="cast_failed_seek">Failed to seek to the new position on the cast device</string>
<string name="cast_failed_receiver_player_error">Receiver player has encountered a severe error</string>
<string name="cast_failed_media_error_skipping">Error playing media. Skipping&#8230;</string>
+
+ <!-- Notification channels -->
+ <string name="notification_channel_user_action">Action required</string>
+ <string name="notification_channel_user_action_description">Shown if your action is required</string>
+ <string name="notification_channel_downloading">Downloading</string>
+ <string name="notification_channel_downloading_description">Shown while currently downloading</string>
+ <string name="notification_channel_playing">Currently playing</string>
+ <string name="notification_channel_playing_description">Allows to control playback</string>
+ <string name="notification_channel_error">Errors</string>
+ <string name="notification_channel_error_description">Shown if something went wrong</string>
</resources>