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 1bac54df80e..b469be3b87b 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.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.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 @@ protected void initViews(View rootView, Bundle savedInstanceState) { 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 f70da31d988..149dcfbdf25 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.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 @@ private void toggleSortMode() { 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 @@ private void showStreamDialog(final StreamStatisticsEntry item) { 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 640174ab70e..a8750ed47d8 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 void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {} // Utils //////////////////////////////////////////////////////////////////////////*/ + private PlayQueue getPlayQueueStartingAt(PlaylistStreamEntry infoItem) { + return getPlayQueue(Math.max(itemListAdapter.getItemsList().indexOf(infoItem), 0)); + } + protected void showStreamItemDialog(final PlaylistStreamEntry item) { final Context context = getContext(); final Activity activity = getActivity(); @@ -535,8 +539,13 @@ protected void showStreamItemDialog(final PlaylistStreamEntry item) { 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.set_as_playlist_thumbnail.setCustomAction( (fragment, infoItemDuplicate) -> changeThumbnailUrl(item.thumbnailUrl)); StreamDialogEntry.delete.setCustomAction(