package dev.hienlt.tableviewdemo;
import android.os.SystemClock;
import android.view.View;
public abstract class SingleClickListener implements View.OnClickListener {
private static final long DEBOUNCE_INTERVAL_DEFAULT = 500;
private long debounceInterval;
private static long lastClickTime;
public SingleClickListener() {
this(DEBOUNCE_INTERVAL_DEFAULT);
}
public SingleClickListener(final long debounceInterval) {
this.debounceInterval = debounceInterval;
}
@Override
public void onClick(final View v) {
if ((SystemClock.elapsedRealtime() - SingleClickListener.lastClickTime) < debounceInterval) {
return;
}
SingleClickListener.lastClickTime = SystemClock.elapsedRealtime();
onSingleClick(v);
}
abstract void onSingleClick(View v);
}