Improve extenson & remove redundant utils
This commit is contained in:
@@ -25,17 +25,10 @@ import android.os.Looper
|
||||
fun runAsync(action: () -> Unit) = Thread(Runnable(action)).start()
|
||||
|
||||
fun runOnUiThread(action: () -> Unit) {
|
||||
if (isMainLooperAlive()) {
|
||||
action()
|
||||
} else {
|
||||
Handler(Looper.getMainLooper()).post(Runnable(action))
|
||||
when {
|
||||
isMainThread() -> action.invoke()
|
||||
else -> Handler(Looper.getMainLooper()).post(Runnable(action))
|
||||
}
|
||||
}
|
||||
|
||||
fun runDelayed(delayMillis: Long, action: () -> Unit) =
|
||||
Handler().postDelayed(Runnable(action), delayMillis)
|
||||
|
||||
fun runDelayedOnUiThread(delayMillis: Long, action: () -> Unit) =
|
||||
Handler(Looper.getMainLooper()).postDelayed(Runnable(action), delayMillis)
|
||||
|
||||
private fun isMainLooperAlive() = Looper.myLooper() == Looper.getMainLooper()
|
||||
private fun isMainThread() = Looper.myLooper() == Looper.getMainLooper()
|
||||
|
||||
Reference in New Issue
Block a user