Ensure default actions cannot be overwritten permanently in StreamDialogEntry

This commit is contained in:
Stypox 2019-07-25 00:53:13 +02:00
parent 759e9846ad
commit 9df27f43de
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 27 additions and 16 deletions

View File

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

View File

@ -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<List<PlaylistSt
StreamDialogEntry.share);
}
StreamDialogEntry.set_as_playlist_thumbnail.setAction(
StreamDialogEntry.set_as_playlist_thumbnail.setCustomAction(
(fragment, infoItemDuplicate) -> changeThumbnailUrl(item.thumbnailUrl));
StreamDialogEntry.delete.setAction(
StreamDialogEntry.delete.setCustomAction(
(fragment, infoItemDuplicate) -> deleteItem(item));
new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) ->

View File

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