From 70354eb73ed230460391a48723985509fec0e611 Mon Sep 17 00:00:00 2001 From: z3r0r4 <38572382+z3r0r4@users.noreply.github.com> Date: Sat, 18 Sep 2021 13:22:49 +0400 Subject: [PATCH] Add play next to long press menu & refactor enqueue methods (#6872) * added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings * changed line length for checkstyle pass * cleaned comments, moved strings * Update app/src/main/res/values/strings.xml to make long press entry more descriptive Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com> * Update app/src/main/res/values/strings.xml Co-authored-by: Stypox * replace redundant nextOnVideoPlayer methods Co-authored-by: Stypox * add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with add section comments * removed deprecated methods removed redundant methods * removed deprecated methods removed redundant methods * replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods * now works with playlists * renamed dialog entry * checking for >1 items in the queue using the PlayerHolder * making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio) * corrected strings * improve getQueueSize in PlayerHolder * long press to enqueue only if queue isnt empty * add Whitespace Co-authored-by: Stypox * clarify comments / add spaces * PlayerType as parameter of the enqueueOnPlayer method add Helper method * using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere / passing checkstyle * assimilated the enqueue*OnPlayer methods * removed redundant comment, variable * simplify code line Co-authored-by: Stypox * move if * replace workaround for isPlayerOpen() Co-authored-by: Stypox * replaced workarounds (getType), corrected static access with getInstance * remove unused imports * changed method call to original, new method doesnt exist yet. * Use getter method instead of property access syntax. * improve conditional for play next entry Co-authored-by: Stypox * show play next btn in feed fragment Co-authored-by: Stypox * add play next to local playlist and statistics fragment Co-authored-by: Stypox * formating Co-authored-by: Stypox * correcting logic Co-authored-by: Stypox * remove 2 year old unused string, formating Co-authored-by: Stypox * correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play. * remove player open checks from button long press enqueue actions * improve log msg * Rename next to enqueue_next * Refactor kotlin Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com> Co-authored-by: Stypox --- .../fragments/detail/VideoDetailFragment.java | 9 +- .../fragments/list/BaseListFragment.java | 8 +- .../list/channel/ChannelFragment.java | 5 +- .../list/playlist/PlaylistFragment.java | 12 ++- .../schabi/newpipe/local/feed/FeedFragment.kt | 7 +- .../history/StatisticsPlaylistFragment.java | 7 +- .../local/playlist/LocalPlaylistFragment.java | 11 ++- .../org/schabi/newpipe/player/Player.java | 20 ++-- .../newpipe/player/helper/PlayerHolder.java | 4 + .../schabi/newpipe/util/NavigationHelper.java | 94 ++++++++----------- .../newpipe/util/StreamDialogEntry.java | 27 ++---- app/src/main/res/values/strings.xml | 4 +- 12 files changed, 110 insertions(+), 98 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index ecf235abc..f206bb00a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -77,6 +77,7 @@ import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.dialog.PlaylistCreationDialog; import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.player.MainPlayer; +import org.schabi.newpipe.player.MainPlayer.PlayerType; import org.schabi.newpipe.player.Player; import org.schabi.newpipe.player.event.OnKeyDownListener; import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener; @@ -1096,8 +1097,8 @@ public final class VideoDetailFragment toggleFullscreenIfInFullscreenMode(); final PlayQueue queue = setupPlayQueueForIntent(append); - if (append) { - NavigationHelper.enqueueOnPopupPlayer(activity, queue, false); + if (append) { //resumePlayback: false + NavigationHelper.enqueueOnPlayer(activity, queue, PlayerType.POPUP); } else { replaceQueueIfUserConfirms(() -> NavigationHelper .playOnPopupPlayer(activity, queue, true)); @@ -1155,7 +1156,7 @@ public final class VideoDetailFragment final PlayQueue queue = setupPlayQueueForIntent(append); if (append) { - NavigationHelper.enqueueOnBackgroundPlayer(activity, queue, false); + NavigationHelper.enqueueOnPlayer(activity, queue, PlayerType.AUDIO); } else { replaceQueueIfUserConfirms(() -> NavigationHelper .playOnBackgroundPlayer(activity, queue, true)); @@ -1181,7 +1182,7 @@ public final class VideoDetailFragment addVideoPlayerView(); final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(), - MainPlayer.class, queue, true, autoPlayEnabled); + MainPlayer.class, queue, autoPlayEnabled); ContextCompat.startForegroundService(activity, playerIntent); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index ae661cfa3..c30b6fc05 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -350,12 +350,16 @@ public abstract class BaseListFragment extends BaseStateFragment if (context == null || context.getResources() == null || activity == null) { return; } - final List entries = new ArrayList<>(); - if (PlayerHolder.getInstance().getType() != null) { + if (PlayerHolder.getInstance().isPlayerOpen()) { entries.add(StreamDialogEntry.enqueue); + + if (PlayerHolder.getInstance().getQueueSize() > 1) { + entries.add(StreamDialogEntry.enqueue_next); + } } + if (item.getStreamType() == StreamType.AUDIO_STREAM) { entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 548ae7b2c..1d16559ac 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -37,6 +37,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.ktx.AnimationType; import org.schabi.newpipe.local.subscription.SubscriptionManager; +import org.schabi.newpipe.player.MainPlayer.PlayerType; import org.schabi.newpipe.player.playqueue.ChannelPlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.util.ExtractorHelper; @@ -495,12 +496,12 @@ public class ChannelFragment extends BaseListInfoFragment .playOnBackgroundPlayer(activity, getPlayQueue(), false)); playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> { - NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true); + NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.POPUP); return true; }); playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> { - NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true); + NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.AUDIO); return true; }); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 513fbbc91..f3aa2e306 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -37,6 +37,7 @@ import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; +import org.schabi.newpipe.player.MainPlayer.PlayerType; import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; @@ -148,9 +149,14 @@ public class PlaylistFragment extends BaseListInfoFragment { final ArrayList entries = new ArrayList<>(); - if (PlayerHolder.getInstance().getType() != null) { + if (PlayerHolder.getInstance().isPlayerOpen()) { entries.add(StreamDialogEntry.enqueue); + + if (PlayerHolder.getInstance().getQueueSize() > 1) { + entries.add(StreamDialogEntry.enqueue_next); + } } + if (item.getStreamType() == StreamType.AUDIO_STREAM) { entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, @@ -347,12 +353,12 @@ public class PlaylistFragment extends BaseListInfoFragment { NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false)); playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> { - NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true); + NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.POPUP); return true; }); playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> { - NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true); + NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.AUDIO); return true; }); } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 42fb8915d..b3619276d 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -326,9 +326,14 @@ class FeedFragment : BaseStateFragment() { if (context == null || context.resources == null || activity == null) return val entries = ArrayList() - if (PlayerHolder.getInstance().getType() != null) { + if (PlayerHolder.getInstance().isPlayerOpen) { entries.add(StreamDialogEntry.enqueue) + + if (PlayerHolder.getInstance().queueSize > 1) { + entries.add(StreamDialogEntry.enqueue_next) + } } + if (item.streamType == StreamType.AUDIO_STREAM) { entries.addAll( listOf( diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 6a7a300ca..9632b47f7 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -338,9 +338,14 @@ public class StatisticsPlaylistFragment final ArrayList entries = new ArrayList<>(); - if (PlayerHolder.getInstance().getType() != null) { + if (PlayerHolder.getInstance().isPlayerOpen()) { entries.add(StreamDialogEntry.enqueue); + + if (PlayerHolder.getInstance().getQueueSize() > 1) { + entries.add(StreamDialogEntry.enqueue_next); + } } + if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) { entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 40a7b26e2..21da9e571 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -42,6 +42,7 @@ import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.local.history.HistoryRecordManager; +import org.schabi.newpipe.player.MainPlayer.PlayerType; import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; @@ -493,12 +494,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { - NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true); + NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.POPUP); return true; }); playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> { - NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true); + NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.AUDIO); return true; }); @@ -752,8 +753,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment entries = new ArrayList<>(); - if (PlayerHolder.getInstance().getType() != null) { + if (PlayerHolder.getInstance().isPlayerOpen()) { entries.add(StreamDialogEntry.enqueue); + + if (PlayerHolder.getInstance().getQueueSize() > 1) { + entries.add(StreamDialogEntry.enqueue_next); + } } if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) { entries.addAll(Arrays.asList( diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index dd5468f69..cb6481011 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -226,10 +226,10 @@ public final class Player implements public static final String REPEAT_MODE = "repeat_mode"; public static final String PLAYBACK_QUALITY = "playback_quality"; public static final String PLAY_QUEUE_KEY = "play_queue_key"; - public static final String APPEND_ONLY = "append_only"; + public static final String ENQUEUE = "enqueue"; + public static final String ENQUEUE_NEXT = "enqueue_next"; public static final String RESUME_PLAYBACK = "resume_playback"; public static final String PLAY_WHEN_READY = "play_when_ready"; - public static final String SELECT_ON_APPEND = "select_on_append"; public static final String PLAYER_TYPE = "player_type"; public static final String IS_MUTED = "is_muted"; @@ -608,15 +608,17 @@ public final class Player implements setPlaybackQuality(intent.getStringExtra(PLAYBACK_QUALITY)); } - // Resolve append intents - if (intent.getBooleanExtra(APPEND_ONLY, false) && playQueue != null) { - final int sizeBeforeAppend = playQueue.size(); + // Resolve enqueue intents + if (intent.getBooleanExtra(ENQUEUE, false) && playQueue != null) { playQueue.append(newQueue.getStreams()); - if ((intent.getBooleanExtra(SELECT_ON_APPEND, false) - || currentState == STATE_COMPLETED) && newQueue.getStreams().size() > 0) { - playQueue.setIndex(sizeBeforeAppend); - } + return; + + // Resolve enqueue next intents + } else if (intent.getBooleanExtra(ENQUEUE_NEXT, false) && playQueue != null) { + final int currentIndex = playQueue.getIndex(); + playQueue.append(newQueue.getStreams()); + playQueue.move(playQueue.size() - 1, currentIndex + 1); return; } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java index 68de8ce9f..46239cab1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java @@ -70,6 +70,10 @@ public final class PlayerHolder { return player != null; } + public int getQueueSize() { + return isPlayerOpen() ? player.getPlayQueue().size() : 0; + } + public void setListener(@Nullable final PlayerServiceExtendedEventListener newListener) { listener = newListener; 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 eba24020f..fcdf0172d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -45,6 +45,8 @@ import org.schabi.newpipe.local.playlist.LocalPlaylistFragment; import org.schabi.newpipe.local.subscription.SubscriptionFragment; import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment; import org.schabi.newpipe.player.MainPlayer; +import org.schabi.newpipe.player.MainPlayer.PlayerType; +import org.schabi.newpipe.player.NotificationUtil; import org.schabi.newpipe.player.PlayQueueActivity; import org.schabi.newpipe.player.Player; import org.schabi.newpipe.player.helper.PlayerHelper; @@ -61,6 +63,7 @@ import static org.schabi.newpipe.util.external_communication.ShareUtils.installA public final class NavigationHelper { public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag"; public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag"; + private static final String TAG = NotificationUtil.class.getSimpleName(); private NavigationHelper() { } @@ -68,12 +71,11 @@ public final class NavigationHelper { /*////////////////////////////////////////////////////////////////////////// // Players //////////////////////////////////////////////////////////////////////////*/ - + /* INTENT */ @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) { @@ -82,7 +84,6 @@ public final class NavigationHelper { intent.putExtra(Player.PLAY_QUEUE_KEY, cacheKey); } } - intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback); intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal()); return intent; @@ -92,23 +93,28 @@ public final class NavigationHelper { public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue, - final boolean resumePlayback, final boolean playWhenReady) { - return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) + return getPlayerIntent(context, targetClazz, playQueue) .putExtra(Player.PLAY_WHEN_READY, playWhenReady); } @NonNull public static Intent getPlayerEnqueueIntent(@NonNull final Context context, @NonNull final Class targetClazz, - @Nullable final PlayQueue playQueue, - final boolean selectOnAppend, - final boolean resumePlayback) { - return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) - .putExtra(Player.APPEND_ONLY, true) - .putExtra(Player.SELECT_ON_APPEND, selectOnAppend); + @Nullable final PlayQueue playQueue) { + return getPlayerIntent(context, targetClazz, playQueue) + .putExtra(Player.ENQUEUE, true); } + @NonNull + public static Intent getPlayerEnqueueNextIntent(@NonNull final Context context, + @NonNull final Class targetClazz, + @Nullable final PlayQueue playQueue) { + return getPlayerIntent(context, targetClazz, playQueue) + .putExtra(Player.ENQUEUE_NEXT, true); + } + + /* PLAY */ public static void playOnMainPlayer(final AppCompatActivity activity, @NonNull final PlayQueue playQueue) { final PlayQueueItem item = playQueue.getItem(); @@ -154,56 +160,38 @@ public final class NavigationHelper { ContextCompat.startForegroundService(context, intent); } - public static void enqueueOnVideoPlayer(final Context context, final PlayQueue queue, - final boolean resumePlayback) { - enqueueOnVideoPlayer(context, queue, false, resumePlayback); - } - - public static void enqueueOnVideoPlayer(final Context context, final PlayQueue queue, - final boolean selectOnAppend, - final boolean resumePlayback) { - + /* ENQUEUE */ + public static void enqueueOnPlayer(final Context context, + final PlayQueue queue, + final PlayerType playerType) { Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show(); - final Intent intent = getPlayerEnqueueIntent( - context, MainPlayer.class, queue, selectOnAppend, resumePlayback); + final Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue); - intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal()); + intent.putExtra(Player.PLAYER_TYPE, playerType.ordinal()); ContextCompat.startForegroundService(context, intent); } - public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue, - final boolean resumePlayback) { - enqueueOnPopupPlayer(context, queue, false, resumePlayback); - } - - public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue, - final boolean selectOnAppend, - final boolean resumePlayback) { - if (!PermissionHelper.isPopupEnabled(context)) { - PermissionHelper.showPopupEnablementToast(context); - return; + public static void enqueueOnPlayer(final Context context, final PlayQueue queue) { + PlayerType playerType = PlayerHolder.getInstance().getType(); + if (!PlayerHolder.getInstance().isPlayerOpen()) { + Log.e(TAG, "Enqueueing but no player is open; defaulting to background player"); + playerType = MainPlayer.PlayerType.AUDIO; } - Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show(); - final Intent intent = getPlayerEnqueueIntent( - context, MainPlayer.class, queue, selectOnAppend, resumePlayback); - intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.POPUP.ordinal()); - ContextCompat.startForegroundService(context, intent); + enqueueOnPlayer(context, queue, playerType); } - public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue, - final boolean resumePlayback) { - enqueueOnBackgroundPlayer(context, queue, false, resumePlayback); - } + /* ENQUEUE NEXT */ + public static void enqueueNextOnPlayer(final Context context, final PlayQueue queue) { + PlayerType playerType = PlayerHolder.getInstance().getType(); + if (!PlayerHolder.getInstance().isPlayerOpen()) { + Log.e(TAG, "Enqueueing next but no player is open; defaulting to background player"); + playerType = MainPlayer.PlayerType.AUDIO; + } + Toast.makeText(context, R.string.enqueued_next, Toast.LENGTH_SHORT).show(); + final Intent intent = getPlayerEnqueueNextIntent(context, MainPlayer.class, queue); - public static void enqueueOnBackgroundPlayer(final Context context, - final PlayQueue queue, - final boolean selectOnAppend, - final boolean resumePlayback) { - Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show(); - final Intent intent = getPlayerEnqueueIntent( - context, MainPlayer.class, queue, selectOnAppend, resumePlayback); - intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.AUDIO.ordinal()); + intent.putExtra(Player.PLAYER_TYPE, playerType.ordinal()); ContextCompat.startForegroundService(context, intent); } @@ -346,7 +334,7 @@ public final class NavigationHelper { final boolean autoPlay; @Nullable final MainPlayer.PlayerType playerType = PlayerHolder.getInstance().getType(); - if (playerType == null) { + if (!PlayerHolder.getInstance().isPlayerOpen()) { // no player open autoPlay = PlayerHelper.isAutoplayAllowedByUser(context); } else if (switchingPlayers) { diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 6245d6f14..ec51cc370 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -12,8 +12,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.dialog.PlaylistCreationDialog; import org.schabi.newpipe.local.history.HistoryRecordManager; -import org.schabi.newpipe.player.MainPlayer; -import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.util.external_communication.KoreUtils; import org.schabi.newpipe.util.external_communication.ShareUtils; @@ -25,8 +23,6 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.schedulers.Schedulers; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; -import static org.schabi.newpipe.player.MainPlayer.PlayerType.AUDIO; -import static org.schabi.newpipe.player.MainPlayer.PlayerType.POPUP; public enum StreamDialogEntry { ////////////////////////////////////// @@ -43,7 +39,7 @@ public enum StreamDialogEntry { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { - NewPipeDatabase.getInstance(fragment.getContext()).streamDAO() + NewPipeDatabase.getInstance(fragment.requireContext()).streamDAO() .setUploaderUrl(serviceId, url, result.getUploaderUrl()) .subscribeOn(Schedulers.io()).subscribe(); openChannelFragment(fragment, item, result.getUploaderUrl()); @@ -64,18 +60,11 @@ public enum StreamDialogEntry { * Info: Add this entry within showStreamDialog. */ enqueue(R.string.enqueue_stream, (fragment, item) -> { - final MainPlayer.PlayerType type = PlayerHolder.getInstance().getType(); + NavigationHelper.enqueueOnPlayer(fragment.getContext(), new SinglePlayQueue(item)); + }), - if (type == AUDIO) { - NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(), - new SinglePlayQueue(item), false); - } else if (type == POPUP) { - NavigationHelper.enqueueOnPopupPlayer(fragment.getContext(), - new SinglePlayQueue(item), false); - } else /* type == VIDEO */ { - NavigationHelper.enqueueOnVideoPlayer(fragment.getContext(), - new SinglePlayQueue(item), false); - } + enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> { + NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), new SinglePlayQueue(item)); }), start_here_on_background(R.string.start_here_on_background, (fragment, item) -> @@ -108,16 +97,16 @@ public enum StreamDialogEntry { try { NavigationHelper.playWithKore(fragment.requireContext(), videoUrl); } catch (final Exception e) { - KoreUtils.showInstallKoreDialog(fragment.getActivity()); + KoreUtils.showInstallKoreDialog(fragment.requireActivity()); } }), share(R.string.share, (fragment, item) -> - ShareUtils.shareText(fragment.getContext(), item.getName(), item.getUrl(), + ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(), item.getThumbnailUrl())), open_in_browser(R.string.open_in_browser, (fragment, item) -> - ShareUtils.openUrlInBrowser(fragment.getContext(), item.getUrl())), + ShareUtils.openUrlInBrowser(fragment.requireContext(), item.getUrl())), mark_as_watched(R.string.mark_as_watched, (fragment, item) -> { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c0e25bb0..225ccd126 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -416,6 +416,8 @@ Show channel details Enqueue Enqueued + Enqueue next + Enqueued next Start playing in the background Start playing in a popup @@ -701,4 +703,4 @@ Error at Show Channel Details Loading Channel Details… - \ No newline at end of file +