From 1cd3ef5dba37a7b7a3358d5c47a80237cf3f85dc Mon Sep 17 00:00:00 2001 From: TobiGr Date: Mon, 27 Dec 2021 16:16:36 +0100 Subject: [PATCH] Extract entries into beginning and end category --- .../fragments/list/BaseListFragment.java | 13 ++------ .../list/playlist/PlaylistFragment.java | 12 ++----- .../newpipe/info_list/InfoItemDialog.java | 32 ++++++++++++++----- .../schabi/newpipe/local/feed/FeedFragment.kt | 13 ++------ .../history/StatisticsPlaylistFragment.java | 17 +++------- .../local/playlist/LocalPlaylistFragment.java | 13 +++----- 6 files changed, 39 insertions(+), 61 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 ec9e34964..1129baaec 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 @@ -35,7 +35,6 @@ import org.schabi.newpipe.info_list.InfoListAdapter; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.StateSaver; -import org.schabi.newpipe.util.StreamDialogDefaultEntry; import org.schabi.newpipe.views.SuperScrollLayoutManager; import java.util.List; @@ -413,16 +412,8 @@ public abstract class BaseListFragment extends BaseStateFragment final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder( activity, this, item); - dialogBuilder.addEnqueueEntriesIfNeeded(); - dialogBuilder.addStartHereEntries(); - dialogBuilder.addAllEntries( - StreamDialogDefaultEntry.APPEND_PLAYLIST, - StreamDialogDefaultEntry.SHARE, - StreamDialogDefaultEntry.OPEN_IN_BROWSER - ); - dialogBuilder.addPlayWithKodiEntryIfNeeded(); - dialogBuilder.addMarkAsWatchedEntryIfNeeded(item.getStreamType()); - dialogBuilder.addChannelDetailsEntryIfPossible(); + dialogBuilder.addDefaultEntriesAtBeginning(); + dialogBuilder.addDefaultEntriesAtEnd(); dialogBuilder.create().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 d90ea4e8c..26498f61a 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 @@ -145,16 +145,8 @@ public class PlaylistFragment extends BaseListInfoFragment { final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder( activity, this, item); - dialogBuilder.addEnqueueEntriesIfNeeded(); - dialogBuilder.addStartHereEntries(); - dialogBuilder.addAllEntries( - StreamDialogDefaultEntry.APPEND_PLAYLIST, - StreamDialogDefaultEntry.SHARE, - StreamDialogDefaultEntry.OPEN_IN_BROWSER - ); - dialogBuilder.addPlayWithKodiEntryIfNeeded(); - dialogBuilder.addMarkAsWatchedEntryIfNeeded(item.getStreamType()); - dialogBuilder.addChannelDetailsEntryIfPossible(); + dialogBuilder.addDefaultEntriesAtBeginning(); + dialogBuilder.addDefaultEntriesAtEnd(); dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND, (fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer( diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java index b5b17ab3e..fb7d40a3a 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemDialog.java @@ -76,16 +76,16 @@ public final class InfoItemDialog { */ public static class Builder { @NonNull private final Activity activity; - @NonNull private final StreamInfoItem info; + @NonNull private final StreamInfoItem item; @NonNull private final Fragment fragment; @NonNull private final List entries = new ArrayList<>(); public Builder(@NonNull final Activity activity, @NonNull final Fragment fragment, - @NonNull final StreamInfoItem info) { + @NonNull final StreamInfoItem item) { this.activity = activity; this.fragment = fragment; - this.info = info; + this.item = item; } public void addEntry(@NonNull final StreamDialogDefaultEntry entry) { @@ -108,7 +108,7 @@ public final class InfoItemDialog { } public void addChannelDetailsEntryIfPossible() { - if (!isNullOrEmpty(info.getUploaderUrl())) { + if (!isNullOrEmpty(item.getUploaderUrl())) { addEntry(StreamDialogDefaultEntry.SHOW_CHANNEL_DETAILS); } } @@ -125,8 +125,8 @@ public final class InfoItemDialog { public void addStartHereEntries() { addEntry(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND); - if (info.getStreamType() != StreamType.AUDIO_STREAM - && info.getStreamType() != StreamType.AUDIO_LIVE_STREAM) { + if (item.getStreamType() != StreamType.AUDIO_STREAM + && item.getStreamType() != StreamType.AUDIO_LIVE_STREAM) { addEntry(StreamDialogDefaultEntry.START_HERE_ON_POPUP); } } @@ -148,17 +148,33 @@ public final class InfoItemDialog { } public void addPlayWithKodiEntryIfNeeded() { - if (KoreUtils.shouldShowPlayWithKodi(activity, info.getServiceId())) { + if (KoreUtils.shouldShowPlayWithKodi(activity, item.getServiceId())) { addEntry(StreamDialogDefaultEntry.PLAY_WITH_KODI); } } + public void addDefaultEntriesAtBeginning() { + addEnqueueEntriesIfNeeded(); + addStartHereEntries(); + } + + public void addDefaultEntriesAtEnd() { + addAllEntries( + StreamDialogDefaultEntry.APPEND_PLAYLIST, + StreamDialogDefaultEntry.SHARE, + StreamDialogDefaultEntry.OPEN_IN_BROWSER + ); + addPlayWithKodiEntryIfNeeded(); + addMarkAsWatchedEntryIfNeeded(item.getStreamType()); + addChannelDetailsEntryIfPossible(); + } + /** * Creates the {@link InfoItemDialog}. * @return a new instance of {@link InfoItemDialog} */ public InfoItemDialog create() { - return new InfoItemDialog(this.activity, this.fragment, this.info, this.entries); + return new InfoItemDialog(this.activity, this.fragment, this.item, this.entries); } } } 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 78e765609..bda829907 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 @@ -80,7 +80,6 @@ import org.schabi.newpipe.local.subscription.SubscriptionManager import org.schabi.newpipe.util.DeviceUtils import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.NavigationHelper -import org.schabi.newpipe.util.StreamDialogDefaultEntry import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountStreams import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout import java.time.OffsetDateTime @@ -360,16 +359,8 @@ class FeedFragment : BaseStateFragment() { val dialogBuilder = InfoItemDialog.Builder(activity, this, item) - dialogBuilder.addEnqueueEntriesIfNeeded() - dialogBuilder.addStartHereEntries() - dialogBuilder.addAllEntries( - StreamDialogDefaultEntry.APPEND_PLAYLIST, - StreamDialogDefaultEntry.SHARE, - StreamDialogDefaultEntry.OPEN_IN_BROWSER - ) - dialogBuilder.addPlayWithKodiEntryIfNeeded() - dialogBuilder.addMarkAsWatchedEntryIfNeeded(item.streamType) - dialogBuilder.addChannelDetailsEntryIfPossible() + dialogBuilder.addDefaultEntriesAtBeginning() + dialogBuilder.addDefaultEntriesAtEnd() dialogBuilder.create().show() } 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 a11f1a589..542f7c631 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 @@ -335,19 +335,12 @@ public class StatisticsPlaylistFragment final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder( activity, this, infoItem); - dialogBuilder.addEnqueueEntriesIfNeeded(); - dialogBuilder.addStartHereEntries(); - dialogBuilder.addAllEntries( - StreamDialogDefaultEntry.DELETE, - StreamDialogDefaultEntry.APPEND_PLAYLIST, - StreamDialogDefaultEntry.SHARE, - StreamDialogDefaultEntry.OPEN_IN_BROWSER - ); - dialogBuilder.addPlayWithKodiEntryIfNeeded(); - dialogBuilder.addMarkAsWatchedEntryIfNeeded(infoItem.getStreamType()); - dialogBuilder.addChannelDetailsEntryIfPossible(); - + // set entries + dialogBuilder.addDefaultEntriesAtBeginning(); + dialogBuilder.addEntry(StreamDialogDefaultEntry.DELETE); + dialogBuilder.addDefaultEntriesAtEnd(); + // set custom actions dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND, (fragment, infoItemDuplicate) -> NavigationHelper .playOnBackgroundPlayer(context, getPlayQueueStartingAt(item), true)); 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 088577b25..f1f94eaac 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 @@ -750,18 +750,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment