package com.gh.gamecenter.common.utils

import com.gh.gamecenter.common.callback.OnFastClickListener
import io.reactivex.disposables.Disposable
import java.lang.ref.WeakReference

object FastClickUtils {

    private var disposable: Disposable? = null
    private var ref: WeakReference<OnFastClickListener>? = null

    fun click(duration: Int = 500, onClick: OnFastClickListener) {
        ref = WeakReference(onClick)
        disposable?.dispose()
        ref?.get()?.invoke(false)
        disposable = rxTimer(1) {
            if (it >= duration) {
                ref?.get()?.invoke(true)
                disposable?.dispose()
            }
        }
    }
}