Skip to content

Commit 8e32e7a

Browse files
authored
Merge pull request TeamNewPipe#12821 from HatakeKakashri/add_to_queue_menu_option
Add enqueue option to router dialog
2 parents 01dee9d + c596476 commit 8e32e7a

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

app/src/main/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ protected void onSuccess() {
316316
if (choiceChecker.isAvailableAndSelected(
317317
R.string.video_player_key,
318318
R.string.background_player_key,
319-
R.string.popup_player_key)) {
319+
R.string.popup_player_key,
320+
R.string.enqueue_key)) {
320321

321322
final String selectedChoice = choiceChecker.getSelectedChoiceKey();
322323

@@ -329,6 +330,8 @@ protected void onSuccess() {
329330
|| selectedChoice.equals(getString(R.string.popup_player_key));
330331
final boolean isAudioPlayerSelected =
331332
selectedChoice.equals(getString(R.string.background_player_key));
333+
final boolean isEnqueueSelected =
334+
selectedChoice.equals(getString(R.string.enqueue_key));
332335

333336
if (currentLinkType != LinkType.STREAM
334337
&& ((isExtAudioEnabled && isAudioPlayerSelected)
@@ -345,7 +348,9 @@ protected void onSuccess() {
345348

346349
// Check if the service supports the choice
347350
if ((isVideoPlayerSelected && capabilities.contains(VIDEO))
348-
|| (isAudioPlayerSelected && capabilities.contains(AUDIO))) {
351+
|| (isAudioPlayerSelected && capabilities.contains(AUDIO))
352+
|| (isEnqueueSelected && (capabilities.contains(VIDEO)
353+
|| capabilities.contains(AUDIO)))) {
349354
handleChoice(selectedChoice);
350355
} else {
351356
handleChoice(getString(R.string.show_info_key));
@@ -526,25 +531,36 @@ private List<AdapterChoiceItem> getChoicesForService(final StreamingService serv
526531
final List<StreamingService.ServiceInfo.MediaCapability> capabilities =
527532
service.getServiceInfo().getMediaCapabilities();
528533

529-
if (linkType == LinkType.STREAM) {
534+
if (linkType == LinkType.STREAM || linkType == LinkType.PLAYLIST) {
530535
if (capabilities.contains(VIDEO)) {
531536
returnedItems.add(videoPlayer);
532537
returnedItems.add(popupPlayer);
533538
}
534539
if (capabilities.contains(AUDIO)) {
535540
returnedItems.add(backgroundPlayer);
536541
}
537-
// download is redundant for linkType CHANNEL AND PLAYLIST (till playlist downloading is
538-
// not supported )
539-
returnedItems.add(new AdapterChoiceItem(getString(R.string.download_key),
540-
getString(R.string.download),
541-
R.drawable.ic_file_download));
542-
543-
// Add to playlist is not necessary for CHANNEL and PLAYLIST linkType since those can
544-
// not be added to a playlist
545-
returnedItems.add(new AdapterChoiceItem(getString(R.string.add_to_playlist_key),
546-
getString(R.string.add_to_playlist),
547-
R.drawable.ic_add));
542+
543+
// Enqueue is only shown if the current queue is not empty.
544+
// However, if the playqueue or the player is cleared after this item was chosen and
545+
// while the item is extracted, it will automatically fall back to background player.
546+
if (PlayerHolder.INSTANCE.getQueueSize() > 0) {
547+
returnedItems.add(new AdapterChoiceItem(getString(R.string.enqueue_key),
548+
getString(R.string.enqueue_stream), R.drawable.ic_add));
549+
}
550+
551+
if (linkType == LinkType.STREAM) {
552+
// download is redundant for linkType CHANNEL AND PLAYLIST
553+
// (till playlist downloading is not supported )
554+
returnedItems.add(new AdapterChoiceItem(getString(R.string.download_key),
555+
getString(R.string.download),
556+
R.drawable.ic_file_download));
557+
558+
// Add to playlist is not necessary for CHANNEL and PLAYLIST linkType
559+
// since those can not be added to a playlist
560+
returnedItems.add(new AdapterChoiceItem(getString(R.string.add_to_playlist_key),
561+
getString(R.string.add_to_playlist),
562+
R.drawable.ic_playlist_add));
563+
}
548564
} else {
549565
// LinkType.NONE is never present because it's filtered out before
550566
// channels and playlist can be played as they contain a list of videos
@@ -1016,6 +1032,8 @@ public Consumer<Info> getResultHandler(final Choice choice) {
10161032
NavigationHelper.playOnBackgroundPlayer(this, playQueue, true);
10171033
} else if (choice.playerChoice.equals(popupPlayerKey)) {
10181034
NavigationHelper.playOnPopupPlayer(this, playQueue, true);
1035+
} else if (choice.playerChoice.equals(getString(R.string.enqueue_key))) {
1036+
NavigationHelper.enqueueOnPlayer(this, playQueue);
10191037
}
10201038
};
10211039
}

app/src/main/res/values/settings_keys.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@
479479
<string name="popup_player_key">popup_player</string>
480480
<string name="download_key">download</string>
481481
<string name="add_to_playlist_key">add_to_playlist</string>
482+
<string name="enqueue_key">enqueue</string>
482483
<string name="always_ask_open_action_key">always_ask_player</string>
483484

484485
<string-array name="preferred_open_action_description_list">
@@ -488,6 +489,7 @@
488489
<item>@string/popup_player</item>
489490
<item>@string/download</item>
490491
<item>@string/add_to_playlist</item>
492+
<item>@string/enqueue_stream</item>
491493
<item>@string/always_ask_open_action</item>
492494
</string-array>
493495
<string-array name="preferred_open_action_values_list">
@@ -498,6 +500,7 @@
498500
<item>@string/download_key</item>
499501
<item>@string/add_to_playlist_key</item>
500502
<item>@string/always_ask_open_action_key</item>
503+
<item>@string/enqueue_key</item>
501504
</string-array>
502505

503506
<!-- Updates -->

0 commit comments

Comments
 (0)