mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-22 15:55:57 +00:00
Added live data patch
This commit is contained in:
parent
24ea54f034
commit
2102131d99
2 changed files with 35 additions and 0 deletions
|
@ -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
27
livedata.patch
Normal 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();
|
||||
}
|
Loading…
Reference in a new issue