Fix tapping too fast breaking my stories viewer.

This commit is contained in:
Clark
2023-04-12 10:56:49 -04:00
committed by Greyson Parrelli
parent ef058a1644
commit 026d029614
2 changed files with 28 additions and 1 deletions

View File

@@ -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)
}
}
}