[Android] Allow detectMoves on every adapter

Geoffrey Métais git at videolan.org
Mon Jul 10 15:57:32 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jul 10 15:53:11 2017 +0200| [c5c8d8d89e525cc7cca133baa4de2e559ae2289e] | committer: Geoffrey Métais

Allow detectMoves on every adapter

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

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

diff --git a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
index 21788f57e..ba41b4768 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
@@ -30,7 +30,7 @@ public abstract class BaseQueuedAdapter <T, VH extends RecyclerView.ViewHolder>
 
     private final ArrayDeque<T> mPendingUpdates = new ArrayDeque<>();
 
-    protected abstract void internalUpdate(T items);
+    protected abstract void internalUpdate(T items, boolean detectMoves);
 
     @MainThread
     public boolean hasPendingUpdates() {
@@ -49,9 +49,14 @@ public abstract class BaseQueuedAdapter <T, VH extends RecyclerView.ViewHolder>
 
     @MainThread
     public void update(final T items) {
+        update(items, false);
+    }
+
+    @MainThread
+    public void update(final T items, boolean detectMoves) {
         mPendingUpdates.add(items);
         if (mPendingUpdates.size() == 1)
-            internalUpdate(items);
+            internalUpdate(items, detectMoves);
     }
 
     @MainThread
@@ -63,7 +68,7 @@ public abstract class BaseQueuedAdapter <T, VH extends RecyclerView.ViewHolder>
                 mPendingUpdates.clear();
                 update(lastList);
             } else
-                internalUpdate(mPendingUpdates.peek());
+                internalUpdate(mPendingUpdates.peek(), false);
         }
     }
 }
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 da2e1cf9d..fb6e19b59 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -277,12 +277,12 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<ArrayList<? extends M
         }
     }
 
-    protected void internalUpdate(final ArrayList<? extends MediaLibraryItem> items) {
+    protected void internalUpdate(final ArrayList<? extends MediaLibraryItem> items, final boolean detectMoves) {
         VLCApplication.runBackground(new Runnable() {
             @Override
             public void run() {
                 final ArrayList<? extends MediaLibraryItem> newList = (mOriginalDataSet == null && hasSections()) ? generateList(items) : items;
-                final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataList, newList), false);
+                final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataList, newList), detectMoves);
                 VLCApplication.runOnMainThread(new Runnable() {
                     @Override
                     public void run() {
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 a639a6930..16ca9131e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -37,7 +37,6 @@ import android.widget.Filter;
 import android.widget.Filterable;
 import android.widget.Toast;
 
-import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
@@ -124,11 +123,11 @@ public class PlaylistAdapter extends BaseQueuedAdapter<ArrayList<MediaWrapper>,
     }
 
     @MainThread
-    protected void internalUpdate(final ArrayList<MediaWrapper> newList) {
+    protected void internalUpdate(final ArrayList<MediaWrapper> newList, final boolean detectMoves) {
         VLCApplication.runBackground(new Runnable() {
             @Override
             public void run() {
-                final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataSet, newList), false);
+                final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataSet, newList), detectMoves);
                 VLCApplication.runOnMainThread(new Runnable() {
                     @Override
                     public void run() {
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 9ac40ed0b..52eb7fd07 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -371,13 +371,13 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
         return mFilter;
     }
 
-    protected void internalUpdate(final ArrayList<MediaLibraryItem> items) {
+    protected void internalUpdate(final ArrayList<MediaLibraryItem> items, final boolean detectMoves) {
         VLCApplication.runBackground(new Runnable() {
             @Override
             public void run() {
-                if (!fragment.isRootDirectory())
+                if (detectMoves)
                     Collections.sort(items, mMediaComparator);
-                final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mMediaList, items), false);
+                final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mMediaList, items), detectMoves);
                 for (MediaLibraryItem item : items) {
                     if (item.getItemType() == MediaLibraryItem.TYPE_MEDIA
                             && (((MediaWrapper)item).getType() == MediaWrapper.TYPE_AUDIO|| (AndroidUtil.isHoneycombOrLater && ((MediaWrapper)item).getType() == MediaWrapper.TYPE_VIDEO)))
@@ -481,7 +481,7 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
                     break;
             }
             ArrayList<MediaLibraryItem> list = new ArrayList<>(mMediaList);
-            update(list);
+            update(list, true);
             mSettings.edit()
                     .putInt(KEY_SORT_BY, mSortBy)
                     .putInt(KEY_SORT_DIRECTION, mSortDirection)



More information about the Android mailing list