Merge pull request #2368 from Stypox/menu-consistency
Make long-press menu consistent across views
This commit is contained in:
commit
4e5a20ec45
10 changed files with 195 additions and 280 deletions
|
@ -60,7 +60,6 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExt
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
import org.schabi.newpipe.extractor.stream.Stream;
|
import org.schabi.newpipe.extractor.stream.Stream;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
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.StreamType;
|
||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.fragments.BackPressable;
|
import org.schabi.newpipe.fragments.BackPressable;
|
||||||
|
@ -68,7 +67,6 @@ import org.schabi.newpipe.fragments.BaseStateFragment;
|
||||||
import org.schabi.newpipe.fragments.EmptyFragment;
|
import org.schabi.newpipe.fragments.EmptyFragment;
|
||||||
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
|
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
|
||||||
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
|
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.dialog.PlaylistAppendDialog;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.player.MainVideoPlayer;
|
import org.schabi.newpipe.player.MainVideoPlayer;
|
||||||
|
@ -93,7 +91,6 @@ import org.schabi.newpipe.views.AnimatedProgressBar;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -534,42 +531,6 @@ public class VideoDetailFragment
|
||||||
detailControlsPopup.setOnTouchListener(getOnControlsTouchListener());
|
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() {
|
private View.OnTouchListener getOnControlsTouchListener() {
|
||||||
return (View view, MotionEvent motionEvent) -> {
|
return (View view, MotionEvent motionEvent) -> {
|
||||||
if (!PreferenceManager.getDefaultSharedPreferences(activity)
|
if (!PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.schabi.newpipe.fragments.list;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
@ -25,19 +24,17 @@ import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
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.BaseStateFragment;
|
||||||
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
|
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
|
||||||
import org.schabi.newpipe.info_list.InfoItemDialog;
|
import org.schabi.newpipe.info_list.InfoItemDialog;
|
||||||
import org.schabi.newpipe.info_list.InfoListAdapter;
|
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.report.ErrorActivity;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
import org.schabi.newpipe.util.OnClickGesture;
|
||||||
import org.schabi.newpipe.util.ShareUtils;
|
|
||||||
import org.schabi.newpipe.util.StateSaver;
|
import org.schabi.newpipe.util.StateSaver;
|
||||||
|
import org.schabi.newpipe.util.StreamDialogEntry;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
@ -258,45 +255,32 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected void showStreamDialog(final StreamInfoItem item) {
|
protected void showStreamDialog(final StreamInfoItem item) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
if (context == null || context.getResources() == null || getActivity() == null) return;
|
if (context == null || context.getResources() == null || activity == null) return;
|
||||||
|
|
||||||
final String[] commands = new String[]{
|
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
context.getResources().getString(R.string.direct_on_background),
|
StreamDialogEntry.setEnabledEntries(
|
||||||
context.getResources().getString(R.string.enqueue_on_background),
|
StreamDialogEntry.enqueue_on_background,
|
||||||
context.getResources().getString(R.string.enqueue_on_popup),
|
StreamDialogEntry.start_here_on_background,
|
||||||
context.getResources().getString(R.string.append_playlist),
|
StreamDialogEntry.append_playlist,
|
||||||
context.getResources().getString(R.string.share)
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
|
new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), (dialog, which) ->
|
||||||
switch (i) {
|
StreamDialogEntry.clickOn(which, this, item)).show();
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
new InfoItemDialog(getActivity(), item, commands, actions).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package org.schabi.newpipe.fragments.list.channel;
|
package org.schabi.newpipe.fragments.list.channel;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -34,12 +32,9 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
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.local.subscription.SubscriptionService;
|
||||||
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
|
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
|
||||||
import org.schabi.newpipe.report.UserAction;
|
import org.schabi.newpipe.report.UserAction;
|
||||||
import org.schabi.newpipe.util.AnimationUtils;
|
import org.schabi.newpipe.util.AnimationUtils;
|
||||||
import org.schabi.newpipe.util.ExtractorHelper;
|
import org.schabi.newpipe.util.ExtractorHelper;
|
||||||
|
@ -49,7 +44,6 @@ import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.ShareUtils;
|
import org.schabi.newpipe.util.ShareUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -150,56 +144,6 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
|
||||||
return headerRootLayout;
|
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
|
// Menu
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package org.schabi.newpipe.fragments.list.playlist;
|
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.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
@ -30,11 +27,9 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
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.local.playlist.RemotePlaylistManager;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
|
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.ErrorActivity;
|
||||||
import org.schabi.newpipe.report.UserAction;
|
import org.schabi.newpipe.report.UserAction;
|
||||||
import org.schabi.newpipe.util.ExtractorHelper;
|
import org.schabi.newpipe.util.ExtractorHelper;
|
||||||
|
@ -135,50 +130,6 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
infoListAdapter.useMiniItemVariants(true);
|
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
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu +
|
if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu +
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.schabi.newpipe.local.history;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
@ -25,6 +24,7 @@ import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
|
import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
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.info_list.InfoItemDialog;
|
||||||
import org.schabi.newpipe.local.BaseLocalListFragment;
|
import org.schabi.newpipe.local.BaseLocalListFragment;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
|
@ -34,7 +34,7 @@ import org.schabi.newpipe.report.UserAction;
|
||||||
import org.schabi.newpipe.settings.SettingsActivity;
|
import org.schabi.newpipe.settings.SettingsActivity;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
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 org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -360,49 +360,32 @@ public class StatisticsPlaylistFragment
|
||||||
private void showStreamDialog(final StreamStatisticsEntry item) {
|
private void showStreamDialog(final StreamStatisticsEntry item) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final Activity activity = getActivity();
|
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 StreamInfoItem infoItem = item.toStreamInfoItem();
|
||||||
|
|
||||||
final String[] commands = new String[]{
|
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
context.getResources().getString(R.string.enqueue_on_background),
|
StreamDialogEntry.setEnabledEntries(
|
||||||
context.getResources().getString(R.string.enqueue_on_popup),
|
StreamDialogEntry.enqueue_on_background,
|
||||||
context.getResources().getString(R.string.start_here_on_main),
|
StreamDialogEntry.start_here_on_background,
|
||||||
context.getResources().getString(R.string.start_here_on_background),
|
StreamDialogEntry.delete,
|
||||||
context.getResources().getString(R.string.start_here_on_popup),
|
StreamDialogEntry.append_playlist,
|
||||||
context.getResources().getString(R.string.delete),
|
StreamDialogEntry.share);
|
||||||
context.getResources().getString(R.string.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) -> {
|
StreamDialogEntry.delete.setCustomAction((fragment, infoItemDuplicate) ->
|
||||||
final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0);
|
deleteEntry(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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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) {
|
private void deleteEntry(final int index) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.schabi.newpipe.local.playlist;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
@ -26,15 +25,16 @@ import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
|
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
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.info_list.InfoItemDialog;
|
||||||
|
import org.schabi.newpipe.local.BaseLocalListFragment;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||||
import org.schabi.newpipe.report.UserAction;
|
import org.schabi.newpipe.report.UserAction;
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.OnClickGesture;
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -514,56 +514,36 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
protected void showStreamItemDialog(final PlaylistStreamEntry item) {
|
protected void showStreamItemDialog(final PlaylistStreamEntry item) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final Activity activity = getActivity();
|
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 StreamInfoItem infoItem = item.toStreamInfoItem();
|
||||||
|
|
||||||
final String[] commands = new String[]{
|
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
context.getResources().getString(R.string.enqueue_on_background),
|
StreamDialogEntry.setEnabledEntries(
|
||||||
context.getResources().getString(R.string.enqueue_on_popup),
|
StreamDialogEntry.enqueue_on_background,
|
||||||
context.getResources().getString(R.string.start_here_on_main),
|
StreamDialogEntry.start_here_on_background,
|
||||||
context.getResources().getString(R.string.start_here_on_background),
|
StreamDialogEntry.set_as_playlist_thumbnail,
|
||||||
context.getResources().getString(R.string.start_here_on_popup),
|
StreamDialogEntry.delete,
|
||||||
context.getResources().getString(R.string.set_as_playlist_thumbnail),
|
StreamDialogEntry.append_playlist,
|
||||||
context.getResources().getString(R.string.delete),
|
StreamDialogEntry.share);
|
||||||
context.getResources().getString(R.string.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) -> {
|
StreamDialogEntry.set_as_playlist_thumbnail.setCustomAction(
|
||||||
final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0);
|
(fragment, infoItemDuplicate) -> changeThumbnailUrl(item.thumbnailUrl));
|
||||||
switch (i) {
|
StreamDialogEntry.delete.setCustomAction(
|
||||||
case 0:
|
(fragment, infoItemDuplicate) -> deleteItem(item));
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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) {
|
private void setInitialData(long playlistId, String name) {
|
||||||
|
|
|
@ -396,17 +396,17 @@ public class SubscriptionFragment extends BaseStateFragment<List<SubscriptionEnt
|
||||||
if (context == null || context.getResources() == null || getActivity() == null) return;
|
if (context == null || context.getResources() == null || getActivity() == null) return;
|
||||||
|
|
||||||
final String[] commands = new String[]{
|
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) -> {
|
final DialogInterface.OnClickListener actions = (dialogInterface, i) -> {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
shareChannel(selectedItem);
|
deleteChannel(selectedItem);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
deleteChannel(selectedItem);
|
shareChannel(selectedItem);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -288,8 +288,11 @@ public abstract class BasePlayer implements
|
||||||
if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET && isPlaybackResumeEnabled()) {
|
if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET && isPlaybackResumeEnabled()) {
|
||||||
final Disposable stateLoader = recordManager.loadStreamState(item)
|
final Disposable stateLoader = recordManager.loadStreamState(item)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
|
.doFinally(() -> {
|
||||||
/*playOnInit=*/true))
|
if (simpleExoPlayer == null) return; // doFinally called while closing
|
||||||
|
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
|
||||||
|
/*playOnInit=*/true);
|
||||||
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()),
|
state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()),
|
||||||
error -> {
|
error -> {
|
||||||
|
@ -331,6 +334,7 @@ public abstract class BasePlayer implements
|
||||||
simpleExoPlayer.removeListener(this);
|
simpleExoPlayer.removeListener(this);
|
||||||
simpleExoPlayer.stop();
|
simpleExoPlayer.stop();
|
||||||
simpleExoPlayer.release();
|
simpleExoPlayer.release();
|
||||||
|
simpleExoPlayer = null;
|
||||||
}
|
}
|
||||||
if (isProgressLoopRunning()) stopProgressLoop();
|
if (isProgressLoopRunning()) stopProgressLoop();
|
||||||
if (playQueue != null) playQueue.dispose();
|
if (playQueue != null) playQueue.dispose();
|
||||||
|
|
109
app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
Normal file
109
app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -391,7 +391,6 @@
|
||||||
<string name="play_queue_stream_detail">Details</string>
|
<string name="play_queue_stream_detail">Details</string>
|
||||||
<string name="play_queue_audio_settings">Audio Settings</string>
|
<string name="play_queue_audio_settings">Audio Settings</string>
|
||||||
<string name="hold_to_append">Hold To enqueue</string>
|
<string name="hold_to_append">Hold To enqueue</string>
|
||||||
<string name="direct_on_background">Play directly in background</string>
|
|
||||||
<string name="enqueue_on_background">Enqueue in the background</string>
|
<string name="enqueue_on_background">Enqueue in the background</string>
|
||||||
<string name="enqueue_on_popup">Enqueue in a new popup</string>
|
<string name="enqueue_on_popup">Enqueue in a new popup</string>
|
||||||
<string name="start_here_on_main">Start playing here</string>
|
<string name="start_here_on_main">Start playing here</string>
|
||||||
|
|
Loading…
Reference in a new issue