Commit a0d68c39 authored by Geoffrey Métais's avatar Geoffrey Métais

TV: Restore reocmmendations on Oreo

parent 64da0651
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
}
......
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