package com.naz.sdkdemo.utils;

public class FastClickUtil {

    private static long lastClickTime;//记录最近一次点击时间
    private static long interval = 10000;//间隔为10秒
    private static int lastButtonId;//存放最近一次传入的按钮id

    // 不需要传入任何参数 直接在点击事件下调用此方法即可
    public synchronized static boolean isFastClick() {
        long inter = System.currentTimeMillis() - lastClickTime;
        if (inter < interval) {
            return true;
        }
        lastClickTime = System.currentTimeMillis();
        return false;
    }

    // 需要传入ButtonId
    public static boolean isFastClick(int buttonId) {
        if (lastButtonId == buttonId && System.currentTimeMillis() - lastClickTime < interval) {
            return true;
        }
        lastClickTime = System.currentTimeMillis();
        lastButtonId = buttonId;
        return false;
    }

    public static long getLastClickTime() {
        return lastClickTime;
    }

    public static void setLastClickTime(long lastClickTime) {
        FastClickUtil.lastClickTime = lastClickTime;
    }

    public static long getInterval() {
        return interval;
    }
    public static int getRestInterval() {
        long inter = System.currentTimeMillis() - lastClickTime;
        return (int) ((interval - inter) / 1000);
    }
    public static void setInterval(long interval) {
        FastClickUtil.interval = interval;
    }

    public static int getLastButtonId() {
        return lastButtonId;
    }

    public static void setLastButtonId(int lastButtonId) {
        FastClickUtil.lastButtonId = lastButtonId;
    }
}