From 47c3da131c9629ea24e5387a4b9b6f253ebf12cb Mon Sep 17 00:00:00 2001 From: shivanju Date: Sun, 11 Nov 2018 16:24:49 +0530 Subject: [PATCH 1/2] issue:1336 Fix for inserting new streams when auto queuing is enabled --- .../schabi/newpipe/player/helper/PlayerHelper.java | 10 ++++++++-- .../schabi/newpipe/player/playqueue/PlayQueue.java | 10 ++++++++-- .../newpipe/player/playqueue/PlayQueueItem.java | 11 ++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 16dffc3de..d55c81200 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -145,7 +145,7 @@ public class PlayerHelper { final StreamInfoItem nextVideo = info.getNextVideo(); if (nextVideo != null && !urls.contains(nextVideo.getUrl())) { - return new SinglePlayQueue(nextVideo); + return getAutoQueuedSinglePlayQueue(nextVideo); } final List relatedItems = info.getRelatedStreams(); @@ -158,7 +158,7 @@ public class PlayerHelper { } } Collections.shuffle(autoQueueItems); - return autoQueueItems.isEmpty() ? null : new SinglePlayQueue(autoQueueItems.get(0)); + return autoQueueItems.isEmpty() ? null : getAutoQueuedSinglePlayQueue(autoQueueItems.get(0)); } //////////////////////////////////////////////////////////////////////////// @@ -358,4 +358,10 @@ public class PlayerHelper { return getPreferences(context).getString(context.getString(R.string.minimize_on_exit_key), key); } + + private static SinglePlayQueue getAutoQueuedSinglePlayQueue(StreamInfoItem streamInfoItem) { + SinglePlayQueue singlePlayQueue = new SinglePlayQueue(streamInfoItem); + singlePlayQueue.getItem().setAutoQueued(true); + return singlePlayQueue; + } } diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java index c9e07c96a..13a550f2e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java @@ -233,7 +233,11 @@ public abstract class PlayQueue implements Serializable { backup.addAll(itemList); Collections.shuffle(itemList); } - streams.addAll(itemList); + if (!streams.isEmpty() && streams.get(streams.size() - 1).isAutoQueued() && !itemList.get(0).isAutoQueued()) { + streams.addAll(streams.size() - 1, itemList); + } else { + streams.addAll(itemList); + } broadcast(new AppendEvent(itemList.size())); } @@ -314,7 +318,9 @@ public abstract class PlayQueue implements Serializable { queueIndex.incrementAndGet(); } - streams.add(target, streams.remove(source)); + PlayQueueItem playQueueItem = streams.remove(source); + playQueueItem.setAutoQueued(false); + streams.add(target, playQueueItem); broadcast(new MoveEvent(source, target)); } diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java index 8cbc3ed1c..bd0218454 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java @@ -25,9 +25,10 @@ public class PlayQueueItem implements Serializable { @NonNull final private String uploader; @NonNull final private StreamType streamType; + private boolean isAutoQueued; + private long recoveryPosition; private Throwable error; - PlayQueueItem(@NonNull final StreamInfo info) { this(info.getName(), info.getUrl(), info.getServiceId(), info.getDuration(), info.getThumbnailUrl(), info.getUploaderName(), info.getStreamType()); @@ -105,6 +106,14 @@ public class PlayQueueItem implements Serializable { .doOnError(throwable -> error = throwable); } + public boolean isAutoQueued() { + return isAutoQueued; + } + + public void setAutoQueued(boolean autoQueued) { + isAutoQueued = autoQueued; + } + //////////////////////////////////////////////////////////////////////////// // Item States, keep external access out //////////////////////////////////////////////////////////////////////////// From 5bbb0cd666a843c25ad5ec4a44aaa7db700262b7 Mon Sep 17 00:00:00 2001 From: shivanju Date: Sat, 24 Nov 2018 17:20:57 +0530 Subject: [PATCH 2/2] issue:1336 Remove auto queued stream if a new stream gets appended --- .../java/org/schabi/newpipe/player/playqueue/PlayQueue.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java index 13a550f2e..2a7c9f127 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java @@ -234,10 +234,9 @@ public abstract class PlayQueue implements Serializable { Collections.shuffle(itemList); } if (!streams.isEmpty() && streams.get(streams.size() - 1).isAutoQueued() && !itemList.get(0).isAutoQueued()) { - streams.addAll(streams.size() - 1, itemList); - } else { - streams.addAll(itemList); + streams.remove(streams.size() - 1); } + streams.addAll(itemList); broadcast(new AppendEvent(itemList.size())); }