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.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<I, N> extends BaseStateFragment<I>
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();
}

View File

@ -145,16 +145,8 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
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(

View File

@ -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<StreamDialogEntry> 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);
}
}
}

View File

@ -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<FeedState>() {
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()
}

View File

@ -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));

View File

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