mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -16,15 +16,18 @@ class DelayLiveData<T>(val delay: Int) : LiveData<T>() {
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
handler.postDelayed(sendRunnable, postDelay)
|
||||
} else {
|
||||
handler.removeCallbacks(sendRunnable)
|
||||
postTime = System.currentTimeMillis()
|
||||
super.postValue(value)
|
||||
} else {
|
||||
handler.removeCallbacks(sendRunnable)
|
||||
handler.postDelayed(sendRunnable, delay - System.currentTimeMillis() + postTime)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user