[Android] Run UI updates out of threadpool

Geoffrey Métais git at videolan.org
Fri Jul 21 18:09:55 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul 21 18:08:53 2017 +0200| [02282081cf197cc1c7eaa8d5338a3ffb125caa58] | committer: Geoffrey Métais

Run UI updates out of threadpool

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

 vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java          | 3 +++
 vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java  | 2 +-
 vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java      | 2 +-
 vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java | 2 +-
 vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java     | 2 +-
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
index 5d90fa689..c930f85a9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BaseQueuedAdapter.java
@@ -25,9 +25,12 @@ import android.support.v7.widget.RecyclerView;
 
 import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 
 public abstract class BaseQueuedAdapter <T, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
+    protected final ExecutorService mUpdateExecutor = Executors.newSingleThreadExecutor();
 
     protected volatile ArrayList<T> mDataset = new ArrayList<>();
     private final ArrayDeque<ArrayList<T>> mPendingUpdates = new ArrayDeque<>();
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 9bc832916..879e2c5c2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -325,7 +325,7 @@ public class AudioBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Aud
 
     @Override
     protected void internalUpdate(final ArrayList<MediaLibraryItem> items, final boolean detectMoves) {
-        VLCApplication.runBackground(new Runnable() {
+        mUpdateExecutor.execute(new Runnable() {
             @Override
             public void run() {
                 final ArrayList<MediaLibraryItem> newListWithSections = prepareNewList(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 deabbabfb..bff2870e5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -123,7 +123,7 @@ public class PlaylistAdapter extends BaseQueuedAdapter<MediaWrapper, PlaylistAda
 
     @MainThread
     protected void internalUpdate(final ArrayList<MediaWrapper> newList, final boolean detectMoves) {
-        VLCApplication.runBackground(new Runnable() {
+        mUpdateExecutor.execute(new Runnable() {
             @Override
             public void run() {
                 final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(mDataset, newList), detectMoves);
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 995f787f0..35874b0f4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -356,7 +356,7 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<MediaLibraryItem, Base
     }
 
     protected void internalUpdate(final ArrayList<MediaLibraryItem> items, final boolean detectMoves) {
-        VLCApplication.runBackground(new Runnable() {
+        mUpdateExecutor.execute(new Runnable() {
             @Override
             public void run() {
                 if (detectMoves || fragment.isSortEnabled())
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 72f0b8e99..55d533212 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -405,7 +405,7 @@ public class VideoListAdapter extends BaseQueuedAdapter<MediaWrapper, VideoListA
     }
 
     protected void internalUpdate(final ArrayList<MediaWrapper> items, final boolean detectMoves) {
-        VLCApplication.runBackground(new Runnable() {
+        mUpdateExecutor.execute(new Runnable() {
             @Override
             public void run() {
                 if(detectMoves || items.size() != getItemCount())



More information about the Android mailing list