Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun View.setIntervalOnClick(intervalMillis: Long = 0, doClick: (View) -> Unit) =
- setOnClickListener(DebouncingOnClickListener(intervalMillis, doClick))
- class DebouncingOnClickListener(
- private val intervalMillis: Long,
- private val doClick: ((View) -> Unit)
- ) : View.OnClickListener {
- override fun onClick(v: View) {
- if (enabled) {
- enabled = false
- v.postDelayed(ENABLE_AGAIN, intervalMillis)
- doClick(v)
- }
- }
- companion object {
- @JvmStatic
- var enabled = true
- private val ENABLE_AGAIN =
- Runnable { enabled = true }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement