[Android] TV: Restore recommendations on Oreo

Geoffrey Métais git at videolan.org
Wed Jul 4 18:44:11 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jul  4 15:27:00 2018 +0200| [2dd063f9a88b8ac972f0108b506871662fbc17a7] | committer: Geoffrey Métais

TV: Restore recommendations on Oreo

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

 vlc-android/src/org/videolan/vlc/BootupReceiver.java  | 16 ++++++----------
 .../src/org/videolan/vlc/RecommendationsService.java  | 19 +++++++------------
 .../src/org/videolan/vlc/gui/tv/MainTvFragment.kt     |  2 +-
 3 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/BootupReceiver.java b/vlc-android/src/org/videolan/vlc/BootupReceiver.java
index a33f6f325..097c7822c 100644
--- a/vlc-android/src/org/videolan/vlc/BootupReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/BootupReceiver.java
@@ -40,23 +40,19 @@ 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);
         }
     }
 
     private void scheduleRecommendationUpdate(Context context) {
-        AlarmManager alarmManager = (AlarmManager) context.getApplicationContext().getSystemService(
+        final  AlarmManager alarmManager = (AlarmManager) context.getApplicationContext().getSystemService(
                 Context.ALARM_SERVICE);
-        Intent recommendationIntent = new Intent(context,
-                RecommendationsService.class);
-        PendingIntent alarmIntent = PendingIntent.getService(context, 0,
-                recommendationIntent, 0);
+        if (alarmManager == null) return;
+        final Intent ri = new Intent(context, RecommendationsService.class);
+        final PendingIntent pi = PendingIntent.getService(context, 0, ri, 0);
 
-        alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
-                INITIAL_DELAY,
-                AlarmManager.INTERVAL_HOUR,
-                alarmIntent);
+        alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, INITIAL_DELAY, AlarmManager.INTERVAL_HOUR, pi);
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/RecommendationsService.java b/vlc-android/src/org/videolan/vlc/RecommendationsService.java
index badc676b1..bc94614d7 100644
--- a/vlc-android/src/org/videolan/vlc/RecommendationsService.java
+++ b/vlc-android/src/org/videolan/vlc/RecommendationsService.java
@@ -66,12 +66,10 @@ public class RecommendationsService extends IntentService {
     }
 
     private void buildRecommendation(MediaWrapper movie, int id, int priority) {
-        if (movie == null)
-            return;
-
+        if (movie == null) return;
         // build the recommendation as a Notification object
-        Notification notification = new NotificationCompat.BigPictureStyle(
-                new NotificationCompat.Builder(RecommendationsService.this)
+        final Notification notification = new NotificationCompat.BigPictureStyle(
+                new NotificationCompat.Builder(RecommendationsService.this, "vlc_recommendations")
                         .setContentTitle(movie.getTitle())
                         .setContentText(movie.getDescription())
                         .setContentInfo(getString(R.string.app_name))
@@ -84,13 +82,12 @@ public class RecommendationsService extends IntentService {
                         .setSmallIcon(R.drawable.icon)
                         .setContentIntent(buildPendingIntent(movie, id))
         ).build();
-
         // post the recommendation to the NotificationManager
         mNotificationManager.notify(id, notification);
     }
 
     private PendingIntent buildPendingIntent(MediaWrapper mediaWrapper, int id) {
-        Intent intent = new Intent(RecommendationsService.this, VideoPlayerActivity.class);
+        final Intent intent = new Intent(RecommendationsService.this, VideoPlayerActivity.class);
         intent.setAction(Constants.PLAY_FROM_VIDEOGRID);
         intent.putExtra(Constants.PLAY_EXTRA_ITEM_LOCATION, mediaWrapper.getUri());
         intent.putExtra(Constants.PLAY_EXTRA_ITEM_TITLE, mediaWrapper.getTitle());
@@ -105,13 +102,11 @@ public class RecommendationsService extends IntentService {
             @Override
             public void run() {
                 int id = 0;
-                List<MediaWrapper> videoList = Arrays.asList(VLCApplication.getMLInstance().getRecentVideos());
-                if (Util.isListEmpty(videoList))
-                    return;
+                final List<MediaWrapper> videoList = Arrays.asList(VLCApplication.getMLInstance().getRecentVideos());
+                if (Util.isListEmpty(videoList)) return;
                 for (MediaWrapper mediaWrapper : videoList){
                     buildRecommendation(mediaWrapper, ++id, Notification.PRIORITY_DEFAULT);
-                    if (id == MAX_RECOMMENDATIONS)
-                        break;
+                    if (id == MAX_RECOMMENDATIONS) break;
                 }
             }
         });
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
index 65441cf61..1e83c6753 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
@@ -169,7 +169,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
 
     override fun onStop() {
         super.onStop()
-        if (AndroidDevices.isAndroidTv && !AndroidUtil.isOOrLater) requireActivity().startService(Intent(requireActivity(), RecommendationsService::class.java))
+        if (AndroidDevices.isAndroidTv) requireActivity().startService(Intent(requireActivity(), RecommendationsService::class.java))
     }
 
     override fun onDestroy() {



More information about the Android mailing list