From e15c10c15ec35e396f29bbcfdfa2b7c551ec1b1c Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 4 May 2025 21:37:14 +0200 Subject: [PATCH] Player/handleIntent: always early return on ENQUEUE an ENQUEUE_NEXT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can do this, because: 1. if `playQueue` is not null, we return early 2. if `playQueue` is null and we need to enqueue: - the only “proper” case that could be triggered is the `RESUME_PLAYBACK` case, which is never `true` for the queuing intents, see the comment in `NavigationHelper.enqueueOnPlayer` - the generic `else` case is degenerate, because it would crash on `playQueue` being `null`. This makes some sense, because there is no way to trigger the enqueueing logic via the UI currently if there is no video playing yet, in which case `playQueue` is not `null`. So we need to transform this whole if desaster into a big switch. --- .../java/org/schabi/newpipe/player/Player.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 4e35e921d..6fd3525fe 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -368,15 +368,20 @@ public final class Player implements PlaybackListener, Listener { } // Resolve enqueue intents - if (intent.getBooleanExtra(ENQUEUE, false) && playQueue != null) { - playQueue.append(newQueue.getStreams()); + if (intent.getBooleanExtra(ENQUEUE, false)) { + if (playQueue != null) { + playQueue.append(newQueue.getStreams()); + } return; + } // 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); + 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); + } return; }