Fix notification content intent not being updated when needed
This commit is contained in:
parent
9cf0bc6c82
commit
bc8954fbba
|
@ -120,8 +120,6 @@ public final class NotificationUtil {
|
||||||
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setColor(ContextCompat.getColor(player.context, R.color.gray))
|
.setColor(ContextCompat.getColor(player.context, R.color.gray))
|
||||||
.setContentIntent(PendingIntent.getActivity(player.context, NOTIFICATION_ID,
|
|
||||||
getIntentForNotification(player), FLAG_UPDATE_CURRENT))
|
|
||||||
.setDeleteIntent(PendingIntent.getBroadcast(player.context, NOTIFICATION_ID,
|
.setDeleteIntent(PendingIntent.getBroadcast(player.context, NOTIFICATION_ID,
|
||||||
new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT));
|
new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT));
|
||||||
|
|
||||||
|
@ -141,6 +139,9 @@ public final class NotificationUtil {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// also update content intent, in case the user switched players
|
||||||
|
notificationBuilder.setContentIntent(PendingIntent.getActivity(player.context,
|
||||||
|
NOTIFICATION_ID, getIntentForNotification(player), FLAG_UPDATE_CURRENT));
|
||||||
notificationBuilder.setContentTitle(player.getVideoTitle());
|
notificationBuilder.setContentTitle(player.getVideoTitle());
|
||||||
notificationBuilder.setContentText(player.getUploaderName());
|
notificationBuilder.setContentText(player.getUploaderName());
|
||||||
updateActions(notificationBuilder, player);
|
updateActions(notificationBuilder, player);
|
||||||
|
@ -326,20 +327,19 @@ public final class NotificationUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent getIntentForNotification(final VideoPlayerImpl player) {
|
private Intent getIntentForNotification(final VideoPlayerImpl player) {
|
||||||
final Intent intent;
|
|
||||||
if (player.audioPlayerSelected() || player.popupPlayerSelected()) {
|
if (player.audioPlayerSelected() || player.popupPlayerSelected()) {
|
||||||
// Means we play in popup or audio only. Let's show BackgroundPlayerActivity
|
// Means we play in popup or audio only. Let's show the play queue
|
||||||
intent = NavigationHelper.getBackgroundPlayerActivityIntent(player.context);
|
return NavigationHelper.getPlayQueueActivityIntent(player.context);
|
||||||
} else {
|
} else {
|
||||||
// We are playing in fragment. Don't open another activity just show fragment. That's it
|
// We are playing in fragment. Don't open another activity just show fragment. That's it
|
||||||
intent = NavigationHelper.getPlayerIntent(
|
final Intent intent = NavigationHelper.getPlayerIntent(
|
||||||
player.context, MainActivity.class, null, true);
|
player.context, MainActivity.class, null, true);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.setAction(Intent.ACTION_MAIN);
|
intent.setAction(Intent.ACTION_MAIN);
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||||
}
|
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
|
@ -57,7 +57,7 @@ import org.schabi.newpipe.settings.SettingsActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
@SuppressWarnings({"unused"})
|
||||||
public final class NavigationHelper {
|
public final class NavigationHelper {
|
||||||
public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag";
|
public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag";
|
||||||
public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag";
|
public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag";
|
||||||
|
@ -69,17 +69,19 @@ public final class NavigationHelper {
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Intent getPlayerIntent(@NonNull final Context context,
|
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
||||||
@NonNull final Class targetClazz,
|
@NonNull final Class<T> targetClazz,
|
||||||
@NonNull final PlayQueue playQueue,
|
@Nullable final PlayQueue playQueue,
|
||||||
@Nullable final String quality,
|
@Nullable final String quality,
|
||||||
final boolean resumePlayback) {
|
final boolean resumePlayback) {
|
||||||
final Intent intent = new Intent(context, targetClazz);
|
final Intent intent = new Intent(context, targetClazz);
|
||||||
|
|
||||||
|
if (playQueue != null) {
|
||||||
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);
|
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);
|
||||||
if (cacheKey != null) {
|
if (cacheKey != null) {
|
||||||
intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey);
|
intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (quality != null) {
|
if (quality != null) {
|
||||||
intent.putExtra(VideoPlayer.PLAYBACK_QUALITY, quality);
|
intent.putExtra(VideoPlayer.PLAYBACK_QUALITY, quality);
|
||||||
}
|
}
|
||||||
|
@ -90,17 +92,17 @@ public final class NavigationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Intent getPlayerIntent(@NonNull final Context context,
|
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
||||||
@NonNull final Class targetClazz,
|
@NonNull final Class<T> targetClazz,
|
||||||
@NonNull final PlayQueue playQueue,
|
@Nullable final PlayQueue playQueue,
|
||||||
final boolean resumePlayback) {
|
final boolean resumePlayback) {
|
||||||
return getPlayerIntent(context, targetClazz, playQueue, null, resumePlayback);
|
return getPlayerIntent(context, targetClazz, playQueue, null, resumePlayback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Intent getPlayerEnqueueIntent(@NonNull final Context context,
|
public static <T> Intent getPlayerEnqueueIntent(@NonNull final Context context,
|
||||||
@NonNull final Class targetClazz,
|
@NonNull final Class<T> targetClazz,
|
||||||
@NonNull final PlayQueue playQueue,
|
@Nullable final PlayQueue playQueue,
|
||||||
final boolean selectOnAppend,
|
final boolean selectOnAppend,
|
||||||
final boolean resumePlayback) {
|
final boolean resumePlayback) {
|
||||||
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
|
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
|
||||||
|
@ -109,9 +111,9 @@ public final class NavigationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Intent getPlayerIntent(@NonNull final Context context,
|
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
||||||
@NonNull final Class targetClazz,
|
@NonNull final Class<T> targetClazz,
|
||||||
@NonNull final PlayQueue playQueue,
|
@Nullable final PlayQueue playQueue,
|
||||||
final int repeatMode,
|
final int repeatMode,
|
||||||
final float playbackSpeed,
|
final float playbackSpeed,
|
||||||
final float playbackPitch,
|
final float playbackPitch,
|
||||||
|
@ -126,15 +128,13 @@ public final class NavigationHelper {
|
||||||
.putExtra(BasePlayer.IS_MUTED, isMuted);
|
.putExtra(BasePlayer.IS_MUTED, isMuted);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playOnMainPlayer(
|
public static void playOnMainPlayer(final AppCompatActivity activity,
|
||||||
final AppCompatActivity activity,
|
|
||||||
final PlayQueue queue,
|
final PlayQueue queue,
|
||||||
final boolean autoPlay) {
|
final boolean autoPlay) {
|
||||||
playOnMainPlayer(activity.getSupportFragmentManager(), queue, autoPlay);
|
playOnMainPlayer(activity.getSupportFragmentManager(), queue, autoPlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playOnMainPlayer(
|
public static void playOnMainPlayer(final FragmentManager fragmentManager,
|
||||||
final FragmentManager fragmentManager,
|
|
||||||
final PlayQueue queue,
|
final PlayQueue queue,
|
||||||
final boolean autoPlay) {
|
final boolean autoPlay) {
|
||||||
final PlayQueueItem currentStream = queue.getItem();
|
final PlayQueueItem currentStream = queue.getItem();
|
||||||
|
@ -148,7 +148,7 @@ public final class NavigationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playOnMainPlayer(@NonNull final Context context,
|
public static void playOnMainPlayer(@NonNull final Context context,
|
||||||
@NonNull final PlayQueue queue,
|
@Nullable final PlayQueue queue,
|
||||||
@NonNull final StreamingService.LinkType linkType,
|
@NonNull final StreamingService.LinkType linkType,
|
||||||
@NonNull final String url,
|
@NonNull final String url,
|
||||||
@NonNull final String title,
|
@NonNull final String title,
|
||||||
|
@ -553,18 +553,14 @@ public final class NavigationHelper {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent getBackgroundPlayerActivityIntent(final Context context) {
|
public static Intent getPlayQueueActivityIntent(final Context context) {
|
||||||
return getServicePlayerActivityIntent(context, BackgroundPlayerActivity.class);
|
final Intent intent = new Intent(context, BackgroundPlayerActivity.class);
|
||||||
}
|
|
||||||
|
|
||||||
private static Intent getServicePlayerActivityIntent(final Context context,
|
|
||||||
final Class activityClass) {
|
|
||||||
final Intent intent = new Intent(context, activityClass);
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
}
|
}
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Link handling
|
// Link handling
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
Loading…
Reference in New Issue