Disable "Edited" click listener for outgoing messages.

This commit is contained in:
Clark
2024-05-29 16:53:28 -04:00
committed by Cody Henthorne
parent 8bb3d71472
commit b41bf66133
11 changed files with 71 additions and 19 deletions

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.util
import android.os.Handler
import android.os.Looper
import java.util.concurrent.TimeUnit
/**
* A class to throttle on click events. If multiple clicks happen in succession (within the threshold)
* We ignore both and let the caller know it was a double click.
*/
class DoubleClickDebouncer(private val threshold: Long) {
private val handler = Handler(Looper.getMainLooper())
constructor(threshold: Long, timeUnit: TimeUnit) : this(timeUnit.toMillis(threshold))
private var clickEnqueued = false
/**
* Returns true if the click is enqueued, otherwise its a double click
*/
fun onClick(runnable: Runnable?): Boolean {
handler.removeCallbacksAndMessages(null)
if (!clickEnqueued) {
handler.postDelayed({
runnable!!.run()
clickEnqueued = false
}, threshold)
clickEnqueued = true
} else {
clickEnqueued = false
}
return clickEnqueued
}
fun clear() {
handler.removeCallbacksAndMessages(null)
}
}