Updated on 2026-08-14

This commit is contained in:
Tangem 2022-12-26 18:11:01 +03:00
parent 5352f6e6f4
commit 1ef5e450d8
2 changed files with 29 additions and 3 deletions

View file

@ -0,0 +1,25 @@
package com.tangem.core.ui.utils
import android.os.SystemClock
import android.view.View
/**
* Implementation of click listener for preventing multiple click events
*
* @property action action that called when a view has been clicked
*/
class OneTouchClickListener(private val action: () -> Unit) : View.OnClickListener {
private var lastClickTimeMs: Long = 0L
override fun onClick(v: View?) {
if (SystemClock.elapsedRealtime() - lastClickTimeMs > CLICK_DELAY_MS) {
lastClickTimeMs = SystemClock.elapsedRealtime()
action()
}
}
companion object {
private const val CLICK_DELAY_MS = 500L
}
}