一杠步、防止View 快速點擊
/**
* Created by Yangxy on 2020-01-08
* description -- 防止View快速點擊
*/
const val preventClicksKey = 1766613352
var <T : View> T.lastClickTime: Long
set(value) = setTag(preventClicksKey, value)
get() = getTag(preventClicksKey) as? Long ?: 0
inline fun <T : View> T.preventClicks(time: Long = 800, crossinline block: (T) -> Unit) {
setOnClickListener {
val currentTimeMillis = System.currentTimeMillis()
if (currentTimeMillis - lastClickTime > time || this is Checkable) {
lastClickTime = currentTimeMillis
block(this)
}
}
}