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 7ebe2bbfc..61f1c6418 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 @@ -2,7 +2,6 @@ package org.schabi.newpipe.local.history; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -28,7 +27,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; 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; @@ -36,7 +34,6 @@ import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; -import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.util.ThemeHelper; @@ -384,7 +381,7 @@ public class StatisticsPlaylistFragment StreamDialogEntry.share); } - StreamDialogEntry.delete.setAction((fragment, infoItemDuplicate) -> + StreamDialogEntry.delete.setCustomAction((fragment, infoItemDuplicate) -> deleteEntry(Math.max(itemListAdapter.getItemsList().indexOf(item), 0))); new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) -> 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 db802272b..c0d8654b6 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 @@ -2,7 +2,6 @@ package org.schabi.newpipe.local.playlist; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -29,14 +28,12 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; 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; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; -import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.StreamDialogEntry; import java.util.ArrayList; @@ -540,9 +537,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment changeThumbnailUrl(item.thumbnailUrl)); - StreamDialogEntry.delete.setAction( + StreamDialogEntry.delete.setCustomAction( (fragment, infoItemDuplicate) -> deleteItem(item)); new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) -> diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index aed112983..1b503dbbb 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -11,9 +11,9 @@ import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import java.util.Collections; public enum StreamDialogEntry { - ////////////////////////////// - // enum values with actions // - ////////////////////////////// + ////////////////////////////////////// + // enum values with DEFAULT actions // + ////////////////////////////////////// enqueue_on_background(R.string.enqueue_on_background, (fragment, item) -> NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), false)), @@ -50,7 +50,8 @@ public enum StreamDialogEntry { } private final int resource; - private StreamDialogEntryAction action; + private final StreamDialogEntryAction action; + private StreamDialogEntryAction customAction; private static StreamDialogEntry[] enabledEntries; @@ -62,10 +63,14 @@ public enum StreamDialogEntry { StreamDialogEntry(final int resource, StreamDialogEntryAction action) { this.resource = resource; this.action = action; + this.customAction = null; } - public void setAction(StreamDialogEntryAction action) { - this.action = action; + /** + * Can be used after {@link #setEnabledEntries(StreamDialogEntry...)} has been called + */ + public void setCustomAction(StreamDialogEntryAction action) { + this.customAction = action; } @@ -73,7 +78,15 @@ public enum StreamDialogEntry { // static methods that act on enabled entries // //////////////////////////////////////////////// + /** + * To be called before using {@link #setCustomAction(StreamDialogEntryAction)} + */ public static void setEnabledEntries(StreamDialogEntry... entries) { + // cleanup from last time StreamDialogEntry was used + for (StreamDialogEntry streamDialogEntry : values()) { + streamDialogEntry.customAction = null; + } + enabledEntries = entries; } @@ -87,6 +100,10 @@ public enum StreamDialogEntry { } public static void clickOn(int which, Fragment fragment, StreamInfoItem infoItem) { - enabledEntries[which].action.onClick(fragment, infoItem); + if (enabledEntries[which].customAction == null) { + enabledEntries[which].action.onClick(fragment, infoItem); + } else { + enabledEntries[which].customAction.onClick(fragment, infoItem); + } } }