package com.qimai.log

import android.view.View

/**
 * Created by chuxiaoshan on 2021/11/15 20:25
 *
 * Description:
 */
/**
 * 扩展属性参数：用于标记是否可点击
 */
private var <T : View> T.viewClickable: Boolean
    get() = if (getTag(1 + 2 shl 24) != null) getTag(1 + 2 shl 24) as Boolean else true
    set(value) {
        setTag(1 + 2 shl 24, value)
    }

/**
 * 设置点击监听, 并自定义防抖时间
 *
 * @receiver T View
 * @param time Long 防抖间隔时长 默认300
 * @param action Function1<[@kotlin.ParameterName] View, Unit> 点击事件
 */
fun <T : View> T.click(time: Long = 300, action: (T: View) -> Unit) {
    setOnClickListener {
        if (viewClickable) {
            viewClickable = false
            action(it)
            postDelayed({ viewClickable = true }, time)
        }
    }
}