Minor cleanup

This commit is contained in:
arkon
2021-04-03 10:12:31 -04:00
parent efd2a0cb7b
commit a3992d9fbe
5 changed files with 12 additions and 12 deletions

View File

@@ -42,8 +42,8 @@ import kotlin.math.roundToInt
* @param resource the text resource.
* @param duration the duration of the toast. Defaults to short.
*/
fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT): Toast {
return Toast.makeText(this, resource, duration).also { it.show() }
fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast {
return toast(getString(resource), duration, block)
}
/**
@@ -52,8 +52,11 @@ fun Context.toast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SHORT):
* @param text the text to display.
* @param duration the duration of the toast. Defaults to short.
*/
fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT): Toast {
return Toast.makeText(this, text.orEmpty(), duration).also { it.show() }
fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT, block: (Toast) -> Unit = {}): Toast {
return Toast.makeText(this, text.orEmpty(), duration).also {
block(it)
it.show()
}
}
/**