Added live data patch

This commit is contained in:
M66B 2019-07-06 10:51:16 +02:00
parent 24ea54f034
commit 2102131d99
2 changed files with 35 additions and 0 deletions

View File

@ -89,14 +89,22 @@ public abstract class ComputableLiveData<T> {
@Override
public void run() {
boolean computed;
long last;
do {
computed = false;
// compute can happen only in 1 thread but no reason to lock others.
if (mComputing.compareAndSet(false, true)) {
// as long as it is invalid, keep computing.
try {
last = android.os.SystemClock.elapsedRealtime();
T value = null;
while (mInvalid.compareAndSet(true, false)) {
long now = android.os.SystemClock.elapsedRealtime();
if (last + 1500 < now && value != null) {
eu.faircode.email.Log.i(mLiveData + " post age=" + (now - last));
last = now;
mLiveData.postValue(value);
}
computed = true;
value = compute();
}

27
livedata.patch Normal file
View File

@ -0,0 +1,27 @@
diff --git a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
index 837a35dbf..338af5c89 100644
--- a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
+++ b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
@@ -89,14 +89,22 @@ public abstract class ComputableLiveData<T> {
@Override
public void run() {
boolean computed;
+ long last;
do {
computed = false;
// compute can happen only in 1 thread but no reason to lock others.
if (mComputing.compareAndSet(false, true)) {
// as long as it is invalid, keep computing.
try {
+ last = android.os.SystemClock.elapsedRealtime();
T value = null;
while (mInvalid.compareAndSet(true, false)) {
+ long now = android.os.SystemClock.elapsedRealtime();
+ if (last + 1500 < now && value != null) {
+ eu.faircode.email.Log.i(mLiveData + " post age=" + (now - last));
+ last = now;
+ mLiveData.postValue(value);
+ }
computed = true;
value = compute();
}