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