[Android] TV: Restore reocmmendations on Oreo

Geoffrey Métais git at videolan.org
Wed Jul 4 12:06:17 CEST 2018


vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jul  4 12:05:23 2018 +0200| [a0d68c39b38be8cf6068ec15d0da29c882489684] | committer: Geoffrey Métais

TV: Restore reocmmendations on Oreo

> https://code.videolan.org/videolan/vlc-android/commit/a0d68c39b38be8cf6068ec15d0da29c882489684
---

 .../src/org/videolan/vlc/BootupReceiver.java       |  2 +-
 .../org/videolan/vlc/RecommendationsService.java   | 25 +++---------
 .../vlc/gui/helpers/NotificationHelper.java        | 45 ++++++++++++++++++++--
 .../org/videolan/vlc/gui/tv/MainTvActivity.java    |  2 +-
 4 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/BootupReceiver.java b/vlc-android/src/org/videolan/vlc/BootupReceiver.java
index a33f6f325..61e8271a3 100644
--- a/vlc-android/src/org/videolan/vlc/BootupReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/BootupReceiver.java
@@ -40,7 +40,7 @@ public class BootupReceiver extends BroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
         final String action = intent.getAction();
-        if (action != null && AndroidDevices.isAndroidTv && !AndroidUtil.isOOrLater && action.endsWith(Intent.ACTION_BOOT_COMPLETED)) {
+        if (action != null && AndroidDevices.isAndroidTv && action.endsWith(Intent.ACTION_BOOT_COMPLETED)) {
             if (BuildConfig.DEBUG) Log.d(TAG, "ACTION_BOOT_COMPLETED ");
             scheduleRecommendationUpdate(context);
         }
diff --git a/vlc-android/src/org/videolan/vlc/RecommendationsService.java b/vlc-android/src/org/videolan/vlc/RecommendationsService.java
index 6a662d9e1..396a20383 100644
--- a/vlc-android/src/org/videolan/vlc/RecommendationsService.java
+++ b/vlc-android/src/org/videolan/vlc/RecommendationsService.java
@@ -33,6 +33,7 @@ import android.support.v4.content.ContextCompat;
 
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.gui.helpers.BitmapUtil;
+import org.videolan.vlc.gui.helpers.NotificationHelper;
 import org.videolan.vlc.gui.video.VideoPlayerActivity;
 import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.util.Util;
@@ -45,6 +46,7 @@ public class RecommendationsService extends IntentService {
 
     private static final String TAG = "VLC/RecommendationsService";
     private static final int MAX_RECOMMENDATIONS = 3;
+    private String appName;
 
     private NotificationManager mNotificationManager;
 
@@ -57,6 +59,7 @@ public class RecommendationsService extends IntentService {
         super.onCreate();
         mNotificationManager = (NotificationManager)
                 getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
+        appName = getString(R.string.app_name);
     }
 
     @Override
@@ -65,25 +68,9 @@ public class RecommendationsService extends IntentService {
     }
 
     private void buildRecommendation(MediaWrapper movie, int id, int priority) {
-        if (movie == null)
-            return;
-
-        // build the recommendation as a Notification object
-        Notification notification = new NotificationCompat.BigPictureStyle(
-                new NotificationCompat.Builder(RecommendationsService.this)
-                        .setContentTitle(movie.getTitle())
-                        .setContentText(movie.getDescription())
-                        .setContentInfo(getString(R.string.app_name))
-                        .setPriority(priority)
-                        .setLocalOnly(true)
-                        .setOngoing(true)
-                        .setColor(ContextCompat.getColor(this, R.color.orange800))
-                        .setCategory(Notification.CATEGORY_RECOMMENDATION)
-                        .setLargeIcon(BitmapUtil.getPicture(movie))
-                        .setSmallIcon(R.drawable.icon)
-                        .setContentIntent(buildPendingIntent(movie, id))
-        ).build();
-
+        if (movie == null) return;
+        final Notification notification = NotificationHelper.createRecommendation(this, movie, priority, appName, buildPendingIntent(movie, id));
+        if (notification == null) return;
         // post the recommendation to the NotificationManager
         mNotificationManager.notify(id, notification);
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java b/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java
index e8faf0a52..cb3fb866f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java
@@ -31,11 +31,14 @@ import android.graphics.Bitmap;
 import android.media.session.MediaSession;
 import android.os.Build;
 import android.support.annotation.RequiresApi;
+import android.support.v4.content.ContextCompat;
 import android.support.v4.media.session.MediaSessionCompat;
 import android.support.v7.app.NotificationCompat;
 
 import org.videolan.libvlc.util.AndroidUtil;
+import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.R;
+import org.videolan.vlc.RecommendationsService;
 import org.videolan.vlc.StartActivity;
 import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Constants;
@@ -60,14 +63,14 @@ public class NotificationHelper {
         if (AndroidUtil.isOOrLater) {
             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)
+                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                     .setContentTitle(title)
                     .setContentText(Util.getMediaDescription(artist, album))
                     .setLargeIcon(cover)
                     .setTicker(title + " - " + artist)
                     .setAutoCancel(!playing)
                     .setOngoing(playing)
-                    .setCategory(NotificationCompat.CATEGORY_SERVICE)
+                    .setCategory(Notification.CATEGORY_SERVICE)
                     .setDeleteIntent(piStop)
                     .setContentIntent(spi)
                     .addAction(R.drawable.ic_widget_previous_w, ctx.getString(R.string.previous), piBackward);
@@ -125,7 +128,7 @@ public class NotificationHelper {
                 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)
+                        .setVisibility(Notification.VISIBILITY_PUBLIC)
                         .setContentTitle(ctx.getString(R.string.ml_scanning))
                         .setAutoCancel(false)
                         .setCategory(NotificationCompat.CATEGORY_PROGRESS)
@@ -167,6 +170,42 @@ public class NotificationHelper {
         }
     }
 
+    public static Notification createRecommendation(Context ctx, MediaWrapper movie, int priority, String appName, PendingIntent pi) {
+        // build the recommendation as a Notification object
+        if (AndroidUtil.isOOrLater) {
+            final Notification.BigPictureStyle bps = new Notification.BigPictureStyle();
+            bps.setBuilder(
+                    new Notification.Builder(ctx, "vlc_recommendations")
+                    .setContentTitle(movie.getTitle())
+                    .setContentText(movie.getDescription())
+                    .setSubText(appName)
+                    .setPriority(priority)
+                    .setLocalOnly(true)
+                    .setOngoing(true)
+                    .setColor(ContextCompat.getColor(ctx, R.color.orange800))
+                    .setCategory(Notification.CATEGORY_RECOMMENDATION)
+                    .setLargeIcon(BitmapUtil.getPicture(movie))
+                    .setSmallIcon(R.drawable.icon)
+                    .setContentIntent(pi)
+            );
+            return bps.build();
+        } else return new android.support.v4.app.NotificationCompat.BigPictureStyle(
+                new android.support.v4.app.NotificationCompat.Builder(ctx)
+                        .setContentTitle(movie.getTitle())
+                        .setContentText(movie.getDescription())
+                        .setContentInfo(appName)
+                        .setPriority(priority)
+                        .setLocalOnly(true)
+                        .setOngoing(true)
+                        .setColor(ContextCompat.getColor(ctx, R.color.orange800))
+                        .setCategory(Notification.CATEGORY_RECOMMENDATION)
+                        .setLargeIcon(BitmapUtil.getPicture(movie))
+                        .setSmallIcon(R.drawable.icon)
+                        .setContentIntent(pi)
+        ).build();
+
+    }
+
     @RequiresApi(api = Build.VERSION_CODES.O)
     public static void createNotificationChannels(Context appCtx) {
         final NotificationManager notificationManager = (NotificationManager) appCtx.getSystemService(Context.NOTIFICATION_SERVICE);
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index c7f9c9a49..e128c28db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -208,7 +208,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
     @Override
     protected void onStop() {
         super.onStop();
-        if (AndroidDevices.isAndroidTv && !AndroidUtil.isOOrLater) startService(new Intent(this, RecommendationsService.class));
+        if (AndroidDevices.isAndroidTv) startService(new Intent(this, RecommendationsService.class));
         TvUtil.releaseBackgroundManager(mBackgroundManager);
     }
 



More information about the Android mailing list