mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-16 15:20:31 +05:30
31 lines
822 B
Kotlin
31 lines
822 B
Kotlin
package com.github.libretube.extensions
|
|
|
|
import android.content.Context
|
|
import android.os.Handler
|
|
import android.os.Looper
|
|
import android.widget.Toast
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.withContext
|
|
|
|
fun Context.toastFromMainThread(text: String) {
|
|
Handler(Looper.getMainLooper()).post {
|
|
Toast.makeText(
|
|
this,
|
|
text,
|
|
Toast.LENGTH_SHORT
|
|
).show()
|
|
}
|
|
}
|
|
|
|
fun Context.toastFromMainThread(stringId: Int) {
|
|
toastFromMainThread(getString(stringId))
|
|
}
|
|
|
|
suspend fun Context.toastFromMainDispatcher(text: String) = withContext(Dispatchers.Main) {
|
|
Toast.makeText(this@toastFromMainDispatcher, text, Toast.LENGTH_SHORT).show()
|
|
}
|
|
|
|
suspend fun Context.toastFromMainDispatcher(stringId: Int) {
|
|
toastFromMainDispatcher(getString(stringId))
|
|
}
|