[Android] Use app threadpool for diffutil calculations

Geoffrey Métais git at videolan.org
Wed Feb 22 15:18:25 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 22 14:06:29 2017 +0100| [026f410f7ee7e43cfc9d39f7cd8c08371ceaf17b] | committer: Geoffrey Métais

Use app threadpool for diffutil calculations

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

 .../src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java   |  4 ++--
 .../src/org/videolan/vlc/gui/audio/PlaylistAdapter.java       |  8 +-------
 .../src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java  | 11 ++---------
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java      |  4 ++--
 4 files changed, 7 insertions(+), 20 deletions(-)

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 1fe1268..3c7f6db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -279,7 +279,7 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
     }
 
     private void internalUpdate(final MediaLibraryItem[] items) {
-        new Thread(new Runnable() {
+        VLCApplication.runBackground(new Runnable() {
             @Override
             public void run() {
                 final MediaLibraryItem[] newList = mOriginalDataSet == null && hasSections() ? generateList(items) : items;
@@ -296,7 +296,7 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
                     }
                 });
             }
-        }).start();
+        });
     }
 
     @MainThread
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 fee6872..153e0c7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -52,17 +52,11 @@ import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
 
 public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHolder> implements SwipeDragHelperAdapter, Filterable {
 
     private static final String TAG = "VLC/PlaylistAdapter";
 
-    private ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(1, 1, 2, TimeUnit.SECONDS,
-            new LinkedBlockingQueue<Runnable>(), VLCApplication.THREAD_FACTORY);
-
     private ItemFilter mFilter = new ItemFilter();
     private PlaybackService mService = null;
     private IPlayer mAudioPlayer;
@@ -143,7 +137,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
 
     @MainThread
     private void internalUpdate(final List<MediaWrapper> newList) {
-        mThreadPool.execute(new Runnable() {
+        VLCApplication.runBackground(new Runnable() {
             @Override
             public void run() {
                 final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataSet, newList), false);
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 f81f5d6..8dd081c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -50,9 +50,6 @@ import org.videolan.vlc.util.MediaItemFilter;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
 
 import static org.videolan.medialibrary.media.MediaLibraryItem.FLAG_SELECTED;
 import static org.videolan.medialibrary.media.MediaLibraryItem.TYPE_MEDIA;
@@ -75,9 +72,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
     private int mTop = 0, mMediaCount = 0, mSelectionCount = 0;
     private ItemFilter mFilter = new ItemFilter();
 
-    private ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(1, 1, 2, TimeUnit.SECONDS,
-            new LinkedBlockingQueue<Runnable>(), VLCApplication.THREAD_FACTORY);
-
     BaseBrowserAdapter(BaseBrowserFragment fragment){
         this.fragment = fragment;
     }
@@ -356,7 +350,6 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
         return mFilter;
     }
 
-    boolean isHoneyComb = AndroidUtil.isHoneycombOrLater();
     private ArrayDeque<ArrayList<MediaLibraryItem>> mPendingUpdates = new ArrayDeque<>();
     void dispatchUpdate(final ArrayList<MediaLibraryItem> items) {
         mPendingUpdates.add(items);
@@ -365,13 +358,13 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
     }
 
     private void update(final ArrayList<MediaLibraryItem> items) {
-        mThreadPool.execute(new Runnable() {
+        VLCApplication.runBackground(new Runnable() {
             @Override
             public void run() {
                 final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mMediaList, items), false);
                 for (MediaLibraryItem item : items) {
                     if (item.getItemType() == MediaLibraryItem.TYPE_MEDIA
-                            && (((MediaWrapper)item).getType() == MediaWrapper.TYPE_AUDIO|| (isHoneyComb && ((MediaWrapper)item).getType() == MediaWrapper.TYPE_VIDEO)))
+                            && (((MediaWrapper)item).getType() == MediaWrapper.TYPE_AUDIO|| (AndroidUtil.isHoneycombOrLater() && ((MediaWrapper)item).getType() == MediaWrapper.TYPE_VIDEO)))
                         mMediaCount++;
                 }
                 VLCApplication.runOnMainThread(new Runnable() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 485ed7e..0672d61 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -495,7 +495,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
     }
 
     private void internalUpdate(final ArrayList<MediaWrapper> items, final boolean detectMoves) {
-        new Thread(new Runnable() {
+        VLCApplication.runBackground(new Runnable() {
             @Override
             public void run() {
                 Collections.sort(items, mVideoComparator);
@@ -512,7 +512,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
                     }
                 });
             }
-        }).start();
+        });
     }
 
     private class VideoItemDiffCallback extends DiffUtil.Callback {



More information about the Android mailing list