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 37598eb1a..d82566440 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 @@ -6,7 +6,6 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; -import androidx.preference.PreferenceManager; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -15,6 +14,7 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -29,6 +29,7 @@ import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.info_list.InfoListAdapter; +import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; @@ -36,6 +37,8 @@ import org.schabi.newpipe.util.StateSaver; import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.views.SuperScrollLayoutManager; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Queue; @@ -336,21 +339,26 @@ public abstract class BaseListFragment extends BaseStateFragment return; } + final ArrayList entries = new ArrayList<>(); + + if (PlayerHolder.getType() != null) { + entries.add(StreamDialogEntry.enqueue_stream); + } if (item.getStreamType() == StreamType.AUDIO_STREAM) { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); - } else { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, - StreamDialogEntry.enqueue_on_popup, + StreamDialogEntry.share + )); + } else { + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.start_here_on_popup, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); + StreamDialogEntry.share + )); } + StreamDialogEntry.setEnabledEntries(entries); new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), (dialog, which) -> StreamDialogEntry.clickOn(which, this, item)).show(); 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 38594553b..d52012491 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 @@ -33,6 +33,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.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; import org.schabi.newpipe.report.ErrorActivity; @@ -46,6 +47,7 @@ import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -151,25 +153,26 @@ public class PlaylistFragment extends BaseListInfoFragment { return; } + final ArrayList entries = new ArrayList<>(); + + if (PlayerHolder.getType() != null) { + entries.add(StreamDialogEntry.enqueue_stream); + } if (item.getStreamType() == StreamType.AUDIO_STREAM) { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); - } else { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, - StreamDialogEntry.enqueue_on_popup, + StreamDialogEntry.share + )); + } else { + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.start_here_on_popup, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); - - StreamDialogEntry.start_here_on_popup.setCustomAction((fragment, infoItem) -> - NavigationHelper.playOnPopupPlayer(context, - getPlayQueueStartingAt(infoItem), true)); + StreamDialogEntry.share + )); } + StreamDialogEntry.setEnabledEntries(entries); StreamDialogEntry.start_here_on_background.setCustomAction((fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer(context, 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 887e5d124..ff4b74a01 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 @@ -29,6 +29,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.BaseLocalListFragment; +import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; @@ -40,6 +41,7 @@ import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -387,27 +389,28 @@ public class StatisticsPlaylistFragment } final StreamInfoItem infoItem = item.toStreamInfoItem(); + final ArrayList entries = new ArrayList<>(); + + if (PlayerHolder.getType() != null) { + entries.add(StreamDialogEntry.enqueue_stream); + } if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.delete, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); - } else { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, - StreamDialogEntry.enqueue_on_popup, + StreamDialogEntry.share + )); + } else { + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.start_here_on_popup, StreamDialogEntry.delete, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); - - StreamDialogEntry.start_here_on_popup.setCustomAction((fragment, infoItemDuplicate) -> - NavigationHelper - .playOnPopupPlayer(context, getPlayQueueStartingAt(item), true)); + StreamDialogEntry.share + )); } + StreamDialogEntry.setEnabledEntries(entries); StreamDialogEntry.start_here_on_background.setCustomAction((fragment, infoItemDuplicate) -> NavigationHelper 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 3b66fd73f..26b1d3be6 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 @@ -36,6 +36,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.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; @@ -45,6 +46,7 @@ import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.StreamDialogEntry; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -756,29 +758,30 @@ public class LocalPlaylistFragment extends BaseLocalListFragment entries = new ArrayList<>(); + + if (PlayerHolder.getType() != null) { + entries.add(StreamDialogEntry.enqueue_stream); + } if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.set_as_playlist_thumbnail, StreamDialogEntry.delete, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); - } else { - StreamDialogEntry.setEnabledEntries( - StreamDialogEntry.enqueue_on_background, - StreamDialogEntry.enqueue_on_popup, + StreamDialogEntry.share + )); + } else { + entries.addAll(Arrays.asList( StreamDialogEntry.start_here_on_background, StreamDialogEntry.start_here_on_popup, StreamDialogEntry.set_as_playlist_thumbnail, StreamDialogEntry.delete, StreamDialogEntry.append_playlist, - StreamDialogEntry.share); - - StreamDialogEntry.start_here_on_popup.setCustomAction( - (fragment, infoItemDuplicate) -> NavigationHelper. - playOnPopupPlayer(context, getPlayQueueStartingAt(item), true)); + StreamDialogEntry.share + )); } + StreamDialogEntry.setEnabledEntries(entries); StreamDialogEntry.start_here_on_background.setCustomAction((fragment, infoItemDuplicate) -> NavigationHelper.playOnBackgroundPlayer(context, 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 f337080a4..d3844c941 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 @@ -38,6 +38,8 @@ public final class PlayerHolder { /** * Returns the current {@link MainPlayer.PlayerType} of the {@link MainPlayer} service, * otherwise `null` if no service running. + * + * @return Current PlayerType */ @Nullable public static MainPlayer.PlayerType getType() { 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 6c7be293e..26e3b440c 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -12,6 +12,7 @@ import org.schabi.newpipe.player.MainPlayer; import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; +import java.util.ArrayList; import java.util.Collections; public enum StreamDialogEntry { @@ -108,6 +109,10 @@ public enum StreamDialogEntry { // non-static methods to initialize and edit entries // /////////////////////////////////////////////////////// + public static void setEnabledEntries(final ArrayList entries) { + setEnabledEntries(entries.toArray(new StreamDialogEntry[0])); + } + /** * To be called before using {@link #setCustomAction(StreamDialogEntryAction)}. *