refactor(utils): 简化 toast 扩展函数实现
- 移除多余的 null 检查代码块 - 删除已注释的旧版 toast 实现 - 简化条件判断语法 - 保留 ToastUtil 统一调用方式
This commit is contained in:
@@ -31,10 +31,7 @@ fun Context.toast(
|
|||||||
message: String?,
|
message: String?,
|
||||||
duration: Int = Toast.LENGTH_SHORT,
|
duration: Int = Toast.LENGTH_SHORT,
|
||||||
) {
|
) {
|
||||||
if (message.isNullOrBlank()) {
|
if (message.isNullOrBlank()) return
|
||||||
return
|
|
||||||
}
|
|
||||||
//Toast.makeText(this, message, duration).show()
|
|
||||||
ToastUtil.show(this, message, duration)
|
ToastUtil.show(this, message, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,28 +42,6 @@ fun Fragment.toast(
|
|||||||
activity?.toast(message, duration)
|
activity?.toast(message, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
//fun Fragment.toast(
|
|
||||||
// message: String?,
|
|
||||||
// duration: Int = 2000
|
|
||||||
//) {
|
|
||||||
// if (isAdded.not()) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// CustomToast(
|
|
||||||
// activity = requireActivity(),
|
|
||||||
// message = message,
|
|
||||||
// duration = duration
|
|
||||||
// ).show()
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//public fun BaseActivity.toast(message: String?, duration: Int = 2000) {
|
|
||||||
// CustomToast(
|
|
||||||
// activity = this,
|
|
||||||
// message = message,
|
|
||||||
// duration = duration
|
|
||||||
// ).show()
|
|
||||||
//}
|
|
||||||
|
|
||||||
fun View.visible() {
|
fun View.visible() {
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user