[Android] uiStart() for coroutines UI context fine dispatch

Geoffrey Métais git at videolan.org
Fri Apr 13 10:16:02 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 12 13:11:12 2018 +0200| [6b5de438485263f406a015c47b78dba79b7c0156] | committer: Geoffrey Métais

uiStart() for coroutines UI context fine dispatch

> https://code.videolan.org/videolan/vlc-android/commit/6b5de438485263f406a015c47b78dba79b7c0156
---

 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 cf902099c..ede160541 100644
--- a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -2,8 +2,10 @@ package org.videolan.vlc.util
 
 import android.arch.lifecycle.ViewModel
 import android.arch.lifecycle.ViewModelProviders
+import android.os.Looper
 import android.support.v4.app.Fragment
 import android.support.v4.app.FragmentActivity
+import kotlinx.coroutines.experimental.CoroutineStart
 import kotlinx.coroutines.experimental.delay
 import java.io.File
 import java.net.URI
@@ -43,4 +45,6 @@ suspend fun retry (
         delay(delayTime)
     }
     return block() // last attempt
-}
\ No newline at end of file
+}
+
+fun uiStart() = if (Looper.getMainLooper() == Looper.myLooper()) CoroutineStart.UNDISPATCHED else CoroutineStart.DEFAULT
\ No newline at end of file



More information about the Android mailing list