Skip to content

Instantly share code, notes, and snippets.

@blipinsk
Last active January 8, 2018 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blipinsk/41e4e7e80d205993f8789c1c14059513 to your computer and use it in GitHub Desktop.
Save blipinsk/41e4e7e80d205993f8789c1c14059513 to your computer and use it in GitHub Desktop.
[Medium] Butterknife's DebouncingOnClickListener as interface
public interface DebouncingOnClickListener extends View.OnClickListener {
Enabled enabled = new Enabled(true);
Runnable ENABLE_AGAIN = () -> enabled.set(true);
void doClick(View v);
@Override
default void onClick(View v) {
if (enabled.get()) {
enabled.set(false);
v.post(ENABLE_AGAIN);
doClick(v);
}
}
}
class Enabled {
private boolean raw;
Enabled(boolean initialValue) {
this.raw = initialValue;
}
public boolean get() {
return raw;
}
public void set(boolean enabled) {
this.raw = enabled;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment