From 395cea51655f2d78ea188bfff136ef8eebe72473 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 4 May 2025 20:56:27 +0200 Subject: [PATCH] NavigationHelper: push out resumePlayback one layer --- .../player/notification/NotificationUtil.java | 3 +- .../schabi/newpipe/util/NavigationHelper.java | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index 30420b0c7..bb6ef3f5f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -256,7 +256,8 @@ public final class NotificationUtil { } else { // We are playing in fragment. Don't open another activity just show fragment. That's it final Intent intent = NavigationHelper.getPlayerIntent( - player.getContext(), MainActivity.class, null, true); + player.getContext(), MainActivity.class, null); + intent.putExtra(Player.RESUME_PLAYBACK, true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); 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 d4afaa6c2..72c3c82a4 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -84,8 +84,7 @@ public final class NavigationHelper { @NonNull public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, - @Nullable final PlayQueue playQueue, - final boolean resumePlayback) { + @Nullable final PlayQueue playQueue) { final Intent intent = new Intent(context, targetClazz); if (playQueue != null) { @@ -95,7 +94,6 @@ public final class NavigationHelper { } } intent.putExtra(Player.PLAYER_TYPE, PlayerType.MAIN.valueForIntent()); - intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback); intent.putExtra(PlayerService.SHOULD_START_FOREGROUND_EXTRA, true); return intent; @@ -107,17 +105,19 @@ public final class NavigationHelper { @Nullable final PlayQueue playQueue, final boolean resumePlayback, final boolean playWhenReady) { - return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) - .putExtra(Player.PLAY_WHEN_READY, playWhenReady); + return getPlayerIntent(context, targetClazz, playQueue) + .putExtra(Player.PLAY_WHEN_READY, playWhenReady) + .putExtra(Player.RESUME_PLAYBACK, resumePlayback); } @NonNull public static Intent getPlayerEnqueueNextIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue) { - // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false - return getPlayerIntent(context, targetClazz, playQueue, false) - .putExtra(Player.ENQUEUE_NEXT, true); + return getPlayerIntent(context, targetClazz, playQueue) + .putExtra(Player.ENQUEUE_NEXT, true) + // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false + .putExtra(Player.RESUME_PLAYBACK, false); } /* PLAY */ @@ -151,8 +151,9 @@ public final class NavigationHelper { Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show(); - final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback); - intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent()); + final Intent intent = getPlayerIntent(context, PlayerService.class, queue); + intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent()) + .putExtra(Player.RESUME_PLAYBACK, resumePlayback); ContextCompat.startForegroundService(context, intent); } @@ -162,8 +163,9 @@ public final class NavigationHelper { Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT) .show(); - final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback); + final Intent intent = getPlayerIntent(context, PlayerService.class, queue); intent.putExtra(Player.PLAYER_TYPE, PlayerType.AUDIO.valueForIntent()); + intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback); ContextCompat.startForegroundService(context, intent); } @@ -176,6 +178,7 @@ public final class NavigationHelper { } Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show(); + // when enqueueing `resumePlayback` is always `false` since: // - if there is a video already playing, the value of `resumePlayback` just doesn't make // any difference. @@ -183,8 +186,9 @@ public final class NavigationHelper { // slightly different behaviour than the normal play action: the latter resumes playback, // the former doesn't. (note that enqueue can be triggered when nothing is playing only // by long pressing the video detail fragment, playlist or channel controls - final Intent intent = getPlayerIntent(context, PlayerService.class, queue, false) - .putExtra(Player.ENQUEUE, true); + final Intent intent = getPlayerIntent(context, PlayerService.class, queue) + .putExtra(Player.ENQUEUE, true) + .putExtra(Player.RESUME_PLAYBACK, false); intent.putExtra(Player.PLAYER_TYPE, playerType.valueForIntent()); ContextCompat.startForegroundService(context, intent);