Skip to content

Commit 4836593

Browse files
committed
NavigationHelper: push out resumePlayback one layer
1 parent eec0793 commit 4836593

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ private Intent getIntentForNotification() {
254254
} else {
255255
// We are playing in fragment. Don't open another activity just show fragment. That's it
256256
final Intent intent = NavigationHelper.getPlayerIntent(
257-
player.getContext(), MainActivity.class, null, true);
257+
player.getContext(), MainActivity.class, null);
258+
intent.putExtra(Player.RESUME_PLAYBACK, true);
258259
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
259260
intent.setAction(Intent.ACTION_MAIN);
260261
intent.addCategory(Intent.CATEGORY_LAUNCHER);

app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ private NavigationHelper() {
8484
@NonNull
8585
public static <T> Intent getPlayerIntent(@NonNull final Context context,
8686
@NonNull final Class<T> targetClazz,
87-
@Nullable final PlayQueue playQueue,
88-
final boolean resumePlayback) {
87+
@Nullable final PlayQueue playQueue) {
8988
final Intent intent = new Intent(context, targetClazz);
9089

9190
if (playQueue != null) {
@@ -95,7 +94,6 @@ public static <T> Intent getPlayerIntent(@NonNull final Context context,
9594
}
9695
}
9796
intent.putExtra(Player.PLAYER_TYPE, PlayerType.MAIN.valueForIntent());
98-
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
9997
intent.putExtra(PlayerService.SHOULD_START_FOREGROUND_EXTRA, true);
10098

10199
return intent;
@@ -107,17 +105,19 @@ public static <T> Intent getPlayerIntent(@NonNull final Context context,
107105
@Nullable final PlayQueue playQueue,
108106
final boolean resumePlayback,
109107
final boolean playWhenReady) {
110-
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
111-
.putExtra(Player.PLAY_WHEN_READY, playWhenReady);
108+
return getPlayerIntent(context, targetClazz, playQueue)
109+
.putExtra(Player.PLAY_WHEN_READY, playWhenReady)
110+
.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
112111
}
113112

114113
@NonNull
115114
public static <T> Intent getPlayerEnqueueNextIntent(@NonNull final Context context,
116115
@NonNull final Class<T> targetClazz,
117116
@Nullable final PlayQueue playQueue) {
118-
// see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false
119-
return getPlayerIntent(context, targetClazz, playQueue, false)
120-
.putExtra(Player.ENQUEUE_NEXT, true);
117+
return getPlayerIntent(context, targetClazz, playQueue)
118+
.putExtra(Player.ENQUEUE_NEXT, true)
119+
// see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false
120+
.putExtra(Player.RESUME_PLAYBACK, false);
121121
}
122122

123123
/* PLAY */
@@ -151,8 +151,9 @@ public static void playOnPopupPlayer(final Context context,
151151

152152
Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
153153

154-
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback);
155-
intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent());
154+
final Intent intent = getPlayerIntent(context, PlayerService.class, queue);
155+
intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent())
156+
.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
156157
ContextCompat.startForegroundService(context, intent);
157158
}
158159

@@ -162,8 +163,9 @@ public static void playOnBackgroundPlayer(final Context context,
162163
Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT)
163164
.show();
164165

165-
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback);
166+
final Intent intent = getPlayerIntent(context, PlayerService.class, queue);
166167
intent.putExtra(Player.PLAYER_TYPE, PlayerType.AUDIO.valueForIntent());
168+
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
167169
ContextCompat.startForegroundService(context, intent);
168170
}
169171

@@ -176,15 +178,17 @@ public static void enqueueOnPlayer(final Context context,
176178
}
177179

178180
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show();
181+
179182
// when enqueueing `resumePlayback` is always `false` since:
180183
// - if there is a video already playing, the value of `resumePlayback` just doesn't make
181184
// any difference.
182185
// - if there is nothing already playing, it is useful for the enqueue action to have a
183186
// slightly different behaviour than the normal play action: the latter resumes playback,
184187
// the former doesn't. (note that enqueue can be triggered when nothing is playing only
185188
// by long pressing the video detail fragment, playlist or channel controls
186-
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, false)
187-
.putExtra(Player.ENQUEUE, true);
189+
final Intent intent = getPlayerIntent(context, PlayerService.class, queue)
190+
.putExtra(Player.ENQUEUE, true)
191+
.putExtra(Player.RESUME_PLAYBACK, false);
188192

189193
intent.putExtra(Player.PLAYER_TYPE, playerType.valueForIntent());
190194
ContextCompat.startForegroundService(context, intent);

0 commit comments

Comments
 (0)