Log filtered out click

This commit is contained in:
Benoit Marty 2021-05-31 16:10:03 +02:00
parent ffde34cbb2
commit 2c5418feaa

View file

@ -17,6 +17,7 @@ package im.vector.app.core.utils
import android.os.SystemClock import android.os.SystemClock
import android.view.View import android.view.View
import timber.log.Timber
import java.util.WeakHashMap import java.util.WeakHashMap
/** /**
@ -30,13 +31,14 @@ class DebouncedClickListener(
private val lastClickMap = WeakHashMap<View, Long>() private val lastClickMap = WeakHashMap<View, Long>()
override fun onClick(v: View) { override fun onClick(v: View) {
val previousClickTimestamp = lastClickMap[v] val previousClickTimestamp = lastClickMap[v] ?: 0
val currentTimestamp = SystemClock.elapsedRealtime() val currentTimestamp = SystemClock.elapsedRealtime()
lastClickMap[v] = currentTimestamp lastClickMap[v] = currentTimestamp
if (previousClickTimestamp == null || currentTimestamp - previousClickTimestamp > minimumInterval) { if (currentTimestamp > previousClickTimestamp + minimumInterval) {
original.onClick(v) original.onClick(v)
} else {
Timber.v("Debounced click!")
} }
} }
} }