[Android] Limit triggers of update finished callback

Geoffrey Métais git at videolan.org
Thu Jul 20 15:50:18 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jul 20 15:15:58 2017 +0200| [08ee95aee5dff20234a931506e4e560d271e5468] | committer: Geoffrey Métais

Limit triggers of update finished callback

Now called only once updates deque is empty

> https://code.videolan.org/videolan/vlc-android/commit/08ee95aee5dff20234a931506e4e560d271e5468
---

 vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java       | 5 ++++-
 .../src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java       | 6 +++++-
 vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java   | 8 ++++++--
 .../src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java      | 6 +++++-
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
index ba41b4768..4f4239f3f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
@@ -31,6 +31,7 @@ public abstract class BaseQueuedAdapter <T, VH extends RecyclerView.ViewHolder>
     private final ArrayDeque<T> mPendingUpdates = new ArrayDeque<>();
 
     protected abstract void internalUpdate(T items, boolean detectMoves);
+    protected abstract void onUpdateFinished();
 
     @MainThread
     public boolean hasPendingUpdates() {
@@ -62,7 +63,9 @@ public abstract class BaseQueuedAdapter <T, VH extends RecyclerView.ViewHolder>
     @MainThread
     protected void processQueue() {
         mPendingUpdates.remove();
-        if (!mPendingUpdates.isEmpty()) {
+        if (mPendingUpdates.isEmpty())
+            onUpdateFinished();
+        else {
             if (mPendingUpdates.size() > 1) {
                 T lastList = mPendingUpdates.peekLast();
                 mPendingUpdates.clear();
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index d1d739fa6..d11abc1b4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -341,7 +341,6 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<ArrayList<? extends M
                     public void run() {
                         addAll(newListWithSections, false);
                         result.dispatchUpdatesTo(AudioBrowserAdapter.this);
-                        mIEventsHandler.onUpdateFinished(AudioBrowserAdapter.this);
                         processQueue();
                     }
                 });
@@ -349,6 +348,11 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<ArrayList<? extends M
         });
     }
 
+    @Override
+    protected void onUpdateFinished() {
+        mIEventsHandler.onUpdateFinished(AudioBrowserAdapter.this);
+    }
+
     private ArrayList<? extends MediaLibraryItem> prepareNewList(final ArrayList<? extends MediaLibraryItem> items) {
         ArrayList<? extends MediaLibraryItem> newListWithSections;
         ArrayList<? extends MediaLibraryItem> newList = removeSections(items);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
index 16ca9131e..b1a360665 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -134,8 +134,6 @@ public class PlaylistAdapter extends BaseQueuedAdapter<ArrayList<MediaWrapper>,
                         mDataSet.clear();
                         addAll(newList);
                         result.dispatchUpdatesTo(PlaylistAdapter.this);
-                        if (mService != null)
-                            setCurrentIndex(mService.getCurrentMediaPosition());
                         processQueue();
                     }
                 });
@@ -144,6 +142,12 @@ public class PlaylistAdapter extends BaseQueuedAdapter<ArrayList<MediaWrapper>,
 
     }
 
+    @Override
+    protected void onUpdateFinished() {
+        if (mService != null)
+            setCurrentIndex(mService.getCurrentMediaPosition());
+    }
+
     @MainThread
     public void remove(int position) {
         if (mService == null)
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index 641430cf3..942c3bf34 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -378,7 +378,6 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
                     public void run() {
                         mMediaList = items;
                         result.dispatchUpdatesTo(BaseBrowserAdapter.this);
-                        fragment.onUpdateFinished(null);
                         processQueue();
                     }
                 });
@@ -386,6 +385,11 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
         });
     }
 
+    @Override
+    protected void onUpdateFinished() {
+        fragment.onUpdateFinished(null);
+    }
+
     void restoreList() {
         if (mOriginalData != null) {
             update(new ArrayList<>(mOriginalData));



More information about the Android mailing list