Add play next to long press menu & refactor enqueue methods (#6872)
* added mvp play next button in long press menu; new intent handling, new long press dialog entry, new dialog functions, new strings * changed line length for checkstyle pass * cleaned comments, moved strings * Update app/src/main/res/values/strings.xml to make long press entry more descriptive Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com> * Update app/src/main/res/values/strings.xml Co-authored-by: Stypox <stypox@pm.me> * replace redundant nextOnVideoPlayer methods Co-authored-by: Stypox <stypox@pm.me> * add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend and RESUME_PLAYBACK/ deprecate enqueueNextOn*Player and enqueueOn*Player methods add getPlayerIntent, getPlayerEnqueueIntent and getPlayerEnqueueNextIntent without selectOnAppend and RESUME_PLAYBACK/ deprecate those with add section comments * removed deprecated methods removed redundant methods * removed deprecated methods removed redundant methods * replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining enqueueOn*Player methods * now works with playlists * renamed dialog entry * checking for >1 items in the queue using the PlayerHolder * making enqueue*OnPlayer safe to call when no video is playing (defaulting to audio) * corrected strings * improve getQueueSize in PlayerHolder * long press to enqueue only if queue isnt empty * add Whitespace Co-authored-by: Stypox <stypox@pm.me> * clarify comments / add spaces * PlayerType as parameter of the enqueueOnPlayer method add Helper method * using the helper function everywhere (except for the background and popup long-press actions (also on playlists, history, ...)), so basically nowhere / passing checkstyle * assimilated the enqueue*OnPlayer methods * removed redundant comment, variable * simplify code line Co-authored-by: Stypox <stypox@pm.me> * move if * replace workaround for isPlayerOpen() Co-authored-by: Stypox <stypox@pm.me> * replaced workarounds (getType), corrected static access with getInstance * remove unused imports * changed method call to original, new method doesnt exist yet. * Use getter method instead of property access syntax. * improve conditional for play next entry Co-authored-by: Stypox <stypox@pm.me> * show play next btn in feed fragment Co-authored-by: Stypox <stypox@pm.me> * add play next to local playlist and statistics fragment Co-authored-by: Stypox <stypox@pm.me> * formating Co-authored-by: Stypox <stypox@pm.me> * correcting logic Co-authored-by: Stypox <stypox@pm.me> * remove 2 year old unused string, formating Co-authored-by: Stypox <stypox@pm.me> * correct enqueue (next) conditionals, default to background if no player is open. Dont generally default to background play. * remove player open checks from button long press enqueue actions * improve log msg * Rename next to enqueue_next * Refactor kotlin Co-authored-by: opusforlife2 <53176348+opusforlife2@users.noreply.github.com> Co-authored-by: Stypox <stypox@pm.me>
This commit is contained in:
parent
63083ac0c3
commit
70354eb73e
12 changed files with 110 additions and 98 deletions
|
@ -77,6 +77,7 @@ import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
||||||
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.player.MainPlayer;
|
import org.schabi.newpipe.player.MainPlayer;
|
||||||
|
import org.schabi.newpipe.player.MainPlayer.PlayerType;
|
||||||
import org.schabi.newpipe.player.Player;
|
import org.schabi.newpipe.player.Player;
|
||||||
import org.schabi.newpipe.player.event.OnKeyDownListener;
|
import org.schabi.newpipe.player.event.OnKeyDownListener;
|
||||||
import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener;
|
import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener;
|
||||||
|
@ -1096,8 +1097,8 @@ public final class VideoDetailFragment
|
||||||
toggleFullscreenIfInFullscreenMode();
|
toggleFullscreenIfInFullscreenMode();
|
||||||
|
|
||||||
final PlayQueue queue = setupPlayQueueForIntent(append);
|
final PlayQueue queue = setupPlayQueueForIntent(append);
|
||||||
if (append) {
|
if (append) { //resumePlayback: false
|
||||||
NavigationHelper.enqueueOnPopupPlayer(activity, queue, false);
|
NavigationHelper.enqueueOnPlayer(activity, queue, PlayerType.POPUP);
|
||||||
} else {
|
} else {
|
||||||
replaceQueueIfUserConfirms(() -> NavigationHelper
|
replaceQueueIfUserConfirms(() -> NavigationHelper
|
||||||
.playOnPopupPlayer(activity, queue, true));
|
.playOnPopupPlayer(activity, queue, true));
|
||||||
|
@ -1155,7 +1156,7 @@ public final class VideoDetailFragment
|
||||||
|
|
||||||
final PlayQueue queue = setupPlayQueueForIntent(append);
|
final PlayQueue queue = setupPlayQueueForIntent(append);
|
||||||
if (append) {
|
if (append) {
|
||||||
NavigationHelper.enqueueOnBackgroundPlayer(activity, queue, false);
|
NavigationHelper.enqueueOnPlayer(activity, queue, PlayerType.AUDIO);
|
||||||
} else {
|
} else {
|
||||||
replaceQueueIfUserConfirms(() -> NavigationHelper
|
replaceQueueIfUserConfirms(() -> NavigationHelper
|
||||||
.playOnBackgroundPlayer(activity, queue, true));
|
.playOnBackgroundPlayer(activity, queue, true));
|
||||||
|
@ -1181,7 +1182,7 @@ public final class VideoDetailFragment
|
||||||
addVideoPlayerView();
|
addVideoPlayerView();
|
||||||
|
|
||||||
final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(),
|
final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(),
|
||||||
MainPlayer.class, queue, true, autoPlayEnabled);
|
MainPlayer.class, queue, autoPlayEnabled);
|
||||||
ContextCompat.startForegroundService(activity, playerIntent);
|
ContextCompat.startForegroundService(activity, playerIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -350,12 +350,16 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
|
||||||
if (context == null || context.getResources() == null || activity == null) {
|
if (context == null || context.getResources() == null || activity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<StreamDialogEntry> entries = new ArrayList<>();
|
final List<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getInstance().getType() != null) {
|
if (PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
|
|
||||||
|
if (PlayerHolder.getInstance().getQueueSize() > 1) {
|
||||||
|
entries.add(StreamDialogEntry.enqueue_next);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
entries.addAll(Arrays.asList(
|
entries.addAll(Arrays.asList(
|
||||||
StreamDialogEntry.start_here_on_background,
|
StreamDialogEntry.start_here_on_background,
|
||||||
|
|
|
@ -37,6 +37,7 @@ 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.ktx.AnimationType;
|
import org.schabi.newpipe.ktx.AnimationType;
|
||||||
import org.schabi.newpipe.local.subscription.SubscriptionManager;
|
import org.schabi.newpipe.local.subscription.SubscriptionManager;
|
||||||
|
import org.schabi.newpipe.player.MainPlayer.PlayerType;
|
||||||
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.util.ExtractorHelper;
|
import org.schabi.newpipe.util.ExtractorHelper;
|
||||||
|
@ -495,12 +496,12 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
|
||||||
.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
||||||
|
|
||||||
playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> {
|
playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> {
|
||||||
NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true);
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.POPUP);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> {
|
playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> {
|
||||||
NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true);
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.AUDIO);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
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.info_list.InfoItemDialog;
|
||||||
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
|
||||||
|
import org.schabi.newpipe.player.MainPlayer.PlayerType;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHolder;
|
import org.schabi.newpipe.player.helper.PlayerHolder;
|
||||||
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;
|
||||||
|
@ -148,9 +149,14 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
|
|
||||||
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getInstance().getType() != null) {
|
if (PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
|
|
||||||
|
if (PlayerHolder.getInstance().getQueueSize() > 1) {
|
||||||
|
entries.add(StreamDialogEntry.enqueue_next);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
entries.addAll(Arrays.asList(
|
entries.addAll(Arrays.asList(
|
||||||
StreamDialogEntry.start_here_on_background,
|
StreamDialogEntry.start_here_on_background,
|
||||||
|
@ -347,12 +353,12 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
||||||
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
||||||
|
|
||||||
playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> {
|
playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> {
|
||||||
NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true);
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.POPUP);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> {
|
playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> {
|
||||||
NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true);
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.AUDIO);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -326,9 +326,14 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
||||||
if (context == null || context.resources == null || activity == null) return
|
if (context == null || context.resources == null || activity == null) return
|
||||||
|
|
||||||
val entries = ArrayList<StreamDialogEntry>()
|
val entries = ArrayList<StreamDialogEntry>()
|
||||||
if (PlayerHolder.getInstance().getType() != null) {
|
if (PlayerHolder.getInstance().isPlayerOpen) {
|
||||||
entries.add(StreamDialogEntry.enqueue)
|
entries.add(StreamDialogEntry.enqueue)
|
||||||
|
|
||||||
|
if (PlayerHolder.getInstance().queueSize > 1) {
|
||||||
|
entries.add(StreamDialogEntry.enqueue_next)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (item.streamType == StreamType.AUDIO_STREAM) {
|
if (item.streamType == StreamType.AUDIO_STREAM) {
|
||||||
entries.addAll(
|
entries.addAll(
|
||||||
listOf(
|
listOf(
|
||||||
|
|
|
@ -338,9 +338,14 @@ public class StatisticsPlaylistFragment
|
||||||
|
|
||||||
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getInstance().getType() != null) {
|
if (PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
|
|
||||||
|
if (PlayerHolder.getInstance().getQueueSize() > 1) {
|
||||||
|
entries.add(StreamDialogEntry.enqueue_next);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
entries.addAll(Arrays.asList(
|
entries.addAll(Arrays.asList(
|
||||||
StreamDialogEntry.start_here_on_background,
|
StreamDialogEntry.start_here_on_background,
|
||||||
|
|
|
@ -42,6 +42,7 @@ 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.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
|
import org.schabi.newpipe.player.MainPlayer.PlayerType;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHolder;
|
import org.schabi.newpipe.player.helper.PlayerHolder;
|
||||||
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;
|
||||||
|
@ -493,12 +494,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false));
|
||||||
|
|
||||||
playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> {
|
playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> {
|
||||||
NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true);
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.POPUP);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> {
|
playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> {
|
||||||
NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true);
|
NavigationHelper.enqueueOnPlayer(activity, getPlayQueue(), PlayerType.AUDIO);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -752,8 +753,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
|
|
||||||
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getInstance().getType() != null) {
|
if (PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
|
|
||||||
|
if (PlayerHolder.getInstance().getQueueSize() > 1) {
|
||||||
|
entries.add(StreamDialogEntry.enqueue_next);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
entries.addAll(Arrays.asList(
|
entries.addAll(Arrays.asList(
|
||||||
|
|
|
@ -226,10 +226,10 @@ public final class Player implements
|
||||||
public static final String REPEAT_MODE = "repeat_mode";
|
public static final String REPEAT_MODE = "repeat_mode";
|
||||||
public static final String PLAYBACK_QUALITY = "playback_quality";
|
public static final String PLAYBACK_QUALITY = "playback_quality";
|
||||||
public static final String PLAY_QUEUE_KEY = "play_queue_key";
|
public static final String PLAY_QUEUE_KEY = "play_queue_key";
|
||||||
public static final String APPEND_ONLY = "append_only";
|
public static final String ENQUEUE = "enqueue";
|
||||||
|
public static final String ENQUEUE_NEXT = "enqueue_next";
|
||||||
public static final String RESUME_PLAYBACK = "resume_playback";
|
public static final String RESUME_PLAYBACK = "resume_playback";
|
||||||
public static final String PLAY_WHEN_READY = "play_when_ready";
|
public static final String PLAY_WHEN_READY = "play_when_ready";
|
||||||
public static final String SELECT_ON_APPEND = "select_on_append";
|
|
||||||
public static final String PLAYER_TYPE = "player_type";
|
public static final String PLAYER_TYPE = "player_type";
|
||||||
public static final String IS_MUTED = "is_muted";
|
public static final String IS_MUTED = "is_muted";
|
||||||
|
|
||||||
|
@ -608,15 +608,17 @@ public final class Player implements
|
||||||
setPlaybackQuality(intent.getStringExtra(PLAYBACK_QUALITY));
|
setPlaybackQuality(intent.getStringExtra(PLAYBACK_QUALITY));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve append intents
|
// Resolve enqueue intents
|
||||||
if (intent.getBooleanExtra(APPEND_ONLY, false) && playQueue != null) {
|
if (intent.getBooleanExtra(ENQUEUE, false) && playQueue != null) {
|
||||||
final int sizeBeforeAppend = playQueue.size();
|
|
||||||
playQueue.append(newQueue.getStreams());
|
playQueue.append(newQueue.getStreams());
|
||||||
|
|
||||||
if ((intent.getBooleanExtra(SELECT_ON_APPEND, false)
|
return;
|
||||||
|| currentState == STATE_COMPLETED) && newQueue.getStreams().size() > 0) {
|
|
||||||
playQueue.setIndex(sizeBeforeAppend);
|
// Resolve enqueue next intents
|
||||||
}
|
} else if (intent.getBooleanExtra(ENQUEUE_NEXT, false) && playQueue != null) {
|
||||||
|
final int currentIndex = playQueue.getIndex();
|
||||||
|
playQueue.append(newQueue.getStreams());
|
||||||
|
playQueue.move(playQueue.size() - 1, currentIndex + 1);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,10 @@ public final class PlayerHolder {
|
||||||
return player != null;
|
return player != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getQueueSize() {
|
||||||
|
return isPlayerOpen() ? player.getPlayQueue().size() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
public void setListener(@Nullable final PlayerServiceExtendedEventListener newListener) {
|
public void setListener(@Nullable final PlayerServiceExtendedEventListener newListener) {
|
||||||
listener = newListener;
|
listener = newListener;
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
|
||||||
import org.schabi.newpipe.local.subscription.SubscriptionFragment;
|
import org.schabi.newpipe.local.subscription.SubscriptionFragment;
|
||||||
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
|
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment;
|
||||||
import org.schabi.newpipe.player.MainPlayer;
|
import org.schabi.newpipe.player.MainPlayer;
|
||||||
|
import org.schabi.newpipe.player.MainPlayer.PlayerType;
|
||||||
|
import org.schabi.newpipe.player.NotificationUtil;
|
||||||
import org.schabi.newpipe.player.PlayQueueActivity;
|
import org.schabi.newpipe.player.PlayQueueActivity;
|
||||||
import org.schabi.newpipe.player.Player;
|
import org.schabi.newpipe.player.Player;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHelper;
|
import org.schabi.newpipe.player.helper.PlayerHelper;
|
||||||
|
@ -61,6 +63,7 @@ import static org.schabi.newpipe.util.external_communication.ShareUtils.installA
|
||||||
public final class NavigationHelper {
|
public final class NavigationHelper {
|
||||||
public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag";
|
public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag";
|
||||||
public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag";
|
public static final String SEARCH_FRAGMENT_TAG = "search_fragment_tag";
|
||||||
|
private static final String TAG = NotificationUtil.class.getSimpleName();
|
||||||
|
|
||||||
private NavigationHelper() {
|
private NavigationHelper() {
|
||||||
}
|
}
|
||||||
|
@ -68,12 +71,11 @@ public final class NavigationHelper {
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Players
|
// Players
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
/* INTENT */
|
||||||
@NonNull
|
@NonNull
|
||||||
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
||||||
@NonNull final Class<T> targetClazz,
|
@NonNull final Class<T> targetClazz,
|
||||||
@Nullable final PlayQueue playQueue,
|
@Nullable final PlayQueue playQueue) {
|
||||||
final boolean resumePlayback) {
|
|
||||||
final Intent intent = new Intent(context, targetClazz);
|
final Intent intent = new Intent(context, targetClazz);
|
||||||
|
|
||||||
if (playQueue != null) {
|
if (playQueue != null) {
|
||||||
|
@ -82,7 +84,6 @@ public final class NavigationHelper {
|
||||||
intent.putExtra(Player.PLAY_QUEUE_KEY, cacheKey);
|
intent.putExtra(Player.PLAY_QUEUE_KEY, cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
|
|
||||||
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal());
|
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal());
|
||||||
|
|
||||||
return intent;
|
return intent;
|
||||||
|
@ -92,23 +93,28 @@ public final class NavigationHelper {
|
||||||
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
public static <T> Intent getPlayerIntent(@NonNull final Context context,
|
||||||
@NonNull final Class<T> targetClazz,
|
@NonNull final Class<T> targetClazz,
|
||||||
@Nullable final PlayQueue playQueue,
|
@Nullable final PlayQueue playQueue,
|
||||||
final boolean resumePlayback,
|
|
||||||
final boolean playWhenReady) {
|
final boolean playWhenReady) {
|
||||||
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
|
return getPlayerIntent(context, targetClazz, playQueue)
|
||||||
.putExtra(Player.PLAY_WHEN_READY, playWhenReady);
|
.putExtra(Player.PLAY_WHEN_READY, playWhenReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static <T> Intent getPlayerEnqueueIntent(@NonNull final Context context,
|
public static <T> Intent getPlayerEnqueueIntent(@NonNull final Context context,
|
||||||
@NonNull final Class<T> targetClazz,
|
@NonNull final Class<T> targetClazz,
|
||||||
@Nullable final PlayQueue playQueue,
|
@Nullable final PlayQueue playQueue) {
|
||||||
final boolean selectOnAppend,
|
return getPlayerIntent(context, targetClazz, playQueue)
|
||||||
final boolean resumePlayback) {
|
.putExtra(Player.ENQUEUE, true);
|
||||||
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
|
|
||||||
.putExtra(Player.APPEND_ONLY, true)
|
|
||||||
.putExtra(Player.SELECT_ON_APPEND, selectOnAppend);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static <T> Intent getPlayerEnqueueNextIntent(@NonNull final Context context,
|
||||||
|
@NonNull final Class<T> targetClazz,
|
||||||
|
@Nullable final PlayQueue playQueue) {
|
||||||
|
return getPlayerIntent(context, targetClazz, playQueue)
|
||||||
|
.putExtra(Player.ENQUEUE_NEXT, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PLAY */
|
||||||
public static void playOnMainPlayer(final AppCompatActivity activity,
|
public static void playOnMainPlayer(final AppCompatActivity activity,
|
||||||
@NonNull final PlayQueue playQueue) {
|
@NonNull final PlayQueue playQueue) {
|
||||||
final PlayQueueItem item = playQueue.getItem();
|
final PlayQueueItem item = playQueue.getItem();
|
||||||
|
@ -154,56 +160,38 @@ public final class NavigationHelper {
|
||||||
ContextCompat.startForegroundService(context, intent);
|
ContextCompat.startForegroundService(context, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enqueueOnVideoPlayer(final Context context, final PlayQueue queue,
|
/* ENQUEUE */
|
||||||
final boolean resumePlayback) {
|
public static void enqueueOnPlayer(final Context context,
|
||||||
enqueueOnVideoPlayer(context, queue, false, resumePlayback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void enqueueOnVideoPlayer(final Context context, final PlayQueue queue,
|
|
||||||
final boolean selectOnAppend,
|
|
||||||
final boolean resumePlayback) {
|
|
||||||
|
|
||||||
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show();
|
|
||||||
final Intent intent = getPlayerEnqueueIntent(
|
|
||||||
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
|
|
||||||
|
|
||||||
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal());
|
|
||||||
ContextCompat.startForegroundService(context, intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue,
|
|
||||||
final boolean resumePlayback) {
|
|
||||||
enqueueOnPopupPlayer(context, queue, false, resumePlayback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue,
|
|
||||||
final boolean selectOnAppend,
|
|
||||||
final boolean resumePlayback) {
|
|
||||||
if (!PermissionHelper.isPopupEnabled(context)) {
|
|
||||||
PermissionHelper.showPopupEnablementToast(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show();
|
|
||||||
final Intent intent = getPlayerEnqueueIntent(
|
|
||||||
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
|
|
||||||
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.POPUP.ordinal());
|
|
||||||
ContextCompat.startForegroundService(context, intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue,
|
|
||||||
final boolean resumePlayback) {
|
|
||||||
enqueueOnBackgroundPlayer(context, queue, false, resumePlayback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void enqueueOnBackgroundPlayer(final Context context,
|
|
||||||
final PlayQueue queue,
|
final PlayQueue queue,
|
||||||
final boolean selectOnAppend,
|
final PlayerType playerType) {
|
||||||
final boolean resumePlayback) {
|
|
||||||
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show();
|
||||||
final Intent intent = getPlayerEnqueueIntent(
|
final Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue);
|
||||||
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
|
|
||||||
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.AUDIO.ordinal());
|
intent.putExtra(Player.PLAYER_TYPE, playerType.ordinal());
|
||||||
|
ContextCompat.startForegroundService(context, intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enqueueOnPlayer(final Context context, final PlayQueue queue) {
|
||||||
|
PlayerType playerType = PlayerHolder.getInstance().getType();
|
||||||
|
if (!PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
|
Log.e(TAG, "Enqueueing but no player is open; defaulting to background player");
|
||||||
|
playerType = MainPlayer.PlayerType.AUDIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
enqueueOnPlayer(context, queue, playerType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ENQUEUE NEXT */
|
||||||
|
public static void enqueueNextOnPlayer(final Context context, final PlayQueue queue) {
|
||||||
|
PlayerType playerType = PlayerHolder.getInstance().getType();
|
||||||
|
if (!PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
|
Log.e(TAG, "Enqueueing next but no player is open; defaulting to background player");
|
||||||
|
playerType = MainPlayer.PlayerType.AUDIO;
|
||||||
|
}
|
||||||
|
Toast.makeText(context, R.string.enqueued_next, Toast.LENGTH_SHORT).show();
|
||||||
|
final Intent intent = getPlayerEnqueueNextIntent(context, MainPlayer.class, queue);
|
||||||
|
|
||||||
|
intent.putExtra(Player.PLAYER_TYPE, playerType.ordinal());
|
||||||
ContextCompat.startForegroundService(context, intent);
|
ContextCompat.startForegroundService(context, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +334,7 @@ public final class NavigationHelper {
|
||||||
|
|
||||||
final boolean autoPlay;
|
final boolean autoPlay;
|
||||||
@Nullable final MainPlayer.PlayerType playerType = PlayerHolder.getInstance().getType();
|
@Nullable final MainPlayer.PlayerType playerType = PlayerHolder.getInstance().getType();
|
||||||
if (playerType == null) {
|
if (!PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
// no player open
|
// no player open
|
||||||
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
||||||
} else if (switchingPlayers) {
|
} else if (switchingPlayers) {
|
||||||
|
|
|
@ -12,8 +12,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
|
||||||
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.player.MainPlayer;
|
|
||||||
import org.schabi.newpipe.player.helper.PlayerHolder;
|
|
||||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||||
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
||||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||||
|
@ -25,8 +23,6 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
import static org.schabi.newpipe.player.MainPlayer.PlayerType.AUDIO;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.PlayerType.POPUP;
|
|
||||||
|
|
||||||
public enum StreamDialogEntry {
|
public enum StreamDialogEntry {
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
@ -43,7 +39,7 @@ public enum StreamDialogEntry {
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(result -> {
|
.subscribe(result -> {
|
||||||
NewPipeDatabase.getInstance(fragment.getContext()).streamDAO()
|
NewPipeDatabase.getInstance(fragment.requireContext()).streamDAO()
|
||||||
.setUploaderUrl(serviceId, url, result.getUploaderUrl())
|
.setUploaderUrl(serviceId, url, result.getUploaderUrl())
|
||||||
.subscribeOn(Schedulers.io()).subscribe();
|
.subscribeOn(Schedulers.io()).subscribe();
|
||||||
openChannelFragment(fragment, item, result.getUploaderUrl());
|
openChannelFragment(fragment, item, result.getUploaderUrl());
|
||||||
|
@ -64,18 +60,11 @@ public enum StreamDialogEntry {
|
||||||
* Info: Add this entry within showStreamDialog.
|
* Info: Add this entry within showStreamDialog.
|
||||||
*/
|
*/
|
||||||
enqueue(R.string.enqueue_stream, (fragment, item) -> {
|
enqueue(R.string.enqueue_stream, (fragment, item) -> {
|
||||||
final MainPlayer.PlayerType type = PlayerHolder.getInstance().getType();
|
NavigationHelper.enqueueOnPlayer(fragment.getContext(), new SinglePlayQueue(item));
|
||||||
|
}),
|
||||||
|
|
||||||
if (type == AUDIO) {
|
enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> {
|
||||||
NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(),
|
NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), new SinglePlayQueue(item));
|
||||||
new SinglePlayQueue(item), false);
|
|
||||||
} else if (type == POPUP) {
|
|
||||||
NavigationHelper.enqueueOnPopupPlayer(fragment.getContext(),
|
|
||||||
new SinglePlayQueue(item), false);
|
|
||||||
} else /* type == VIDEO */ {
|
|
||||||
NavigationHelper.enqueueOnVideoPlayer(fragment.getContext(),
|
|
||||||
new SinglePlayQueue(item), false);
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
start_here_on_background(R.string.start_here_on_background, (fragment, item) ->
|
start_here_on_background(R.string.start_here_on_background, (fragment, item) ->
|
||||||
|
@ -108,16 +97,16 @@ public enum StreamDialogEntry {
|
||||||
try {
|
try {
|
||||||
NavigationHelper.playWithKore(fragment.requireContext(), videoUrl);
|
NavigationHelper.playWithKore(fragment.requireContext(), videoUrl);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
KoreUtils.showInstallKoreDialog(fragment.getActivity());
|
KoreUtils.showInstallKoreDialog(fragment.requireActivity());
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
share(R.string.share, (fragment, item) ->
|
share(R.string.share, (fragment, item) ->
|
||||||
ShareUtils.shareText(fragment.getContext(), item.getName(), item.getUrl(),
|
ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(),
|
||||||
item.getThumbnailUrl())),
|
item.getThumbnailUrl())),
|
||||||
|
|
||||||
open_in_browser(R.string.open_in_browser, (fragment, item) ->
|
open_in_browser(R.string.open_in_browser, (fragment, item) ->
|
||||||
ShareUtils.openUrlInBrowser(fragment.getContext(), item.getUrl())),
|
ShareUtils.openUrlInBrowser(fragment.requireContext(), item.getUrl())),
|
||||||
|
|
||||||
|
|
||||||
mark_as_watched(R.string.mark_as_watched, (fragment, item) -> {
|
mark_as_watched(R.string.mark_as_watched, (fragment, item) -> {
|
||||||
|
|
|
@ -416,6 +416,8 @@
|
||||||
<string name="show_channel_details">Show channel details</string>
|
<string name="show_channel_details">Show channel details</string>
|
||||||
<string name="enqueue_stream">Enqueue</string>
|
<string name="enqueue_stream">Enqueue</string>
|
||||||
<string name="enqueued">Enqueued</string>
|
<string name="enqueued">Enqueued</string>
|
||||||
|
<string name="enqueue_next_stream">Enqueue next</string>
|
||||||
|
<string name="enqueued_next">Enqueued next</string>
|
||||||
<string name="start_here_on_background">Start playing in the background</string>
|
<string name="start_here_on_background">Start playing in the background</string>
|
||||||
<string name="start_here_on_popup">Start playing in a popup</string>
|
<string name="start_here_on_popup">Start playing in a popup</string>
|
||||||
<!-- Drawer -->
|
<!-- Drawer -->
|
||||||
|
|
Loading…
Reference in a new issue