Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a play next button to the long press menu #6872

Merged
merged 44 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
13f9f34
added mvp play next button in long press menu; new intent handling, n…
z3r0r4 Aug 7, 2021
d86560c
changed line length for checkstyle pass
z3r0r4 Aug 7, 2021
7966d55
cleaned comments, moved strings
z3r0r4 Aug 8, 2021
5649ef5
Update app/src/main/res/values/strings.xml
z3r0r4 Aug 8, 2021
a345886
Update app/src/main/res/values/strings.xml
z3r0r4 Aug 9, 2021
340b497
replace redundant nextOnVideoPlayer methods
z3r0r4 Aug 15, 2021
bea56dd
add enqueueNextOnPlayer and enqueueOnPlayer without selectOnAppend an…
z3r0r4 Aug 15, 2021
4286b98
Merge remote-tracking branch 'origin/playNextButton' into playNextButton
z3r0r4 Aug 15, 2021
fbda029
removed deprecated methods
z3r0r4 Aug 15, 2021
09920ac
removed deprecated methods
z3r0r4 Aug 15, 2021
9bab471
replaced APPEND_ONLY, removed SELECT_ON_APPEND / replaced remaining e…
z3r0r4 Aug 15, 2021
b8ebda7
now works with playlists
z3r0r4 Aug 15, 2021
c6dbad1
renamed dialog entry
z3r0r4 Aug 15, 2021
c9d5e21
checking for >1 items in the queue using the PlayerHolder
z3r0r4 Aug 15, 2021
5b3487d
making enqueue*OnPlayer safe to call when no video is playing (defaul…
z3r0r4 Aug 15, 2021
83df7b0
corrected strings
z3r0r4 Aug 15, 2021
1b89971
improve getQueueSize in PlayerHolder
z3r0r4 Aug 16, 2021
04c7f58
long press to enqueue only if queue isnt empty
z3r0r4 Aug 16, 2021
21de2bd
add Whitespace
z3r0r4 Aug 17, 2021
9b6574a
clarify comments / add spaces
z3r0r4 Aug 17, 2021
8cbfcc4
PlayerType as parameter of the enqueueOnPlayer method
z3r0r4 Aug 17, 2021
ca17b02
using the helper function everywhere (except for the background and p…
z3r0r4 Aug 17, 2021
f73c435
Merge remote-tracking branch 'origin/playNextButton' into playNextButton
z3r0r4 Aug 17, 2021
bdf3cc4
assimilated the enqueue*OnPlayer methods
z3r0r4 Aug 17, 2021
6b3858d
removed redundant comment, variable
z3r0r4 Aug 17, 2021
8053f76
simplify code line
z3r0r4 Aug 17, 2021
3fdd3d4
move if
z3r0r4 Aug 17, 2021
7a82f45
replace workaround for isPlayerOpen()
z3r0r4 Sep 6, 2021
52fef40
replaced workarounds (getType), corrected static access with getInstance
z3r0r4 Sep 6, 2021
9a08ce1
Merge branch 'dev' into playNextButton
z3r0r4 Sep 10, 2021
b0602da
remove unused imports
z3r0r4 Sep 10, 2021
8b74011
changed method call to original, new method doesnt exist yet.
z3r0r4 Sep 10, 2021
59470b9
Use getter method instead of property access syntax.
z3r0r4 Sep 10, 2021
a836934
improve conditional for play next entry
z3r0r4 Sep 12, 2021
5bf50ea
show play next btn in feed fragment
z3r0r4 Sep 12, 2021
7b0fc71
add play next to local playlist and statistics fragment
z3r0r4 Sep 12, 2021
4e9d57d
formating
z3r0r4 Sep 12, 2021
6153b41
correcting logic
z3r0r4 Sep 12, 2021
dde9fed
remove 2 year old unused string, formating
z3r0r4 Sep 12, 2021
f324c39
correct enqueue (next) conditionals, default to background if no play…
z3r0r4 Sep 13, 2021
1865cb7
remove player open checks from button long press enqueue actions
z3r0r4 Sep 13, 2021
3dad84d
improve log msg
z3r0r4 Sep 13, 2021
cf0427e
Rename next to enqueue_next
Stypox Sep 18, 2021
7e37d85
Refactor kotlin
Stypox Sep 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ protected void showStreamDialog(final StreamInfoItem item) {
if (context == null || context.getResources() == null || activity == null) {
return;
}

final List<StreamDialogEntry> entries = new ArrayList<>();

if (PlayerHolder.getInstance().getType() != null) {
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
entries.add(StreamDialogEntry.enqueue);
entries.add(StreamDialogEntry.next);
}
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
entries.addAll(Arrays.asList(
Expand Down
21 changes: 19 additions & 2 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,30 @@ public void handleIntent(@NonNull final Intent intent) {
}

// Resolve append intents
if (intent.getBooleanExtra(APPEND_ONLY, false) && playQueue != null) {
if (intent.getBooleanExtra(APPEND_ONLY, false)
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
&& playQueue != null) { /* Append Only = true && playQueue not empty*/
final int sizeBeforeAppend = playQueue.size();
playQueue.append(newQueue.getStreams());


if ((intent.getBooleanExtra(SELECT_ON_APPEND, false)
|| currentState == STATE_COMPLETED) && newQueue.getStreams().size() > 0) {
playQueue.setIndex(sizeBeforeAppend); // zero index => play appended
}

return;
//TODO reduce code duplication
} else if (!(intent.getBooleanExtra(APPEND_ONLY, false))
&& playQueue != null) { /* Append Only = false && playQueue not empty*/

final int currentIndex = playQueue.getIndex();
Log.e(TAG, "handleIntent: PLAYING NEXT" + currentIndex, null); //DEBUG
playQueue.append(newQueue.getStreams());
playQueue.move(playQueue.size() - 1, currentIndex + 1);

if ((intent.getBooleanExtra(SELECT_ON_APPEND, false)
|| currentState == STATE_COMPLETED) && newQueue.getStreams().size() > 0) {
playQueue.setIndex(sizeBeforeAppend);
playQueue.setIndex(currentIndex + 1); // play the nexted
}

return;
Expand Down
78 changes: 78 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ public static <T> Intent getPlayerEnqueueIntent(@NonNull final Context context,
.putExtra(Player.SELECT_ON_APPEND, selectOnAppend);
}

@NonNull
public static <T> Intent getPlayerNextIntent(@NonNull final Context context,
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
@NonNull final Class<T> targetClazz,
@Nullable final PlayQueue playQueue,
final boolean selectOnAppend,
final boolean resumePlayback) {
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
.putExtra(Player.APPEND_ONLY, false)
.putExtra(Player.SELECT_ON_APPEND, selectOnAppend);
}

public static void playOnMainPlayer(final AppCompatActivity activity,
@NonNull final PlayQueue playQueue) {
final PlayQueueItem item = playQueue.getItem();
Expand Down Expand Up @@ -209,6 +220,73 @@ public static void enqueueOnBackgroundPlayer(final Context context,
ContextCompat.startForegroundService(context, intent);
}

// TODO reduce code duplication
/**
* @param context Context
* @param queue a single video
* @param resumePlayback ?
*/
public static void nextOnVideoPlayer(final Context context,
final PlayQueue queue,
final boolean resumePlayback) {
nextOnVideoPlayer(context, queue, false, resumePlayback);
}

/**
* @param context Context
* @param queue a single video
* @param selectOnAppend play when video is "play nexted"
* @param resumePlayback ?
*/
public static void nextOnVideoPlayer(final Context context,
final PlayQueue queue,
final boolean selectOnAppend,
final boolean resumePlayback) {
Toast.makeText(context, R.string.playing_next, Toast.LENGTH_SHORT).show(); //Toast
final Intent intent = getPlayerNextIntent(
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);

intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.VIDEO.ordinal());
ContextCompat.startForegroundService(context, intent);
}

public static void nextOnPopupPlayer(final Context context,
final PlayQueue queue,
final boolean resumePlayback) {
nextOnPopupPlayer(context, queue, false, resumePlayback);
}

public static void nextOnPopupPlayer(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.playing_next, Toast.LENGTH_SHORT).show();
final Intent intent = getPlayerNextIntent(
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.POPUP.ordinal());
ContextCompat.startForegroundService(context, intent);
}

public static void nextOnBackgroundPlayer(final Context context,
final PlayQueue queue,
final boolean resumePlayback) {
nextOnBackgroundPlayer(context, queue, false, resumePlayback);
}

public static void nextOnBackgroundPlayer(final Context context,
final PlayQueue queue,
final boolean selectOnAppend,
final boolean resumePlayback) {
Toast.makeText(context, R.string.playing_next, Toast.LENGTH_SHORT).show();
final Intent intent = getPlayerNextIntent(
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
intent.putExtra(Player.PLAYER_TYPE, MainPlayer.PlayerType.AUDIO.ordinal());
ContextCompat.startForegroundService(context, intent);
}
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
/*//////////////////////////////////////////////////////////////////////////
// External Players
//////////////////////////////////////////////////////////////////////////*/
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ public enum StreamDialogEntry {
new SinglePlayQueue(item), false);
}
}),
//TODO reduce duplication
next(R.string.play_next_stream, (fragment, item) -> {
final MainPlayer.PlayerType type = PlayerHolder.getInstance().getType();

if (type == AUDIO) {
NavigationHelper.nextOnVideoPlayer(fragment.getContext(),
new SinglePlayQueue(item), false);
} else if (type == POPUP) {
NavigationHelper.nextOnPopupPlayer(fragment.getContext(),
new SinglePlayQueue(item), false);
} else /* type == VIDEO */ {
NavigationHelper.nextOnVideoPlayer(fragment.getContext(),
new SinglePlayQueue(item), false);
}
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
}),

start_here_on_background(R.string.start_here_on_background, (fragment, item) ->
NavigationHelper.playOnBackgroundPlayer(fragment.getContext(),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@
<string name="hold_to_append">Hold to enqueue</string>
<string name="show_channel_details">Show channel details</string>
<string name="enqueue_stream">Enqueue</string>
<string name="play_next_stream">Next</string>
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
<string name="playing_next">Playing Next</string>
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
<string name="enqueued">Enqueued</string>
<string name="start_here_on_main">Start playing here</string>
z3r0r4 marked this conversation as resolved.
Show resolved Hide resolved
<string name="start_here_on_background">Start playing in the background</string>
Expand Down