package com.rc.core.util

import android.view.View

/**
 * info
 *
 * @author ReiChin_
 */
class FastClickDelegate(private val listener: View.OnClickListener) : View.OnClickListener {

    companion object {
        private const val FAST_CLICK_DELAY_TIME = 1000
    }

    private var mLastClickTime = 1L

    override fun onClick(v: View?) {
        if (!isFastClick()) listener.onClick(v)
    }

    private fun isFastClick(): Boolean {
        var isFastClick = true
        val currentTimeMillis = System.currentTimeMillis()
        if (currentTimeMillis - mLastClickTime > FAST_CLICK_DELAY_TIME) {
            isFastClick = false
        }
        mLastClickTime = currentTimeMillis
        return isFastClick
    }

}