44 lines
1.1 KiB
Kotlin
44 lines
1.1 KiB
Kotlin
package com.juhabi.birds.util
|
|
|
|
import android.content.Context
|
|
import android.widget.Toast
|
|
|
|
/** Toast 统一管理工具。 */
|
|
object ToastUtil {
|
|
|
|
var isShow = true
|
|
|
|
private var toast: Toast? = null
|
|
|
|
fun showShort(context: Context, message: CharSequence) {
|
|
show(context, message, Toast.LENGTH_SHORT)
|
|
}
|
|
|
|
fun showShort(context: Context, message: Int) {
|
|
show(context, message.toString(), Toast.LENGTH_SHORT)
|
|
}
|
|
|
|
fun showLong(context: Context, message: CharSequence) {
|
|
show(context, message, Toast.LENGTH_LONG)
|
|
}
|
|
|
|
fun showLong(context: Context, message: Int) {
|
|
show(context, message.toString(), Toast.LENGTH_LONG)
|
|
}
|
|
|
|
fun show(context: Context, message: CharSequence, duration: Int) {
|
|
val currentToast = toast
|
|
if (currentToast == null) {
|
|
toast = Toast.makeText(context, message, duration)
|
|
} else {
|
|
currentToast.setText(message)
|
|
currentToast.duration = duration
|
|
}
|
|
toast?.show()
|
|
}
|
|
|
|
fun show(context: Context, message: Int, duration: Int) {
|
|
show(context, message.toString(), duration)
|
|
}
|
|
}
|