Unify notification channels for background service and background media player

This commit is contained in:
Akinwale Ariwodola 2018-09-02 11:38:15 +01:00
parent 87a50c494f
commit 0592c42df0
2 changed files with 3 additions and 17 deletions

View file

@ -37,14 +37,14 @@ import org.renpy.android.ResourceManager;
*/ */
public class LbrynetService extends PythonService { public class LbrynetService extends PythonService {
private static final String NOTIFICATION_CHANNEL_ID = "io.lbry.browser.DAEMON_NOTIFICATION_CHANNEL";
private static final int SERVICE_NOTIFICATION_GROUP_ID = -1; private static final int SERVICE_NOTIFICATION_GROUP_ID = -1;
public static final String ACTION_STOP_SERVICE = "io.lbry.browser.ACTION_STOP_SERVICE"; public static final String ACTION_STOP_SERVICE = "io.lbry.browser.ACTION_STOP_SERVICE";
public static final String GROUP_SERVICE = "io.lbry.browser.GROUP_SERVICE"; public static final String GROUP_SERVICE = "io.lbry.browser.GROUP_SERVICE";
public static final String NOTIFICATION_CHANNEL_ID = "io.lbry.browser.DAEMON_NOTIFICATION_CHANNEL";
public static String TAG = "LbrynetService"; public static String TAG = "LbrynetService";
public static LbrynetService serviceInstance; public static LbrynetService serviceInstance;

View file

@ -26,16 +26,12 @@ public class BackgroundMediaModule extends ReactContextBaseJavaModule {
private static final int NOTIFICATION_ID = -2; private static final int NOTIFICATION_ID = -2;
private static final String NOTIFICATION_CHANNEL_ID = "io.lbry.browser.MEDIA_PLAYER_NOTIFICATION_CHANNEL";
public static final String ACTION_PLAY = "io.lbry.browser.ACTION_MEDIA_PLAY"; public static final String ACTION_PLAY = "io.lbry.browser.ACTION_MEDIA_PLAY";
public static final String ACTION_PAUSE = "io.lbry.browser.ACTION_MEDIA_PAUSE"; public static final String ACTION_PAUSE = "io.lbry.browser.ACTION_MEDIA_PAUSE";
public static final String ACTION_STOP = "io.lbry.browser.ACTION_MEDIA_STOP"; public static final String ACTION_STOP = "io.lbry.browser.ACTION_MEDIA_STOP";
private boolean channelCreated;
private Context context; private Context context;
public BackgroundMediaModule(ReactApplicationContext reactContext) { public BackgroundMediaModule(ReactApplicationContext reactContext) {
@ -50,16 +46,6 @@ public class BackgroundMediaModule extends ReactContextBaseJavaModule {
@ReactMethod @ReactMethod
public void showPlaybackNotification(String title, String publisher, String uri, boolean paused) { public void showPlaybackNotification(String title, String publisher, String uri, boolean paused) {
if (!channelCreated && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(
NOTIFICATION_CHANNEL_ID, "LBRY Media", NotificationManager.IMPORTANCE_LOW);
channel.setDescription("LBRY media player");
notificationManager.createNotificationChannel(channel);
channelCreated = true;
}
Intent contextIntent = new Intent(context, MainActivity.class); Intent contextIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contextIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
@ -72,7 +58,7 @@ public class BackgroundMediaModule extends ReactContextBaseJavaModule {
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(context, 0, pauseIntent, 0); PendingIntent pausePendingIntent = PendingIntent.getBroadcast(context, 0, pauseIntent, 0);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, LbrynetService.NOTIFICATION_CHANNEL_ID);
builder.setColor(ContextCompat.getColor(context, R.color.lbrygreen)) builder.setColor(ContextCompat.getColor(context, R.color.lbrygreen))
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setContentTitle(title) .setContentTitle(title)