Improve extenson & remove redundant utils

This commit is contained in:
Rahul Kumar Patel
2021-02-24 17:41:20 +05:30
parent 1d29d1dca1
commit b877552634
20 changed files with 209 additions and 195 deletions

View File

@@ -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()