From 2102131d99d8ab8d81a61c749695eea882a02e1c Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 6 Jul 2019 10:51:16 +0200 Subject: [PATCH] Added live data patch --- .../lifecycle/ComputableLiveData.java | 8 ++++++ livedata.patch | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 livedata.patch diff --git a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java index 837a35dbf9..338af5c89b 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 { @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(); } diff --git a/livedata.patch b/livedata.patch new file mode 100644 index 0000000000..4b4c500e81 --- /dev/null +++ b/livedata.patch @@ -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 { + @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(); + }