[Android] Image loading: Use Activity scope if available

Geoffrey Métais git at videolan.org
Tue Aug 6 17:30:25 CEST 2019


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

Image loading: Use Activity scope if available

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

 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