From e5278632597247f58b5d142a3d7e850fa5df43d9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Jan 2023 13:39:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/utils/DelayLiveData.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/DelayLiveData.kt b/app/src/main/java/io/legado/app/utils/DelayLiveData.kt index d2f97d727..975f8fbc1 100644 --- a/app/src/main/java/io/legado/app/utils/DelayLiveData.kt +++ b/app/src/main/java/io/legado/app/utils/DelayLiveData.kt @@ -16,15 +16,18 @@ class DelayLiveData(val delay: Int) : LiveData() { } } + @Synchronized public override fun postValue(value: T) { data = value - if (System.currentTimeMillis() >= postTime + delay) { + val postDelay = postTime + delay - System.currentTimeMillis() + if (postDelay > 0) { handler.removeCallbacks(sendRunnable) - postTime = System.currentTimeMillis() - super.postValue(value) + handler.postDelayed(sendRunnable, postDelay) } else { handler.removeCallbacks(sendRunnable) - handler.postDelayed(sendRunnable, delay - System.currentTimeMillis() + postTime) + postTime = System.currentTimeMillis() + super.postValue(value) } } + } \ No newline at end of file