Player/handleIntent: start converting intent data to enum
The goal here is to convert all player intents to use a single enum with extra data for each case. The queue ones are pretty easy, they don’t carry any extra data. We fall through for everything else for now.
This commit is contained in:
parent
ab7d1377e5
commit
5750ef6aa8
5 changed files with 52 additions and 25 deletions
|
|
@ -157,11 +157,10 @@ public final class Player implements PlaybackListener, Listener {
|
|||
public static final String REPEAT_MODE = "repeat_mode";
|
||||
public static final String PLAYBACK_QUALITY = "playback_quality";
|
||||
public static final String PLAY_QUEUE_KEY = "play_queue_key";
|
||||
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 PLAY_WHEN_READY = "play_when_ready";
|
||||
public static final String PLAYER_TYPE = "player_type";
|
||||
public static final String PLAYER_INTENT_TYPE = "player_intent_type";
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Time constants
|
||||
|
|
@ -365,22 +364,26 @@ public final class Player implements PlaybackListener, Listener {
|
|||
videoResolver.setPlaybackQuality(intent.getStringExtra(PLAYBACK_QUALITY));
|
||||
}
|
||||
|
||||
// Resolve enqueue intents
|
||||
if (intent.getBooleanExtra(ENQUEUE, false)) {
|
||||
if (playQueue != null) {
|
||||
playQueue.append(newQueue.getStreams());
|
||||
}
|
||||
return;
|
||||
}
|
||||
final PlayerIntentType playerIntentType = intent.getParcelableExtra(PLAYER_INTENT_TYPE);
|
||||
|
||||
// Resolve enqueue next intents
|
||||
if (intent.getBooleanExtra(ENQUEUE_NEXT, false)) {
|
||||
if (playQueue != null) {
|
||||
final int currentIndex = playQueue.getIndex();
|
||||
playQueue.append(newQueue.getStreams());
|
||||
playQueue.move(playQueue.size() - 1, currentIndex + 1);
|
||||
switch (playerIntentType) {
|
||||
case Enqueue -> {
|
||||
if (playQueue != null) {
|
||||
playQueue.append(newQueue.getStreams());
|
||||
}
|
||||
return;
|
||||
}
|
||||
case EnqueueNext -> {
|
||||
if (playQueue != null) {
|
||||
final int currentIndex = playQueue.getIndex();
|
||||
playQueue.append(newQueue.getStreams());
|
||||
playQueue.move(playQueue.size() - 1, currentIndex + 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
case AllOthers -> {
|
||||
// fallthrough; TODO: put other intent data in separate cases
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// initPlayback Parameters
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package org.schabi.newpipe.player
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
// We model this as an enum class plus one struct for each enum value
|
||||
// so we can consume it from Java properly. After converting to Kotlin,
|
||||
// we could switch to a sealed enum class & a proper Kotlin `when` match.
|
||||
|
||||
@Parcelize
|
||||
enum class PlayerIntentType : Parcelable {
|
||||
Enqueue,
|
||||
EnqueueNext,
|
||||
AllOthers
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ import androidx.core.content.ContextCompat;
|
|||
import org.schabi.newpipe.MainActivity;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.player.Player;
|
||||
import org.schabi.newpipe.player.PlayerIntentType;
|
||||
import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
|
||||
|
|
@ -254,7 +255,8 @@ public final class NotificationUtil {
|
|||
} else {
|
||||
// We are playing in fragment. Don't open another activity just show fragment. That's it
|
||||
final Intent intent = NavigationHelper.getPlayerIntent(
|
||||
player.getContext(), MainActivity.class, null);
|
||||
player.getContext(), MainActivity.class, null,
|
||||
PlayerIntentType.AllOthers);
|
||||
intent.putExtra(Player.RESUME_PLAYBACK, true);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue