mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 08:09:12 +01:00
Fix tapping too fast breaking my stories viewer.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.view.View
|
||||
|
||||
/**
|
||||
* A View.OnClickListener that ignores clicks for a specified internal. This is useful for fixing
|
||||
* double press events that might be more difficult/cumbersome to fix by managing explicit state.
|
||||
*/
|
||||
class DebouncedOnClickListener(
|
||||
private val interval: Long = 500,
|
||||
private val onClickListener: View.OnClickListener
|
||||
) : View.OnClickListener {
|
||||
private var lastClickTime = 0L
|
||||
|
||||
override fun onClick(v: View) {
|
||||
val time = System.currentTimeMillis()
|
||||
if (time - lastClickTime >= interval) {
|
||||
lastClickTime = time
|
||||
onClickListener.onClick(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user