aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2018-07-26 18:00:58 -0700
committerScott Jackson <daneren2005@gmail.com>2018-07-26 18:00:58 -0700
commiteebdb979a2d6d114ab4d8c2e6f5f6ed762b3ae4c (patch)
tree2204522f145b586c07e69d02872f40f7c0e73720
parent602a5429a0523d518cf95022920fa6dabb0a12b4 (diff)
downloaddsub-eebdb979a2d6d114ab4d8c2e6f5f6ed762b3ae4c.tar.gz
dsub-eebdb979a2d6d114ab4d8c2e6f5f6ed762b3ae4c.tar.bz2
dsub-eebdb979a2d6d114ab4d8c2e6f5f6ed762b3ae4c.zip
Add notification channels for API v26 compliance
-rw-r--r--app/build.gradle12
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Notifications.java68
-rw-r--r--build.gradle5
3 files changed, 77 insertions, 8 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 93d4c38f..803d85eb 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 26
+ compileSdkVersion 27
buildToolsVersion '25.0.0'
defaultConfig {
@@ -56,11 +56,11 @@ android {
dependencies {
compile project(':Server Proxy')
compile fileTree(include: ['*.jar'], dir: 'libs')
- compile 'com.android.support:support-v4:24.2.+'
- compile 'com.android.support:appcompat-v7:24.2.+'
- compile 'com.android.support:mediarouter-v7:24.2.+'
- compile 'com.android.support:recyclerview-v7:24.2.+'
- compile 'com.android.support:design:24.2.+'
+ compile 'com.android.support:support-v4:27.1.+'
+ compile 'com.android.support:appcompat-v7:27.1.+'
+ compile 'com.android.support:mediarouter-v7:27.1.+'
+ compile 'com.android.support:recyclerview-v7:27.1.+'
+ compile 'com.android.support:design:27.1.+'
googleCompile 'com.google.android.gms:play-services-cast:8.1.0'
compile 'com.sothree.slidinguppanel:library:3.0.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
index 750ab40c..ac36c99d 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
@@ -15,7 +15,9 @@
package github.daneren2005.dsub.util;
+import android.annotation.TargetApi;
import android.app.Notification;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
@@ -56,11 +58,24 @@ public final class Notifications {
private static boolean downloadForeground = false;
private static boolean persistentPlayingShowing = false;
+ private static NotificationChannel playingChannel;
+ private static NotificationChannel downloadingChannel;
+ private static NotificationChannel syncChannel;
+
private final static Pair<Integer, Integer> NOTIFICATION_TEXT_COLORS = new Pair<Integer, Integer>();
public static void showPlayingNotification(final Context context, final DownloadService downloadService, final Handler handler, MusicDirectory.Entry song) {
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ getPlayingNotificationChannel(context);
+ }
+
// Set the icon, scrolling text and timestamp
- final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis());
+ final Notification notification = new NotificationCompat.Builder(context)
+ .setSmallIcon(R.drawable.stat_notify_playing)
+ .setTicker(song.getTitle())
+ .setWhen(System.currentTimeMillis())
+ .setChannelId("now-playing-channel")
+ .build();
final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
if(playing) {
@@ -331,7 +346,24 @@ public final class Notifications {
DSubWidgetProvider.notifyInstances(context, downloadService, false);
}
+ @TargetApi(Build.VERSION_CODES.O)
+ private static NotificationChannel getPlayingNotificationChannel(Context context) {
+ if(playingChannel == null) {
+ playingChannel = new NotificationChannel("now-playing-channel", "Now Playing", NotificationManager.IMPORTANCE_DEFAULT);
+ playingChannel.setDescription("Now playing notification");
+
+ NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(playingChannel);
+ }
+
+ return playingChannel;
+ }
+
public static void showDownloadingNotification(final Context context, final DownloadService downloadService, Handler handler, DownloadFile file, int size) {
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ getDownloadingNotificationChannel(context);
+ }
+
Intent cancelIntent = new Intent(context, DownloadService.class);
cancelIntent.setAction(DownloadService.CANCEL_DOWNLOADS);
PendingIntent cancelPI = PendingIntent.getService(context, 0, cancelIntent, 0);
@@ -356,7 +388,8 @@ public final class Notifications {
.setOngoing(true)
.addAction(R.drawable.notification_close,
context.getResources().getString(R.string.common_cancel),
- cancelPI);
+ cancelPI)
+ .setChannelId("downloading-channel");
Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW, true);
@@ -395,6 +428,19 @@ public final class Notifications {
}
}
+ @TargetApi(Build.VERSION_CODES.O)
+ private static NotificationChannel getDownloadingNotificationChannel(Context context) {
+ if(downloadingChannel == null) {
+ downloadingChannel = new NotificationChannel("downloading-channel", "Downloading Notification", NotificationManager.IMPORTANCE_DEFAULT);
+ downloadingChannel.setDescription("Ongoing downloading notification to keep the service alive");
+
+ NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(downloadingChannel);
+ }
+
+ return downloadingChannel;
+ }
+
public static void showSyncNotification(final Context context, int stringId, String extra) {
showSyncNotification(context, stringId, extra, null);
}
@@ -404,6 +450,10 @@ public final class Notifications {
extra = "";
}
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ getSyncNotificationChannel(context);
+ }
+
NotificationCompat.Builder builder;
builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.stat_notify_sync)
@@ -413,6 +463,7 @@ public final class Notifications {
.setOngoing(false)
.setGroup(NOTIFICATION_SYNC_GROUP)
.setPriority(NotificationCompat.PRIORITY_LOW)
+ .setChannelId("sync-channel")
.setAutoCancel(true);
Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
@@ -449,4 +500,17 @@ public final class Notifications {
notificationManager.notify(stringId, builder.build());
}
}
+
+ @TargetApi(Build.VERSION_CODES.O)
+ private static NotificationChannel getSyncNotificationChannel(Context context) {
+ if(syncChannel == null) {
+ syncChannel = new NotificationChannel("sync-channel", "Sync Notifications", NotificationManager.IMPORTANCE_LOW);
+ syncChannel.setDescription("Sync notifications");
+
+ NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(syncChannel);
+ }
+
+ return syncChannel;
+ }
}
diff --git a/build.gradle b/build.gradle
index b304f7fc..d5dfdd4f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,6 +3,10 @@
buildscript {
repositories {
jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
@@ -18,5 +22,6 @@ allprojects {
maven {
url 'http://4thline.org/m2'
}
+ google()
}
}