Commit 214cdaf8 authored by Geoffrey Métais's avatar Geoffrey Métais

Refine notification channels management

parent 881bf973
......@@ -28,6 +28,10 @@
</plurals>
<string name="play">Play</string>
<string name="playback">Playback</string>
<string name="playback_controls">Playback controls</string>
<string name="medialibrary_scan">Media library scan</string>
<string name="Medialibrary_progress">Media library scanning progress updates</string>
<string name="play_from_start">Play from start</string>
<string name="play_as_audio">Play as audio</string>
<string name="play_as_video">Play as video</string>
......
......@@ -908,8 +908,6 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
Notification notification = NotificationHelper.createPlaybackNotification(PlaybackService.this,
mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO), title, artist, album,
cover, playing, sessionToken, getSessionPendingIntent());
startService(new Intent(ctx, PlaybackService.class));
if (!AndroidUtil.isLolliPopOrLater || playing)
PlaybackService.this.startForeground(3, notification);
else {
......
......@@ -96,7 +96,7 @@ public class VLCApplication extends Application {
@Override
public void run() {
if (AndroidUtil.isOOrLater)
NotificationHelper.createNotificationChannel();
NotificationHelper.createNotificationChannels();
// Prepare cache folder constants
AudioUtil.prepareCacheFolder(instance);
......
......@@ -58,7 +58,7 @@ public class NotificationHelper {
final PendingIntent piPlay = PendingIntent.getBroadcast(ctx, 0, new Intent(PlaybackService.ACTION_REMOTE_PLAYPAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
final PendingIntent piForward = PendingIntent.getBroadcast(ctx, 0, new Intent(PlaybackService.ACTION_REMOTE_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT);
if (AndroidUtil.isOOrLater) {
final Notification.Builder builder = new Notification.Builder(ctx, "vlc_channel");
final Notification.Builder builder = new Notification.Builder(ctx, "vlc_playback");
builder.setSmallIcon(video ? R.drawable.ic_notif_video : R.drawable.ic_notif_audio)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentTitle(title)
......@@ -83,6 +83,7 @@ public class NotificationHelper {
.setShowActionsInCompactView(0,1,2)
);
}
ctx.startForegroundService(new Intent(ctx, PlaybackService.class));
return builder.build();
} else {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
......@@ -111,6 +112,7 @@ public class NotificationHelper {
.setCancelButtonIntent(piStop)
);
}
ctx.startService(new Intent(ctx, PlaybackService.class));
return builder.build();
}
}
......@@ -121,7 +123,7 @@ public class NotificationHelper {
public static Notification createScanNotification(Context ctx, String progressText, boolean updateActions, boolean paused) {
if (AndroidUtil.isOOrLater) {
if (scanBuilder == null) {
scanBuilder = new Notification.Builder(ctx, "vlc_channel")
scanBuilder = new Notification.Builder(ctx, "vlc_medialibrary")
.setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, StartActivity.class), PendingIntent.FLAG_UPDATE_CURRENT))
.setSmallIcon(R.drawable.ic_notif_scan)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
......@@ -168,14 +170,22 @@ public class NotificationHelper {
private static NotificationManager sNotificationManager;
@RequiresApi(api = Build.VERSION_CODES.O)
public static void createNotificationChannel() {
public static void createNotificationChannels() {
if (sNotificationManager == null)
sNotificationManager = (NotificationManager) VLCApplication.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE);
final CharSequence name = VLCApplication.getAppResources().getString(R.string.app_name);
final String description = VLCApplication.getAppResources().getString(R.string.app_name_full);
final int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel mChannel = new NotificationChannel("vlc_channel", name, importance);
mChannel.setDescription(description);
sNotificationManager.createNotificationChannel(mChannel);
// Playback channel
CharSequence name = VLCApplication.getAppResources().getString(R.string.playback);
String description = VLCApplication.getAppResources().getString(R.string.playback_controls);
NotificationChannel channel = new NotificationChannel("vlc_playback", name, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(description);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
sNotificationManager.createNotificationChannel(channel);
// Scan channel
name = VLCApplication.getAppResources().getString(R.string.medialibrary_scan);
description = VLCApplication.getAppResources().getString(R.string.Medialibrary_progress);
channel = new NotificationChannel("vlc_medialibrary", name, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(description);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
sNotificationManager.createNotificationChannel(channel);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment