|
@@ -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()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|