From c96a05a8f9e807d90b838f86af6a0faa5ace152e Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 14 Aug 2019 14:17:05 +0200 Subject: [PATCH] Customize "start here" actions in playlist item views Now those actions start playing the whole playlist from the chosen stream, instead of playing only the chosen stream. --- .../list/playlist/PlaylistFragment.java | 42 +++++++++++++++++++ .../history/StatisticsPlaylistFragment.java | 10 +++++ .../local/playlist/LocalPlaylistFragment.java | 9 ++++ 3 files changed, 61 insertions(+) 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 1bac54df8..b469be3b8 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 @@ -1,8 +1,11 @@ package org.schabi.newpipe.fragments.list.playlist; +import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.util.Log; @@ -26,7 +29,9 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +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.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; @@ -36,6 +41,7 @@ import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ImageDisplayConstants; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ShareUtils; +import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; @@ -130,6 +136,42 @@ public class PlaylistFragment extends BaseListInfoFragment { infoListAdapter.useMiniItemVariants(true); } + private PlayQueue getPlayQueueStartingAt(StreamInfoItem infoItem) { + return getPlayQueue(Math.max(infoListAdapter.getItemsList().indexOf(infoItem), 0)); + } + + @Override + protected void showStreamDialog(StreamInfoItem item) { + final Context context = getContext(); + final Activity activity = getActivity(); + if (context == null || context.getResources() == null || activity == null) return; + + if (item.getStreamType() == StreamType.AUDIO_STREAM) { + StreamDialogEntry.setEnabledEntries( + StreamDialogEntry.enqueue_on_background, + StreamDialogEntry.start_here_on_background, + StreamDialogEntry.append_playlist, + StreamDialogEntry.share); + } else { + StreamDialogEntry.setEnabledEntries( + StreamDialogEntry.enqueue_on_background, + StreamDialogEntry.enqueue_on_popup, + 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.start_here_on_background.setCustomAction( + (fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer(context, getPlayQueueStartingAt(infoItem), true)); + + new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), (dialog, which) -> + StreamDialogEntry.clickOn(which, this, item)).show(); + } + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + 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 f70da31d9..149dcfbdf 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 @@ -22,6 +22,7 @@ import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import org.schabi.newpipe.R; import org.schabi.newpipe.database.LocalItem; +import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; import org.schabi.newpipe.database.stream.StreamStatisticsEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; @@ -357,6 +358,10 @@ public class StatisticsPlaylistFragment startLoading(true); } + private PlayQueue getPlayQueueStartingAt(StreamStatisticsEntry infoItem) { + return getPlayQueue(Math.max(itemListAdapter.getItemsList().indexOf(infoItem), 0)); + } + private void showStreamDialog(final StreamStatisticsEntry item) { final Context context = getContext(); final Activity activity = getActivity(); @@ -379,8 +384,13 @@ public class StatisticsPlaylistFragment StreamDialogEntry.delete, StreamDialogEntry.append_playlist, StreamDialogEntry.share); + + StreamDialogEntry.start_here_on_popup.setCustomAction( + (fragment, infoItemDuplicate) -> NavigationHelper.playOnPopupPlayer(context, getPlayQueueStartingAt(item), true)); } + StreamDialogEntry.start_here_on_background.setCustomAction( + (fragment, infoItemDuplicate) -> NavigationHelper.playOnBackgroundPlayer(context, getPlayQueueStartingAt(item), true)); StreamDialogEntry.delete.setCustomAction((fragment, infoItemDuplicate) -> deleteEntry(Math.max(itemListAdapter.getItemsList().indexOf(item), 0))); 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 640174ab7..a8750ed47 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 @@ -511,6 +511,10 @@ public class LocalPlaylistFragment extends BaseLocalListFragment NavigationHelper.playOnPopupPlayer(context, getPlayQueueStartingAt(item), true)); } + StreamDialogEntry.start_here_on_background.setCustomAction( + (fragment, infoItemDuplicate) -> NavigationHelper.playOnBackgroundPlayer(context, getPlayQueueStartingAt(item), true)); StreamDialogEntry.set_as_playlist_thumbnail.setCustomAction( (fragment, infoItemDuplicate) -> changeThumbnailUrl(item.thumbnailUrl)); StreamDialogEntry.delete.setCustomAction(