2022-11-05 22:11:00 +05:30
|
|
|
package com.github.libretube.extensions
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.os.Handler
|
|
|
|
import android.os.Looper
|
|
|
|
import android.widget.Toast
|
2023-02-03 20:51:25 +05:30
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.withContext
|
2022-11-05 22:11:00 +05:30
|
|
|
|
2022-11-17 22:46:12 +05:30
|
|
|
fun Context.toastFromMainThread(text: String) {
|
|
|
|
Handler(Looper.getMainLooper()).post {
|
|
|
|
Toast.makeText(
|
|
|
|
this,
|
|
|
|
text,
|
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
).show()
|
|
|
|
}
|
|
|
|
}
|
2022-11-20 20:24:55 +05:30
|
|
|
|
|
|
|
fun Context.toastFromMainThread(stringId: Int) {
|
|
|
|
toastFromMainThread(getString(stringId))
|
|
|
|
}
|
2023-02-03 20:51:25 +05:30
|
|
|
|
|
|
|
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))
|
|
|
|
}
|