package com.ama.core.architecture.util

import android.os.SystemClock
import android.view.View
import com.ama.core.architecture.R

class UiUtil {

}

typealias viewClickHandler = View.() -> Unit

inline fun setOnClickBatch(vararg v: View?, crossinline block: viewClickHandler) {
    val interval = 500L
    v.forEach {
        it?.let { view ->
            view.setOnClickListener {
                val lastClickedTimestamp = view.getTag(R.id.view_last_click_timestamp)?.toString()?.toLongOrNull() ?: 0L
                val currTimestamp = SystemClock.uptimeMillis()
                if (currTimestamp - lastClickedTimestamp < interval) return@setOnClickListener
                view.setTag(R.id.view_last_click_timestamp, currTimestamp)
                view.block()
            }
        }
    }
}