[Android] Improve View.scope util property

Geoffrey Métais git at videolan.org
Thu Nov 28 17:21:32 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 28 17:21:05 2019 +0100| [8b1c02ee7de6a8a6ea29b326ffe94859ff8bac15] | committer: Geoffrey Métais

Improve View.scope util property

> https://code.videolan.org/videolan/vlc-android/commit/8b1c02ee7de6a8a6ea29b326ffe94859ff8bac15
---

 vlc-android/src/org/videolan/vlc/util/Kextensions.kt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 1da67b753..e543f9a07 100644
--- a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -213,7 +213,11 @@ fun generateResolutionClass(width: Int, height: Int) : String? = if (width <= 0
 }
 
 val View.scope : CoroutineScope
-    get() = context as? CoroutineScope ?: AppScope
+    get() = when(val ctx = context) {
+        is CoroutineScope -> ctx
+        is LifecycleOwner -> ctx.lifecycleScope
+        else -> AppScope
+    }
 
 fun Activity.manageHttpException(e: Exception) {
     when (e) {



More information about the Android mailing list