Skip to content

Commit 511cbaf

Browse files
committed
NavigationHelper: push out resumePlayback one layer
1 parent 1da9bba commit 511cbaf

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
@@ -256,7 +256,8 @@ private Intent getIntentForNotification() {
256256
} else {
257257
// We are playing in fragment. Don't open another activity just show fragment. That's it
258258
final Intent intent = NavigationHelper.getPlayerIntent(
259-
player.getContext(), MainActivity.class, null, true);
259+
player.getContext(), MainActivity.class, null);
260+
intent.putExtra(Player.RESUME_PLAYBACK, true);
260261
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
261262
intent.setAction(Intent.ACTION_MAIN);
262263
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

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

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

122122
/* PLAY */
@@ -150,8 +150,9 @@ public static void playOnPopupPlayer(final Context context,
150150

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

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

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

164-
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback);
165+
final Intent intent = getPlayerIntent(context, PlayerService.class, queue);
165166
intent.putExtra(Player.PLAYER_TYPE, PlayerType.AUDIO.valueForIntent());
167+
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
166168
ContextCompat.startForegroundService(context, intent);
167169
}
168170

@@ -175,15 +177,17 @@ public static void enqueueOnPlayer(final Context context,
175177
}
176178

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

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

0 commit comments

Comments
 (0)