From 11e8e38f2cf879f6f4a4d62ed6278dcbe17e3b9f Mon Sep 17 00:00:00 2001 From: Schabi Date: Fri, 29 Dec 2017 17:29:15 +0100 Subject: [PATCH] setup context for making notifications open via setContextIntent() --- .../newpipe/player/BackgroundPlayer.java | 7 ++---- .../schabi/newpipe/util/NavigationHelper.java | 22 +++++++++++++++---- .../main/res/layout/player_notification.xml | 2 -- .../layout/player_notification_expanded.xml | 2 -- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 482f8f803..2334031ee 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -180,7 +180,8 @@ public final class BackgroundPlayer extends Service { .setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCustomContentView(notRemoteView) - .setCustomBigContentView(bigNotRemoteView); + .setCustomBigContentView(bigNotRemoteView) + .setContentIntent(NavigationHelper.getServicePlayerControlPendingIntent(this, BackgroundPlayerActivity.class)); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) builder.setPriority(NotificationCompat.PRIORITY_MAX); return builder; } @@ -453,7 +454,6 @@ public final class BackgroundPlayer extends Service { super.setupBroadcastReceiver(intentFilter); intentFilter.addAction(ACTION_CLOSE); intentFilter.addAction(ACTION_PLAY_PAUSE); - intentFilter.addAction(ACTION_OPEN_CONTROLS); intentFilter.addAction(ACTION_REPEAT); intentFilter.addAction(ACTION_PLAY_PREVIOUS); intentFilter.addAction(ACTION_PLAY_NEXT); @@ -478,9 +478,6 @@ public final class BackgroundPlayer extends Service { case ACTION_PLAY_PAUSE: onVideoPlayPause(); break; - case ACTION_OPEN_CONTROLS: - NavigationHelper.openBackgroundPlayerControl(getApplicationContext()); - break; case ACTION_REPEAT: onRepeatClicked(); break; diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index e59ad10b2..4475356fa 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.util; import android.app.Activity; +import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -45,6 +46,8 @@ import org.schabi.newpipe.settings.SettingsActivity; public class NavigationHelper { public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag"; + public static final int PENDING_INTENT_OPEN_PLAYER_ACTIVITY = 1546; + /*////////////////////////////////////////////////////////////////////////// // Players //////////////////////////////////////////////////////////////////////////*/ @@ -269,13 +272,24 @@ public class NavigationHelper { openServicePlayerControl(context, PopupVideoPlayerActivity.class); } - private static void openServicePlayerControl(final Context context, final Class clazz) { - final Intent intent = new Intent(context, clazz); + private static void openServicePlayerControl(final Context context, final Class activityClass) { + Intent intent = getServicePlayerControlIntent(context, activityClass); + context.startActivity(intent); + context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); + } + + public static Intent getServicePlayerControlIntent(final Context context, final Class activityClass) { + final Intent intent = new Intent(context, activityClass); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } - context.startActivity(intent); - context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); + return intent; + } + + public static PendingIntent getServicePlayerControlPendingIntent(final Context context, final Class activityClass) { + Intent intent = getServicePlayerControlIntent(context, activityClass); + PendingIntent pIntent = PendingIntent.getActivity(context, PENDING_INTENT_OPEN_PLAYER_ACTIVITY, intent, 0); + return pIntent; } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/res/layout/player_notification.xml b/app/src/main/res/layout/player_notification.xml index 2a3e7aff3..bab0c9db3 100644 --- a/app/src/main/res/layout/player_notification.xml +++ b/app/src/main/res/layout/player_notification.xml @@ -11,8 +11,6 @@ android:layout_width="match_parent" android:layout_height="64dp" android:background="@color/background_notification_color" - android:clickable="true" - android:focusable="true" android:gravity="center_vertical" android:orientation="horizontal"> diff --git a/app/src/main/res/layout/player_notification_expanded.xml b/app/src/main/res/layout/player_notification_expanded.xml index 7d59720e0..090642303 100644 --- a/app/src/main/res/layout/player_notification_expanded.xml +++ b/app/src/main/res/layout/player_notification_expanded.xml @@ -6,8 +6,6 @@ android:layout_width="match_parent" android:layout_height="128dp" android:background="@color/background_notification_color" - android:clickable="true" - android:focusable="true" android:gravity="center_vertical" android:orientation="horizontal">