|
|
@ -16,15 +16,18 @@ class DelayLiveData<T>(val delay: Int) : LiveData<T>() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
public override fun postValue(value: T) { |
|
|
|
public override fun postValue(value: T) { |
|
|
|
data = value |
|
|
|
data = value |
|
|
|
if (System.currentTimeMillis() >= postTime + delay) { |
|
|
|
val postDelay = postTime + delay - System.currentTimeMillis() |
|
|
|
|
|
|
|
if (postDelay > 0) { |
|
|
|
handler.removeCallbacks(sendRunnable) |
|
|
|
handler.removeCallbacks(sendRunnable) |
|
|
|
postTime = System.currentTimeMillis() |
|
|
|
handler.postDelayed(sendRunnable, postDelay) |
|
|
|
super.postValue(value) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
handler.removeCallbacks(sendRunnable) |
|
|
|
handler.removeCallbacks(sendRunnable) |
|
|
|
handler.postDelayed(sendRunnable, delay - System.currentTimeMillis() + postTime) |
|
|
|
postTime = System.currentTimeMillis() |
|
|
|
|
|
|
|
super.postValue(value) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |