From 8b584f3922d16b1962ab843f2d18bd588aa898a0 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 29 May 2019 16:22:01 +0200 Subject: [PATCH] Make long-press menu consistent across views: fix #2354 Also made the code that creates the menus consistent across files. --- .../fragments/list/BaseListFragment.java | 16 +++++++---- .../list/channel/ChannelFragment.java | 10 ++----- .../list/playlist/PlaylistFragment.java | 15 ++++++---- .../history/StatisticsPlaylistFragment.java | 18 +++++++----- .../local/playlist/LocalPlaylistFragment.java | 28 ++++++++++--------- 5 files changed, 49 insertions(+), 38 deletions(-) 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 dbc3dd8a2..f031ad278 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 @@ -256,9 +256,10 @@ public abstract class BaseListFragment extends BaseStateFragment implem if (context == null || context.getResources() == null || getActivity() == null) return; final String[] commands = new String[]{ - context.getResources().getString(R.string.direct_on_background), context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), + context.getResources().getString(R.string.start_here_on_background), + context.getResources().getString(R.string.start_here_on_popup), context.getResources().getString(R.string.append_playlist), context.getResources().getString(R.string.share) }; @@ -266,21 +267,24 @@ public abstract class BaseListFragment extends BaseStateFragment implem final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { switch (i) { case 0: - NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item)); - break; - case 1: NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item)); break; - case 2: + case 1: NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); break; + case 2: + NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item)); + break; case 3: + NavigationHelper.playOnPopupPlayer(activity, new SinglePlayQueue(item)); + break; + case 4: if (getFragmentManager() != null) { PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) .show(getFragmentManager(), TAG); } break; - case 4: + case 5: ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); break; default: 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 71865b04d..2cb4d2c5f 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 @@ -159,7 +159,6 @@ public class ChannelFragment extends BaseListInfoFragment { final String[] commands = new String[]{ context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_main), context.getResources().getString(R.string.start_here_on_background), context.getResources().getString(R.string.start_here_on_popup), context.getResources().getString(R.string.append_playlist), @@ -176,21 +175,18 @@ public class ChannelFragment extends BaseListInfoFragment { NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; - case 5: + case 4: if (getFragmentManager() != null) { PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) .show(getFragmentManager(), TAG); } break; - case 6: + case 5: ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); break; default: 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 2a775fe8f..f16bf0be4 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 @@ -31,6 +31,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.InfoItemDialog; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; @@ -44,6 +45,7 @@ import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -144,9 +146,9 @@ public class PlaylistFragment extends BaseListInfoFragment { final String[] commands = new String[]{ context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_main), context.getResources().getString(R.string.start_here_on_background), context.getResources().getString(R.string.start_here_on_popup), + context.getResources().getString(R.string.append_playlist), context.getResources().getString(R.string.share) }; @@ -160,14 +162,17 @@ public class PlaylistFragment extends BaseListInfoFragment { NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; + case 4: + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) + .show(getFragmentManager(), TAG); + } + break; case 5: ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); break; 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 5a62a3969..841193fd0 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 @@ -27,6 +27,7 @@ import org.schabi.newpipe.database.stream.StreamStatisticsEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.BaseLocalListFragment; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; @@ -366,10 +367,10 @@ public class StatisticsPlaylistFragment final String[] commands = new String[]{ context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_main), context.getResources().getString(R.string.start_here_on_background), context.getResources().getString(R.string.start_here_on_popup), context.getResources().getString(R.string.delete), + context.getResources().getString(R.string.append_playlist), context.getResources().getString(R.string.share) }; @@ -383,19 +384,22 @@ public class StatisticsPlaylistFragment NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(infoItem)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; - case 5: + case 4: deleteEntry(index); break; + case 5: + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) + .show(getFragmentManager(), TAG); + } + break; case 6: - ShareUtils.shareUrl(this.getContext(), item.toStreamInfoItem().getName(), item.toStreamInfoItem().getUrl()); + ShareUtils.shareUrl(this.getContext(), infoItem.getName(), infoItem.getUrl()); break; default: break; 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 dc101fade..233ddbbdf 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 @@ -28,6 +28,7 @@ import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.info_list.InfoItemDialog; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; @@ -521,42 +522,43 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0); switch (i) { case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, - new SinglePlayQueue(infoItem)); + NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem)); break; case 1: - NavigationHelper.enqueueOnPopupPlayer(activity, new - SinglePlayQueue(infoItem)); + NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(infoItem)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; - case 5: + case 4: changeThumbnailUrl(item.thumbnailUrl); break; - case 6: + case 5: deleteItem(item); break; + case 6: + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) + .show(getFragmentManager(), TAG); + } + break; case 7: - ShareUtils.shareUrl(this.getContext(), item.toStreamInfoItem().getName(), item.toStreamInfoItem().getUrl()); + ShareUtils.shareUrl(this.getContext(), infoItem.getName(), infoItem.getUrl()); break; default: break;