刚开始写kotlin 这段代码写的可能有问题 望指正
object ViewClickDelay {
var hash: Int = 0
var lastClickTime: Long = 0
var SPACE_TIME: Long = 3000
}
infix fun View.clickDelay(clickAction: () -> Unit) {
this.setOnClickListener {
if (this.hashCode() != hash) {
hash = this.hashCode()
lastClickTime = System.currentTimeMillis()
clickAction()
} else {
val currentTime = System.currentTimeMillis()
if (currentTime - lastClickTime > SPACE_TIME) {
lastClickTime = System.currentTimeMillis()
clickAction()
}
}
}
}
复制代码
调用
tv_test_click.clickDelay {
Log.d("eeeeee", "2222222")
}
复制代码