Extract entries into beginning and end category

This commit is contained in:
TobiGr 2021-12-27 16:16:36 +01:00
parent 80157fc1be
commit 1cd3ef5dba
6 changed files with 39 additions and 61 deletions

View file

@ -35,7 +35,6 @@ import org.schabi.newpipe.info_list.InfoListAdapter;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.OnClickGesture;
import org.schabi.newpipe.util.StateSaver; import org.schabi.newpipe.util.StateSaver;
import org.schabi.newpipe.util.StreamDialogDefaultEntry;
import org.schabi.newpipe.views.SuperScrollLayoutManager; import org.schabi.newpipe.views.SuperScrollLayoutManager;
import java.util.List; import java.util.List;
@ -413,16 +412,8 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder( final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder(
activity, this, item); activity, this, item);
dialogBuilder.addEnqueueEntriesIfNeeded(); dialogBuilder.addDefaultEntriesAtBeginning();
dialogBuilder.addStartHereEntries(); dialogBuilder.addDefaultEntriesAtEnd();
dialogBuilder.addAllEntries(
StreamDialogDefaultEntry.APPEND_PLAYLIST,
StreamDialogDefaultEntry.SHARE,
StreamDialogDefaultEntry.OPEN_IN_BROWSER
);
dialogBuilder.addPlayWithKodiEntryIfNeeded();
dialogBuilder.addMarkAsWatchedEntryIfNeeded(item.getStreamType());
dialogBuilder.addChannelDetailsEntryIfPossible();
dialogBuilder.create().show(); dialogBuilder.create().show();
} }

View file

@ -145,16 +145,8 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder( final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder(
activity, this, item); activity, this, item);
dialogBuilder.addEnqueueEntriesIfNeeded(); dialogBuilder.addDefaultEntriesAtBeginning();
dialogBuilder.addStartHereEntries(); dialogBuilder.addDefaultEntriesAtEnd();
dialogBuilder.addAllEntries(
StreamDialogDefaultEntry.APPEND_PLAYLIST,
StreamDialogDefaultEntry.SHARE,
StreamDialogDefaultEntry.OPEN_IN_BROWSER
);
dialogBuilder.addPlayWithKodiEntryIfNeeded();
dialogBuilder.addMarkAsWatchedEntryIfNeeded(item.getStreamType());
dialogBuilder.addChannelDetailsEntryIfPossible();
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND, dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
(fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer( (fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer(

View file

@ -76,16 +76,16 @@ public final class InfoItemDialog {
*/ */
public static class Builder { public static class Builder {
@NonNull private final Activity activity; @NonNull private final Activity activity;
@NonNull private final StreamInfoItem info; @NonNull private final StreamInfoItem item;
@NonNull private final Fragment fragment; @NonNull private final Fragment fragment;
@NonNull private final List<StreamDialogEntry> entries = new ArrayList<>(); @NonNull private final List<StreamDialogEntry> entries = new ArrayList<>();
public Builder(@NonNull final Activity activity, public Builder(@NonNull final Activity activity,
@NonNull final Fragment fragment, @NonNull final Fragment fragment,
@NonNull final StreamInfoItem info) { @NonNull final StreamInfoItem item) {
this.activity = activity; this.activity = activity;
this.fragment = fragment; this.fragment = fragment;
this.info = info; this.item = item;
} }
public void addEntry(@NonNull final StreamDialogDefaultEntry entry) { public void addEntry(@NonNull final StreamDialogDefaultEntry entry) {
@ -108,7 +108,7 @@ public final class InfoItemDialog {
} }
public void addChannelDetailsEntryIfPossible() { public void addChannelDetailsEntryIfPossible() {
if (!isNullOrEmpty(info.getUploaderUrl())) { if (!isNullOrEmpty(item.getUploaderUrl())) {
addEntry(StreamDialogDefaultEntry.SHOW_CHANNEL_DETAILS); addEntry(StreamDialogDefaultEntry.SHOW_CHANNEL_DETAILS);
} }
} }
@ -125,8 +125,8 @@ public final class InfoItemDialog {
public void addStartHereEntries() { public void addStartHereEntries() {
addEntry(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND); addEntry(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND);
if (info.getStreamType() != StreamType.AUDIO_STREAM if (item.getStreamType() != StreamType.AUDIO_STREAM
&& info.getStreamType() != StreamType.AUDIO_LIVE_STREAM) { && item.getStreamType() != StreamType.AUDIO_LIVE_STREAM) {
addEntry(StreamDialogDefaultEntry.START_HERE_ON_POPUP); addEntry(StreamDialogDefaultEntry.START_HERE_ON_POPUP);
} }
} }
@ -148,17 +148,33 @@ public final class InfoItemDialog {
} }
public void addPlayWithKodiEntryIfNeeded() { public void addPlayWithKodiEntryIfNeeded() {
if (KoreUtils.shouldShowPlayWithKodi(activity, info.getServiceId())) { if (KoreUtils.shouldShowPlayWithKodi(activity, item.getServiceId())) {
addEntry(StreamDialogDefaultEntry.PLAY_WITH_KODI); 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}. * Creates the {@link InfoItemDialog}.
* @return a new instance of {@link InfoItemDialog} * @return a new instance of {@link InfoItemDialog}
*/ */
public InfoItemDialog create() { 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);
} }
} }
} }

View file

@ -80,7 +80,6 @@ import org.schabi.newpipe.local.subscription.SubscriptionManager
import org.schabi.newpipe.util.DeviceUtils import org.schabi.newpipe.util.DeviceUtils
import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.Localization
import org.schabi.newpipe.util.NavigationHelper 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.getGridSpanCountStreams
import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout
import java.time.OffsetDateTime import java.time.OffsetDateTime
@ -360,16 +359,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
val dialogBuilder = InfoItemDialog.Builder(activity, this, item) val dialogBuilder = InfoItemDialog.Builder(activity, this, item)
dialogBuilder.addEnqueueEntriesIfNeeded() dialogBuilder.addDefaultEntriesAtBeginning()
dialogBuilder.addStartHereEntries() dialogBuilder.addDefaultEntriesAtEnd()
dialogBuilder.addAllEntries(
StreamDialogDefaultEntry.APPEND_PLAYLIST,
StreamDialogDefaultEntry.SHARE,
StreamDialogDefaultEntry.OPEN_IN_BROWSER
)
dialogBuilder.addPlayWithKodiEntryIfNeeded()
dialogBuilder.addMarkAsWatchedEntryIfNeeded(item.streamType)
dialogBuilder.addChannelDetailsEntryIfPossible()
dialogBuilder.create().show() dialogBuilder.create().show()
} }

View file

@ -335,19 +335,12 @@ public class StatisticsPlaylistFragment
final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder( final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder(
activity, this, infoItem); activity, this, infoItem);
dialogBuilder.addEnqueueEntriesIfNeeded(); // set entries
dialogBuilder.addStartHereEntries(); dialogBuilder.addDefaultEntriesAtBeginning();
dialogBuilder.addAllEntries( dialogBuilder.addEntry(StreamDialogDefaultEntry.DELETE);
StreamDialogDefaultEntry.DELETE, dialogBuilder.addDefaultEntriesAtEnd();
StreamDialogDefaultEntry.APPEND_PLAYLIST,
StreamDialogDefaultEntry.SHARE,
StreamDialogDefaultEntry.OPEN_IN_BROWSER
);
dialogBuilder.addPlayWithKodiEntryIfNeeded();
dialogBuilder.addMarkAsWatchedEntryIfNeeded(infoItem.getStreamType());
dialogBuilder.addChannelDetailsEntryIfPossible();
// set custom actions
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND, dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
(fragment, infoItemDuplicate) -> NavigationHelper (fragment, infoItemDuplicate) -> NavigationHelper
.playOnBackgroundPlayer(context, getPlayQueueStartingAt(item), true)); .playOnBackgroundPlayer(context, getPlayQueueStartingAt(item), true));

View file

@ -750,18 +750,13 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder( final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder(
activity, this, infoItem); activity, this, infoItem);
dialogBuilder.addEnqueueEntriesIfNeeded(); // set entries
dialogBuilder.addStartHereEntries(); dialogBuilder.addDefaultEntriesAtBeginning();
dialogBuilder.addAllEntries( dialogBuilder.addAllEntries(
StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL, StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL,
StreamDialogDefaultEntry.DELETE, StreamDialogDefaultEntry.DELETE
StreamDialogDefaultEntry.APPEND_PLAYLIST,
StreamDialogDefaultEntry.SHARE,
StreamDialogDefaultEntry.OPEN_IN_BROWSER
); );
dialogBuilder.addPlayWithKodiEntryIfNeeded(); dialogBuilder.addDefaultEntriesAtEnd();
dialogBuilder.addMarkAsWatchedEntryIfNeeded(infoItem.getStreamType());
dialogBuilder.addChannelDetailsEntryIfPossible();
// set custom actions // set custom actions
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND, dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,