thanks <@UDWQJDERW> for suggestion it look that so...
# android
thanks @rnpy for suggestion it look that someone already implemented - this should be a good start for me
Instead of this implementation I would just disable button after click and enable it after delay, no need to have weak hsash map all other state for callbacks, just one postDelay
Interesting approach, however disabled button would change it’s look and this may look like UI glich
You also can just set some flag to view tags and check it before trigger next click
Anyway, this gist implementation looks overcomplicated and not really efficient
Good point - I will take a closer look soon
we have a kotlin base debounce implementation. private class DeBouncingOnClickListener(private val onClickListener: ((View) -> Unit)? = null, val viewOnClickListener: View.OnClickListener? = null) : View.OnClickListener { override fun onClick(v: View) { if (enabled) { enabled = false v.postDelayed(ENABLE_AGAIN, DEBOUNCE_DELAY_IN_MILLIS) onClickListener?.invoke(v) viewOnClickListener?.onClick(v) } } companion object { var enabled: Boolean = true val ENABLE_AGAIN = { enabled = true } const val DEBOUNCE_DELAY_IN_MILLIS = 250L } } fun View.setDebounceClickListener(onClickListener: ((View) -> Unit)?) { if (onClickListener != null) { val deBouncingOnClickListener = DeBouncingOnClickListener(onClickListener = onClickListener) setOnClickListener(deBouncingOnClickListener) } else { setOnClickListener(null) } }
this would ignore all view clicks using this method for click for debounce duration. if that is not neede for your usecase you can move
boolean and
method out of companion.