[Android] Set a fixed threadpool of image retrieval

Geoffrey Métais git at videolan.org
Tue Feb 19 15:59:31 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 19 15:54:35 2019 +0100| [984bf7b537dae3ab2761d2c2455c894fa3050a0b] | committer: Geoffrey Métais

Set a fixed threadpool of image retrieval

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

 vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index 73b225f56..21a2ae49a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -14,6 +14,7 @@ import androidx.databinding.OnRebindCallback
 import androidx.databinding.ViewDataBinding
 import androidx.leanback.widget.ImageCardView
 import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.asCoroutineDispatcher
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 import org.videolan.medialibrary.media.Folder
@@ -24,10 +25,12 @@ import org.videolan.vlc.VLCApplication
 import org.videolan.vlc.util.AppScope
 import org.videolan.vlc.util.HttpImageLoader
 import org.videolan.vlc.util.ThumbnailsProvider
+import java.util.concurrent.Executors
 
 private val sBitmapCache = BitmapCache.getInstance()
 private val sMedialibrary = VLCApplication.getMLInstance()
 private const val TAG = "ImageLoader"
+private val dispatcher = Executors.newFixedThreadPool(1).asCoroutineDispatcher()
 
 @MainThread
 @BindingAdapter("media")
@@ -75,10 +78,10 @@ private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataB
     binding?.removeOnRebindCallback(rebindCallbacks!!)
 }
 
-private suspend fun obtainBitmap(item: MediaLibraryItem, width: Int) = withContext(Dispatchers.IO) {
-    when {
-        item is MediaWrapper -> ThumbnailsProvider.getMediaThumbnail(item, width)
-        item is Folder -> ThumbnailsProvider.getFolderThumbnail(item, width)
+private suspend fun obtainBitmap(item: MediaLibraryItem, width: Int) = withContext(dispatcher) {
+    when (item) {
+        is MediaWrapper -> ThumbnailsProvider.getMediaThumbnail(item, width)
+        is Folder -> ThumbnailsProvider.getFolderThumbnail(item, width)
         else -> AudioUtil.readCoverBitmap(Uri.decode(item.artworkMrl), width)
     }
 }



More information about the Android mailing list