Last active
January 8, 2018 15:45
-
-
Save blipinsk/41e4e7e80d205993f8789c1c14059513 to your computer and use it in GitHub Desktop.
[Medium] Butterknife's DebouncingOnClickListener as interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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