diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java
index c80aa565819..f62cda2ddcd 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java
@@ -60,7 +60,6 @@
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.StreamInfo;
-import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.BackPressable;
@@ -68,7 +67,6 @@
import org.schabi.newpipe.fragments.EmptyFragment;
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
-import org.schabi.newpipe.info_list.InfoItemDialog;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.player.MainVideoPlayer;
@@ -93,7 +91,6 @@
import java.io.Serializable;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -534,42 +531,6 @@ protected void initListeners() {
detailControlsPopup.setOnTouchListener(getOnControlsTouchListener());
}
- private void showStreamDialog(final StreamInfoItem item) {
- final Context context = getContext();
- if (context == null || context.getResources() == null || getActivity() == null) return;
-
- final String[] commands = new String[]{
- context.getResources().getString(R.string.enqueue_on_background),
- context.getResources().getString(R.string.enqueue_on_popup),
- context.getResources().getString(R.string.append_playlist),
- context.getResources().getString(R.string.share)
- };
-
- final DialogInterface.OnClickListener actions = (DialogInterface dialogInterface, int i) -> {
- switch (i) {
- case 0:
- NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), true);
- break;
- case 1:
- NavigationHelper.enqueueOnPopupPlayer(getActivity(), new SinglePlayQueue(item), true);
- break;
- case 2:
- if (getFragmentManager() != null) {
- PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
- .show(getFragmentManager(), TAG);
- }
- break;
- case 3:
- ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl());
- break;
- default:
- break;
- }
- };
-
- new InfoItemDialog(getActivity(), item, commands, actions).show();
- }
-
private View.OnTouchListener getOnControlsTouchListener() {
return (View view, MotionEvent motionEvent) -> {
if (!PreferenceManager.getDefaultSharedPreferences(activity)
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java
index d9c58fbf4e0..279b396dfe2 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java
@@ -2,7 +2,6 @@
import android.app.Activity;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -25,19 +24,17 @@
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
+import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
import org.schabi.newpipe.info_list.InfoItemDialog;
import org.schabi.newpipe.info_list.InfoListAdapter;
-import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
-import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.OnClickGesture;
-import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.StateSaver;
+import org.schabi.newpipe.util.StreamDialogEntry;
-import java.util.Collections;
import java.util.List;
import java.util.Queue;
@@ -258,45 +255,32 @@ protected void onScrollToBottom() {
}
}
+
+
+
protected void showStreamDialog(final StreamInfoItem item) {
final Context context = getContext();
final Activity activity = getActivity();
- if (context == null || context.getResources() == null || getActivity() == null) return;
-
- final String[] commands = new String[]{
- context.getResources().getString(R.string.direct_on_background),
- context.getResources().getString(R.string.enqueue_on_background),
- context.getResources().getString(R.string.enqueue_on_popup),
- context.getResources().getString(R.string.append_playlist),
- context.getResources().getString(R.string.share)
- };
-
- final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
- switch (i) {
- case 0:
- NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item), true);
- break;
- case 1:
- NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), true);
- break;
- case 2:
- NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item), true);
- break;
- case 3:
- if (getFragmentManager() != null) {
- PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
- .show(getFragmentManager(), TAG);
- }
- break;
- case 4:
- ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl());
- break;
- default:
- break;
- }
- };
+ if (context == null || context.getResources() == null || activity == null) return;
+
+ if (item.getStreamType() == StreamType.AUDIO_STREAM) {
+ StreamDialogEntry.setEnabledEntries(
+ StreamDialogEntry.enqueue_on_background,
+ StreamDialogEntry.start_here_on_background,
+ StreamDialogEntry.append_playlist,
+ StreamDialogEntry.share);
+ } else {
+ StreamDialogEntry.setEnabledEntries(
+ StreamDialogEntry.enqueue_on_background,
+ StreamDialogEntry.enqueue_on_popup,
+ StreamDialogEntry.start_here_on_background,
+ StreamDialogEntry.start_here_on_popup,
+ StreamDialogEntry.append_playlist,
+ StreamDialogEntry.share);
+ }
- new InfoItemDialog(getActivity(), item, commands, actions).show();
+ new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), (dialog, which) ->
+ StreamDialogEntry.clickOn(which, this, item)).show();
}
/*//////////////////////////////////////////////////////////////////////////
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java
index 934e934e9e4..dd7916314a9 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java
@@ -1,8 +1,6 @@
package org.schabi.newpipe.fragments.list.channel;
-import android.app.Activity;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -34,12 +32,9 @@
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
-import org.schabi.newpipe.info_list.InfoItemDialog;
-import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.subscription.SubscriptionService;
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
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.AnimationUtils;
import org.schabi.newpipe.util.ExtractorHelper;
@@ -49,7 +44,6 @@
import org.schabi.newpipe.util.ShareUtils;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -150,56 +144,6 @@ protected View getListHeader() {
return headerRootLayout;
}
- @Override
- protected void showStreamDialog(final StreamInfoItem item) {
- final Activity activity = getActivity();
- final Context context = getContext();
- if (context == null || context.getResources() == null || getActivity() == null) return;
-
- final String[] commands = new String[]{
- context.getResources().getString(R.string.enqueue_on_background),
- context.getResources().getString(R.string.enqueue_on_popup),
- context.getResources().getString(R.string.start_here_on_main),
- context.getResources().getString(R.string.start_here_on_background),
- context.getResources().getString(R.string.start_here_on_popup),
- context.getResources().getString(R.string.append_playlist),
- context.getResources().getString(R.string.share)
- };
-
- final DialogInterface.OnClickListener actions = (DialogInterface dialogInterface, int i) -> {
- final int index = Math.max(infoListAdapter.getItemsList().indexOf(item), 0);
- switch (i) {
- case 0:
- NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), false);
- break;
- case 1:
- NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item), false);
- break;
- case 2:
- NavigationHelper.playOnMainPlayer(context, getPlayQueue(index), true);
- break;
- case 3:
- NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true);
- break;
- case 4:
- NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index), true);
- break;
- case 5:
- if (getFragmentManager() != null) {
- PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
- .show(getFragmentManager(), TAG);
- }
- break;
- case 6:
- ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl());
- break;
- default:
- break;
- }
- };
-
- new InfoItemDialog(getActivity(), item, commands, actions).show();
- }
/*//////////////////////////////////////////////////////////////////////////
// Menu
//////////////////////////////////////////////////////////////////////////*/
diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java
index 77aa0a25072..1bac54df80e 100644
--- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java
@@ -1,8 +1,5 @@
package org.schabi.newpipe.fragments.list.playlist;
-import android.app.Activity;
-import android.content.Context;
-import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -30,11 +27,9 @@
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
-import org.schabi.newpipe.info_list.InfoItemDialog;
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
-import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.ExtractorHelper;
@@ -135,50 +130,6 @@ protected void initViews(View rootView, Bundle savedInstanceState) {
infoListAdapter.useMiniItemVariants(true);
}
- @Override
- protected void showStreamDialog(final StreamInfoItem item) {
- final Context context = getContext();
- final Activity activity = getActivity();
- if (context == null || context.getResources() == null || getActivity() == null) return;
-
- final String[] commands = new String[]{
- context.getResources().getString(R.string.enqueue_on_background),
- context.getResources().getString(R.string.enqueue_on_popup),
- context.getResources().getString(R.string.start_here_on_main),
- context.getResources().getString(R.string.start_here_on_background),
- context.getResources().getString(R.string.start_here_on_popup),
- context.getResources().getString(R.string.share)
- };
-
- final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
- final int index = Math.max(infoListAdapter.getItemsList().indexOf(item), 0);
- switch (i) {
- case 0:
- NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), false);
- break;
- case 1:
- NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item), false);
- break;
- case 2:
- NavigationHelper.playOnMainPlayer(context, getPlayQueue(index), true);
- break;
- case 3:
- NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true);
- break;
- case 4:
- NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index), true);
- break;
- case 5:
- ShareUtils.shareUrl(requireContext(), item.getName(), item.getUrl());
- break;
- default:
- break;
- }
- };
-
- new InfoItemDialog(getActivity(), item, commands, actions).show();
- }
-
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu +
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 b97fdf8f21a..61f1c641873 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 @@
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;
@@ -25,6 +24,7 @@
import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
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.player.playqueue.PlayQueue;
@@ -34,7 +34,7 @@
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;
import java.util.ArrayList;
@@ -360,49 +360,32 @@ private void toggleSortMode() {
private void showStreamDialog(final StreamStatisticsEntry item) {
final Context context = getContext();
final Activity activity = getActivity();
- if (context == null || context.getResources() == null || getActivity() == null) return;
+ if (context == null || context.getResources() == null || activity == null) return;
final StreamInfoItem infoItem = item.toStreamInfoItem();
- final String[] commands = new String[]{
- context.getResources().getString(R.string.enqueue_on_background),
- context.getResources().getString(R.string.enqueue_on_popup),
- context.getResources().getString(R.string.start_here_on_main),
- context.getResources().getString(R.string.start_here_on_background),
- context.getResources().getString(R.string.start_here_on_popup),
- context.getResources().getString(R.string.delete),
- context.getResources().getString(R.string.share)
- };
+ if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
+ StreamDialogEntry.setEnabledEntries(
+ StreamDialogEntry.enqueue_on_background,
+ StreamDialogEntry.start_here_on_background,
+ StreamDialogEntry.delete,
+ StreamDialogEntry.append_playlist,
+ StreamDialogEntry.share);
+ } else {
+ StreamDialogEntry.setEnabledEntries(
+ StreamDialogEntry.enqueue_on_background,
+ StreamDialogEntry.enqueue_on_popup,
+ StreamDialogEntry.start_here_on_background,
+ StreamDialogEntry.start_here_on_popup,
+ StreamDialogEntry.delete,
+ StreamDialogEntry.append_playlist,
+ StreamDialogEntry.share);
+ }
- final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
- final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0);
- switch (i) {
- case 0:
- NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false);
- break;
- case 1:
- NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(infoItem), false);
- break;
- case 2:
- NavigationHelper.playOnMainPlayer(context, getPlayQueue(index), true);
- break;
- case 3:
- NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true);
- break;
- case 4:
- NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index), true);
- break;
- case 5:
- deleteEntry(index);
- break;
- case 6:
- ShareUtils.shareUrl(this.getContext(), item.toStreamInfoItem().getName(), item.toStreamInfoItem().getUrl());
- break;
- default:
- break;
- }
- };
+ StreamDialogEntry.delete.setCustomAction((fragment, infoItemDuplicate) ->
+ deleteEntry(Math.max(itemListAdapter.getItemsList().indexOf(item), 0)));
- new InfoItemDialog(getActivity(), infoItem, commands, actions).show();
+ new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) ->
+ StreamDialogEntry.clickOn(which, this, infoItem)).show();
}
private void deleteEntry(final int index) {
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 50101664254..640174ab70e 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 @@
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;
@@ -26,15 +25,16 @@
import org.schabi.newpipe.database.LocalItem;
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
-import org.schabi.newpipe.local.BaseLocalListFragment;
+import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.info_list.InfoItemDialog;
+import org.schabi.newpipe.local.BaseLocalListFragment;
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;
import java.util.Collections;
@@ -514,56 +514,36 @@ public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {}
protected void showStreamItemDialog(final PlaylistStreamEntry item) {
final Context context = getContext();
final Activity activity = getActivity();
- if (context == null || context.getResources() == null || getActivity() == null) return;
-
+ if (context == null || context.getResources() == null || activity == null) return;
final StreamInfoItem infoItem = item.toStreamInfoItem();
- final String[] commands = new String[]{
- context.getResources().getString(R.string.enqueue_on_background),
- context.getResources().getString(R.string.enqueue_on_popup),
- context.getResources().getString(R.string.start_here_on_main),
- context.getResources().getString(R.string.start_here_on_background),
- context.getResources().getString(R.string.start_here_on_popup),
- context.getResources().getString(R.string.set_as_playlist_thumbnail),
- context.getResources().getString(R.string.delete),
- context.getResources().getString(R.string.share)
- };
+ if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
+ StreamDialogEntry.setEnabledEntries(
+ StreamDialogEntry.enqueue_on_background,
+ StreamDialogEntry.start_here_on_background,
+ StreamDialogEntry.set_as_playlist_thumbnail,
+ StreamDialogEntry.delete,
+ StreamDialogEntry.append_playlist,
+ StreamDialogEntry.share);
+ } else {
+ StreamDialogEntry.setEnabledEntries(
+ StreamDialogEntry.enqueue_on_background,
+ StreamDialogEntry.enqueue_on_popup,
+ StreamDialogEntry.start_here_on_background,
+ StreamDialogEntry.start_here_on_popup,
+ StreamDialogEntry.set_as_playlist_thumbnail,
+ StreamDialogEntry.delete,
+ StreamDialogEntry.append_playlist,
+ StreamDialogEntry.share);
+ }
- final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
- final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0);
- switch (i) {
- case 0:
- NavigationHelper.enqueueOnBackgroundPlayer(context,
- new SinglePlayQueue(infoItem), false);
- break;
- case 1:
- NavigationHelper.enqueueOnPopupPlayer(activity, new
- SinglePlayQueue(infoItem), false);
- break;
- case 2:
- NavigationHelper.playOnMainPlayer(context, getPlayQueue(index), true);
- break;
- case 3:
- NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true);
- break;
- case 4:
- NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index), true);
- break;
- case 5:
- changeThumbnailUrl(item.thumbnailUrl);
- break;
- case 6:
- deleteItem(item);
- break;
- case 7:
- ShareUtils.shareUrl(this.getContext(), item.toStreamInfoItem().getName(), item.toStreamInfoItem().getUrl());
- break;
- default:
- break;
- }
- };
+ StreamDialogEntry.set_as_playlist_thumbnail.setCustomAction(
+ (fragment, infoItemDuplicate) -> changeThumbnailUrl(item.thumbnailUrl));
+ StreamDialogEntry.delete.setCustomAction(
+ (fragment, infoItemDuplicate) -> deleteItem(item));
- new InfoItemDialog(getActivity(), infoItem, commands, actions).show();
+ new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) ->
+ StreamDialogEntry.clickOn(which, this, infoItem)).show();
}
private void setInitialData(long playlistId, String name) {
diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java
index b00ea05ea7f..9a53e7e94cc 100644
--- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java
@@ -396,17 +396,17 @@ private void showLongTapDialog(ChannelInfoItem selectedItem) {
if (context == null || context.getResources() == null || getActivity() == null) return;
final String[] commands = new String[]{
- context.getResources().getString(R.string.share),
- context.getResources().getString(R.string.unsubscribe)
+ context.getResources().getString(R.string.unsubscribe),
+ context.getResources().getString(R.string.share)
};
final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
switch (i) {
case 0:
- shareChannel(selectedItem);
+ deleteChannel(selectedItem);
break;
case 1:
- deleteChannel(selectedItem);
+ shareChannel(selectedItem);
break;
default:
break;
diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
index 11434b29d6e..46e7c1fdc60 100644
--- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
+++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
@@ -288,8 +288,11 @@ public void handleIntent(Intent intent) {
if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET && isPlaybackResumeEnabled()) {
final Disposable stateLoader = recordManager.loadStreamState(item)
.observeOn(AndroidSchedulers.mainThread())
- .doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
- /*playOnInit=*/true))
+ .doFinally(() -> {
+ if (simpleExoPlayer == null) return; // doFinally called while closing
+ initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
+ /*playOnInit=*/true);
+ })
.subscribe(
state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()),
error -> {
@@ -331,6 +334,7 @@ public void destroyPlayer() {
simpleExoPlayer.removeListener(this);
simpleExoPlayer.stop();
simpleExoPlayer.release();
+ simpleExoPlayer = null;
}
if (isProgressLoopRunning()) stopProgressLoop();
if (playQueue != null) playQueue.dispose();
diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
new file mode 100644
index 00000000000..4ccd66f0dfe
--- /dev/null
+++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
@@ -0,0 +1,109 @@
+package org.schabi.newpipe.util;
+
+import android.content.Context;
+import android.support.v4.app.Fragment;
+
+import org.schabi.newpipe.R;
+import org.schabi.newpipe.extractor.stream.StreamInfoItem;
+import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
+import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
+
+import java.util.Collections;
+
+public enum StreamDialogEntry {
+ //////////////////////////////////////
+ // enum values with DEFAULT actions //
+ //////////////////////////////////////
+
+ enqueue_on_background(R.string.enqueue_on_background, (fragment, item) ->
+ NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), false)),
+
+ enqueue_on_popup(R.string.enqueue_on_popup, (fragment, item) ->
+ NavigationHelper.enqueueOnPopupPlayer(fragment.getContext(), new SinglePlayQueue(item), false)),
+
+ start_here_on_background(R.string.start_here_on_background, (fragment, item) ->
+ NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), true)),
+
+ start_here_on_popup(R.string.start_here_on_popup, (fragment, item) ->
+ NavigationHelper.playOnPopupPlayer(fragment.getContext(), new SinglePlayQueue(item), true)),
+
+ set_as_playlist_thumbnail(R.string.set_as_playlist_thumbnail, (fragment, item) -> {}), // has to be set manually
+
+ delete(R.string.delete, (fragment, item) -> {}), // has to be set manually
+
+ append_playlist(R.string.append_playlist, (fragment, item) -> {
+ if (fragment.getFragmentManager() != null) {
+ PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
+ .show(fragment.getFragmentManager(), "StreamDialogEntry@append_playlist");
+ }}),
+
+ share(R.string.share, (fragment, item) ->
+ ShareUtils.shareUrl(fragment.getContext(), item.getName(), item.getUrl()));
+
+
+ ///////////////
+ // variables //
+ ///////////////
+
+ public interface StreamDialogEntryAction {
+ void onClick(Fragment fragment, final StreamInfoItem infoItem);
+ }
+
+ private final int resource;
+ private final StreamDialogEntryAction defaultAction;
+ private StreamDialogEntryAction customAction;
+
+ private static StreamDialogEntry[] enabledEntries;
+
+
+ ///////////////////////////////////////////////////////
+ // non-static methods to initialize and edit entries //
+ ///////////////////////////////////////////////////////
+
+ StreamDialogEntry(final int resource, StreamDialogEntryAction defaultAction) {
+ this.resource = resource;
+ this.defaultAction = defaultAction;
+ this.customAction = null;
+ }
+
+ /**
+ * Can be used after {@link #setEnabledEntries(StreamDialogEntry...)} has been called
+ */
+ public void setCustomAction(StreamDialogEntryAction action) {
+ this.customAction = action;
+ }
+
+
+ ////////////////////////////////////////////////
+ // 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;
+ }
+
+ public static String[] getCommands(Context context) {
+ String[] commands = new String[enabledEntries.length];
+ for (int i = 0; i != enabledEntries.length; ++i) {
+ commands[i] = context.getResources().getString(enabledEntries[i].resource);
+ }
+
+ return commands;
+ }
+
+ public static void clickOn(int which, Fragment fragment, StreamInfoItem infoItem) {
+ if (enabledEntries[which].customAction == null) {
+ enabledEntries[which].defaultAction.onClick(fragment, infoItem);
+ } else {
+ enabledEntries[which].customAction.onClick(fragment, infoItem);
+ }
+ }
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1122a63e028..847f5fc49ea 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -391,7 +391,6 @@
Details
Audio Settings
Hold To enqueue
- Play directly in background
Enqueue in the background
Enqueue in a new popup
Start playing here