From 701320b100ca463b8ea4b5b9db8cd4274b2f7add Mon Sep 17 00:00:00 2001
From: John Zhen M <kingdomlearke@hotmail.com>
Date: Thu, 31 Aug 2017 17:47:56 -0700
Subject: [PATCH] -Added separate events for play queue index removal.

---
 .../java/org/schabi/newpipe/player/BasePlayer.java | 12 ++++++++++++
 .../org/schabi/newpipe/player/PlaybackManager.java | 14 +++++++++-----
 .../org/schabi/newpipe/playlist/PlayQueue.java     | 12 ++++++++----
 3 files changed, 29 insertions(+), 9 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 6e68253f1..df588df5d 100644
--- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
+++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
@@ -70,6 +70,7 @@ import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListene
 
 import org.schabi.newpipe.Downloader;
 import org.schabi.newpipe.R;
+import org.schabi.newpipe.extractor.stream_info.StreamInfo;
 import org.schabi.newpipe.playlist.PlayQueue;
 
 import java.io.File;
@@ -564,6 +565,17 @@ public abstract class BasePlayer implements Player.EventListener,
         if (currentState != STATE_PLAYING) changeState(STATE_PLAYING);
     }
 
+    @Override
+    public void sync(final StreamInfo info) {
+
+    }
+
+    @Override
+    public MediaSource sourceOf(final StreamInfo info) {
+
+        return null;
+    }
+
     /*//////////////////////////////////////////////////////////////////////////
     // General Player
     //////////////////////////////////////////////////////////////////////////*/
diff --git a/app/src/main/java/org/schabi/newpipe/player/PlaybackManager.java b/app/src/main/java/org/schabi/newpipe/player/PlaybackManager.java
index 3873d7c1c..72f1daede 100644
--- a/app/src/main/java/org/schabi/newpipe/player/PlaybackManager.java
+++ b/app/src/main/java/org/schabi/newpipe/player/PlaybackManager.java
@@ -31,9 +31,9 @@ public class PlaybackManager {
     interface PlaybackListener {
         void block();
         void unblock();
-        void sync();
 
-        MediaSource sourceOf(StreamInfo info);
+        void sync(final StreamInfo info);
+        MediaSource sourceOf(final StreamInfo info);
     }
 
     public PlaybackManager(@NonNull final PlaybackListener listener,
@@ -58,6 +58,10 @@ public class PlaybackManager {
         load(0);
     }
 
+    public void changeSource(final int index) {
+
+    }
+
     public void refreshMedia(final int newMediaIndex) {
         if (newMediaIndex == sourceIndex) return;
 
@@ -67,7 +71,7 @@ public class PlaybackManager {
             queueSource.remove(0);
         } else {
             //something went wrong
-            onInit();
+            init();
         }
     }
 
@@ -124,7 +128,7 @@ public class PlaybackManager {
         if (mediaSource.getSize() > 0 && queueSource.size() > 0) listener.unblock();
     }
 
-    private void onInit() {
+    private void init() {
         listener.block();
         load();
     }
@@ -156,7 +160,7 @@ public class PlaybackManager {
 
                 switch (event) {
                     case INIT:
-                        onInit();
+                        init();
                         break;
                     case APPEND:
                         load();
diff --git a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java
index 87e21cfee..67adc0cf2 100644
--- a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java
+++ b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java
@@ -5,7 +5,6 @@ import android.support.annotation.NonNull;
 import org.schabi.newpipe.extractor.NewPipe;
 import org.schabi.newpipe.extractor.StreamingService;
 import org.schabi.newpipe.extractor.exceptions.ExtractionException;
-import org.schabi.newpipe.extractor.stream_info.StreamInfo;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -15,7 +14,6 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import io.reactivex.BackpressureStrategy;
 import io.reactivex.Flowable;
-import io.reactivex.Maybe;
 import io.reactivex.subjects.BehaviorSubject;
 
 public abstract class PlayQueue {
@@ -94,8 +92,14 @@ public abstract class PlayQueue {
     }
 
     public void remove(final int index) {
-        if (index < streams.size()) {
-            streams.remove(index);
+        if (index >= streams.size()) return;
+        final boolean isCurrent = index == queueIndex.get();
+
+        streams.remove(index);
+
+        if (isCurrent) {
+            broadcast(PlayQueueEvent.REMOVE_CURRENT);
+        } else {
             broadcast(PlayQueueEvent.REMOVE);
         }
     }