[Android] Image loading: Use Activity scope if available

Geoffrey Métais git at videolan.org
Thu Aug 8 13:53:51 CEST 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Aug  6 17:29:40 2019 +0200| [62a3faf8daa2038821ddb5891d3d18fbd7e7cc79] | committer: Geoffrey Métais

Image loading: Use Activity scope if available

(cherry picked from commit 47ca6c76a7c8509706d172289a75ef2dc1a3fbed)

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

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

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 29105f7d4..8bb6e4e28 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -78,7 +78,10 @@ fun loadImage(v: View, item: MediaLibraryItem?, imageWidth: Int = 0) {
     }
     val bitmap = if (cacheKey !== null) BitmapCache.getBitmapFromMemCache(cacheKey) else null
     if (bitmap !== null) updateImageView(bitmap, v, binding)
-    else AppScope.launch { getImage(v, findInLibrary(item, isMedia, isGroup), binding, imageWidth) }
+    else {
+        val scope = (v.context as? CoroutineScope) ?: AppScope
+        scope.launch { getImage(v, findInLibrary(item, isMedia, isGroup), binding, imageWidth) }
+    }
 }
 
 fun loadPlaylistImageWithWidth(v: ImageView, item: MediaLibraryItem?, imageWidth: Int) {



More information about the Android mailing list