From 86c7b8522ea58c2a8535460dfa8a08d7b0b28aee Mon Sep 17 00:00:00 2001 From: John Zhen M Date: Thu, 14 Sep 2017 20:16:09 -0700 Subject: [PATCH] -Reverted current item removal and update logic. -Updated external play queue. --- .../org/schabi/newpipe/player/BasePlayer.java | 3 ++- .../player/playback/PlaybackManager.java | 21 +++++++------------ .../newpipe/playlist/ExternalPlayQueue.java | 12 +++++++---- .../schabi/newpipe/util/NavigationHelper.java | 1 + 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index e659e7b7a..a0086a58a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -267,6 +267,7 @@ public abstract class BasePlayer implements Player.EventListener, final int serviceId = intent.getIntExtra(ExternalPlayQueue.SERVICE_ID, -1); final int index = intent.getIntExtra(ExternalPlayQueue.INDEX, 0); final Serializable serializable = intent.getSerializableExtra(ExternalPlayQueue.STREAMS); + final String url = intent.getStringExtra(ExternalPlayQueue.URL); final String nextPageUrl = intent.getStringExtra(ExternalPlayQueue.NEXT_PAGE_URL); List info = new ArrayList<>(); @@ -276,7 +277,7 @@ public abstract class BasePlayer implements Player.EventListener, } } - final PlayQueue queue = new ExternalPlayQueue(serviceId, nextPageUrl, info, index); + final PlayQueue queue = new ExternalPlayQueue(serviceId, url, nextPageUrl, info, index); initPlayback(this, queue); } diff --git a/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java b/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java index 9b817e36b..0ebb2ac7a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java +++ b/app/src/main/java/org/schabi/newpipe/player/playback/PlaybackManager.java @@ -120,14 +120,11 @@ public class PlaybackManager { break; case REMOVE: final RemoveEvent removeEvent = (RemoveEvent) event; - if (removeEvent.isCurrent()) tryBlock(); - remove(removeEvent.index(), true); - break; + if (!removeEvent.isCurrent()) { + remove(removeEvent.index()); + break; + } case UPDATE: - final UpdateEvent updateEvent = (UpdateEvent) event; - tryBlock(); - remove(updateEvent.index(), false); - break; case SHUFFLE: tryBlock(); resetSources(); @@ -275,7 +272,7 @@ public class PlaybackManager { } } - private void remove(final int queueIndex, final boolean cascade) { + private void remove(final int queueIndex) { if (queueIndex < 0) return; final int sourceIndex = sourceToQueueIndex.indexOf(queueIndex); @@ -284,11 +281,9 @@ public class PlaybackManager { sourceToQueueIndex.remove(sourceIndex); sources.removeMediaSource(sourceIndex); - if (cascade) { - // Will be slow on really large arrays, fast enough for typical use case - for (int i = sourceIndex; i < sourceToQueueIndex.size(); i++) { - sourceToQueueIndex.set(i, sourceToQueueIndex.get(i) - 1); - } + // Will be slow on really large arrays, fast enough for typical use case + for (int i = sourceIndex; i < sourceToQueueIndex.size(); i++) { + sourceToQueueIndex.set(i, sourceToQueueIndex.get(i) - 1); } } } diff --git a/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java index 179c9e6c0..45d456ecf 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/ExternalPlayQueue.java @@ -23,6 +23,7 @@ public final class ExternalPlayQueue extends PlayQueue { public static final String SERVICE_ID = "service_id"; public static final String INDEX = "index"; public static final String STREAMS = "streams"; + public static final String URL = "url"; public static final String NEXT_PAGE_URL = "next_page_url"; private static final int RETRY_COUNT = 2; @@ -30,17 +31,20 @@ public final class ExternalPlayQueue extends PlayQueue { private boolean isComplete; private int serviceId; - private String playlistUrl; + private String baseUrl; + private String nextUrl; private transient Disposable fetchReactor; public ExternalPlayQueue(final int serviceId, + final String url, final String nextPageUrl, final List streams, final int index) { super(index, extractPlaylistItems(streams)); - this.playlistUrl = nextPageUrl; + this.baseUrl = url; + this.nextUrl = nextPageUrl; this.serviceId = serviceId; this.isComplete = nextPageUrl == null || nextPageUrl.isEmpty(); @@ -53,7 +57,7 @@ public final class ExternalPlayQueue extends PlayQueue { @Override public void fetch() { - ExtractorHelper.getMorePlaylistItems(this.serviceId, this.playlistUrl) + ExtractorHelper.getMorePlaylistItems(this.serviceId, this.baseUrl, this.nextUrl) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .retry(RETRY_COUNT) @@ -74,7 +78,7 @@ public final class ExternalPlayQueue extends PlayQueue { @Override public void onSuccess(@NonNull ListExtractor.NextItemsResult result) { if (!result.hasMoreStreams()) isComplete = true; - playlistUrl = result.nextItemsUrl; + nextUrl = result.nextItemsUrl; append(extractPlaylistItems(result.nextItemsList)); } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 735145749..cffef9622 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -64,6 +64,7 @@ public class NavigationHelper { .putExtra(ExternalPlayQueue.SERVICE_ID, info.service_id) .putExtra(ExternalPlayQueue.INDEX, index) .putExtra(ExternalPlayQueue.STREAMS, streams) + .putExtra(ExternalPlayQueue.URL, info.url) .putExtra(ExternalPlayQueue.NEXT_PAGE_URL, info.next_streams_url); }