mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 16:40:32 +00:00
Add default entries automatically
This commit is contained in:
parent
1cd3ef5dba
commit
50e2385e82
@ -409,13 +409,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder(
|
new InfoItemDialog.Builder(activity, this, item).create().show();
|
||||||
activity, this, item);
|
|
||||||
|
|
||||||
dialogBuilder.addDefaultEntriesAtBeginning();
|
|
||||||
dialogBuilder.addDefaultEntriesAtEnd();
|
|
||||||
|
|
||||||
dialogBuilder.create().show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -145,9 +145,6 @@ 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.addDefaultEntriesAtBeginning();
|
|
||||||
dialogBuilder.addDefaultEntriesAtEnd();
|
|
||||||
|
|
||||||
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
|
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
|
||||||
(fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer(
|
(fragment, infoItem) -> NavigationHelper.playOnBackgroundPlayer(
|
||||||
context, getPlayQueueStartingAt(infoItem), true));
|
context, getPlayQueueStartingAt(infoItem), true));
|
||||||
|
@ -76,16 +76,39 @@ 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 item;
|
@NonNull private final StreamInfoItem infoItem;
|
||||||
@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<>();
|
||||||
|
private final boolean addDefaultEntriesAutomatically;
|
||||||
|
|
||||||
public Builder(@NonNull final Activity activity,
|
public Builder(@NonNull final Activity activity,
|
||||||
@NonNull final Fragment fragment,
|
@NonNull final Fragment fragment,
|
||||||
@NonNull final StreamInfoItem item) {
|
@NonNull final StreamInfoItem infoItem) {
|
||||||
|
this(activity, fragment, infoItem, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Create an instance of this Builder</p>
|
||||||
|
* @param activity
|
||||||
|
* @param fragment
|
||||||
|
* @param infoItem
|
||||||
|
* @param addDefaultEntriesAutomatically whether default entries added with
|
||||||
|
* {@link #addDefaultEntriesAtBeginning()} and
|
||||||
|
* {@link #addDefaultEntriesAtEnd()}
|
||||||
|
* are added automatically when generating
|
||||||
|
* the {@link InfoItemDialog}.
|
||||||
|
*/
|
||||||
|
public Builder(@NonNull final Activity activity,
|
||||||
|
@NonNull final Fragment fragment,
|
||||||
|
@NonNull final StreamInfoItem infoItem,
|
||||||
|
final boolean addDefaultEntriesAutomatically) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.fragment = fragment;
|
this.fragment = fragment;
|
||||||
this.item = item;
|
this.infoItem = infoItem;
|
||||||
|
this.addDefaultEntriesAutomatically = addDefaultEntriesAutomatically;
|
||||||
|
if (addDefaultEntriesAutomatically) {
|
||||||
|
addDefaultEntriesAtBeginning();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntry(@NonNull final StreamDialogDefaultEntry entry) {
|
public void addEntry(@NonNull final StreamDialogDefaultEntry entry) {
|
||||||
@ -98,17 +121,26 @@ public final class InfoItemDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Change an entries' action that is called when the entry is selected.</p>
|
||||||
|
* <p><strong>Warning:</strong> Only use this method when the entry has been already added.
|
||||||
|
* Changing the action of an entry which has not been added to the Builder yet
|
||||||
|
* does not have an effect.</p>
|
||||||
|
* @param entry the entry to change
|
||||||
|
* @param action the action to perform when the entry is selected
|
||||||
|
*/
|
||||||
public void setAction(@NonNull final StreamDialogDefaultEntry entry,
|
public void setAction(@NonNull final StreamDialogDefaultEntry entry,
|
||||||
@NonNull final StreamDialogEntry.StreamDialogEntryAction action) {
|
@NonNull final StreamDialogEntry.StreamDialogEntryAction action) {
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
if (entries.get(i).resource == entry.resource) {
|
if (entries.get(i).resource == entry.resource) {
|
||||||
entries.set(i, new StreamDialogEntry(entry.resource, action));
|
entries.set(i, new StreamDialogEntry(entry.resource, action));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChannelDetailsEntryIfPossible() {
|
public void addChannelDetailsEntryIfPossible() {
|
||||||
if (!isNullOrEmpty(item.getUploaderUrl())) {
|
if (!isNullOrEmpty(infoItem.getUploaderUrl())) {
|
||||||
addEntry(StreamDialogDefaultEntry.SHOW_CHANNEL_DETAILS);
|
addEntry(StreamDialogDefaultEntry.SHOW_CHANNEL_DETAILS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,8 +157,8 @@ public final class InfoItemDialog {
|
|||||||
|
|
||||||
public void addStartHereEntries() {
|
public void addStartHereEntries() {
|
||||||
addEntry(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND);
|
addEntry(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND);
|
||||||
if (item.getStreamType() != StreamType.AUDIO_STREAM
|
if (infoItem.getStreamType() != StreamType.AUDIO_STREAM
|
||||||
&& item.getStreamType() != StreamType.AUDIO_LIVE_STREAM) {
|
&& infoItem.getStreamType() != StreamType.AUDIO_LIVE_STREAM) {
|
||||||
addEntry(StreamDialogDefaultEntry.START_HERE_ON_POPUP);
|
addEntry(StreamDialogDefaultEntry.START_HERE_ON_POPUP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,21 +166,20 @@ public final class InfoItemDialog {
|
|||||||
/**
|
/**
|
||||||
* Adds {@link StreamDialogDefaultEntry.MARK_AS_WATCHED} if the watch history is enabled
|
* Adds {@link StreamDialogDefaultEntry.MARK_AS_WATCHED} if the watch history is enabled
|
||||||
* and the stream is not a livestream.
|
* and the stream is not a livestream.
|
||||||
* @param streamType the item's stream type
|
|
||||||
*/
|
*/
|
||||||
public void addMarkAsWatchedEntryIfNeeded(final StreamType streamType) {
|
public void addMarkAsWatchedEntryIfNeeded() {
|
||||||
final boolean isWatchHistoryEnabled = PreferenceManager
|
final boolean isWatchHistoryEnabled = PreferenceManager
|
||||||
.getDefaultSharedPreferences(activity)
|
.getDefaultSharedPreferences(activity)
|
||||||
.getBoolean(activity.getString(R.string.enable_watch_history_key), false);
|
.getBoolean(activity.getString(R.string.enable_watch_history_key), false);
|
||||||
if (streamType != StreamType.AUDIO_LIVE_STREAM
|
if (isWatchHistoryEnabled
|
||||||
&& streamType != StreamType.LIVE_STREAM
|
&& infoItem.getStreamType() != StreamType.LIVE_STREAM
|
||||||
&& isWatchHistoryEnabled) {
|
&& infoItem.getStreamType() != StreamType.AUDIO_LIVE_STREAM) {
|
||||||
addEntry(StreamDialogDefaultEntry.MARK_AS_WATCHED);
|
addEntry(StreamDialogDefaultEntry.MARK_AS_WATCHED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayWithKodiEntryIfNeeded() {
|
public void addPlayWithKodiEntryIfNeeded() {
|
||||||
if (KoreUtils.shouldShowPlayWithKodi(activity, item.getServiceId())) {
|
if (KoreUtils.shouldShowPlayWithKodi(activity, infoItem.getServiceId())) {
|
||||||
addEntry(StreamDialogDefaultEntry.PLAY_WITH_KODI);
|
addEntry(StreamDialogDefaultEntry.PLAY_WITH_KODI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,7 +196,7 @@ public final class InfoItemDialog {
|
|||||||
StreamDialogDefaultEntry.OPEN_IN_BROWSER
|
StreamDialogDefaultEntry.OPEN_IN_BROWSER
|
||||||
);
|
);
|
||||||
addPlayWithKodiEntryIfNeeded();
|
addPlayWithKodiEntryIfNeeded();
|
||||||
addMarkAsWatchedEntryIfNeeded(item.getStreamType());
|
addMarkAsWatchedEntryIfNeeded();
|
||||||
addChannelDetailsEntryIfPossible();
|
addChannelDetailsEntryIfPossible();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +205,10 @@ public final class 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.item, this.entries);
|
if (addDefaultEntriesAutomatically) {
|
||||||
|
addDefaultEntriesAtEnd();
|
||||||
|
}
|
||||||
|
return new InfoItemDialog(this.activity, this.fragment, this.infoItem, this.entries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,12 +357,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
val activity: Activity? = getActivity()
|
val activity: Activity? = getActivity()
|
||||||
if (context == null || context.resources == null || activity == null) return
|
if (context == null || context.resources == null || activity == null) return
|
||||||
|
|
||||||
val dialogBuilder = InfoItemDialog.Builder(activity, this, item)
|
InfoItemDialog.Builder(activity, this, item).create().show()
|
||||||
|
|
||||||
dialogBuilder.addDefaultEntriesAtBeginning()
|
|
||||||
dialogBuilder.addDefaultEntriesAtEnd()
|
|
||||||
|
|
||||||
dialogBuilder.create().show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val listenerStreamItem = object : OnItemClickListener, OnItemLongClickListener {
|
private val listenerStreamItem = object : OnItemClickListener, OnItemLongClickListener {
|
||||||
|
@ -335,10 +335,8 @@ public class StatisticsPlaylistFragment
|
|||||||
final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder(
|
final InfoItemDialog.Builder dialogBuilder = new InfoItemDialog.Builder(
|
||||||
activity, this, infoItem);
|
activity, this, infoItem);
|
||||||
|
|
||||||
// set entries
|
// set entries in the middle; the others are added automatically
|
||||||
dialogBuilder.addDefaultEntriesAtBeginning();
|
|
||||||
dialogBuilder.addEntry(StreamDialogDefaultEntry.DELETE);
|
dialogBuilder.addEntry(StreamDialogDefaultEntry.DELETE);
|
||||||
dialogBuilder.addDefaultEntriesAtEnd();
|
|
||||||
|
|
||||||
// set custom actions
|
// set custom actions
|
||||||
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
|
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
|
||||||
|
@ -750,15 +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);
|
||||||
|
|
||||||
// set entries
|
// add entries in the middle
|
||||||
dialogBuilder.addDefaultEntriesAtBeginning();
|
|
||||||
dialogBuilder.addAllEntries(
|
dialogBuilder.addAllEntries(
|
||||||
StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL,
|
StreamDialogDefaultEntry.SET_AS_PLAYLIST_THUMBNAIL,
|
||||||
StreamDialogDefaultEntry.DELETE
|
StreamDialogDefaultEntry.DELETE
|
||||||
);
|
);
|
||||||
dialogBuilder.addDefaultEntriesAtEnd();
|
|
||||||
|
|
||||||
// set custom actions
|
// set custom actions; all entries modified here have already been added within the builder
|
||||||
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
|
dialogBuilder.setAction(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND,
|
||||||
(fragment, infoItemDuplicate) -> NavigationHelper.playOnBackgroundPlayer(
|
(fragment, infoItemDuplicate) -> NavigationHelper.playOnBackgroundPlayer(
|
||||||
context, getPlayQueueStartingAt(item), true));
|
context, getPlayQueueStartingAt(item), true));
|
||||||
|
Loading…
Reference in New Issue
Block a user