From 24ea54f034e2b4915c46cd12aa69e05ecfb84cf3 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 6 Jul 2019 10:46:15 +0200 Subject: [PATCH] Updated AndroidX libraries --- app/build.gradle | 12 ++++---- .../lifecycle/ComputableLiveData.java | 10 ------- .../java/androidx/lifecycle/LiveData.java | 28 +++++++++++++++---- .../androidx/lifecycle/MutableLiveData.java | 17 +++++++++++ 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d0201d3191..6f3383f695 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -126,18 +126,18 @@ configurations.all { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - def appcompat_version = "1.1.0-beta01" - def recyclerview_version = "1.1.0-alpha06" + def appcompat_version = "1.1.0-rc01" + def recyclerview_version = "1.1.0-beta01" def coordinatorlayout_version = "1.1.0-beta01" def constraintlayout_version = "2.0.0-beta1" def material_version = "1.1.0-alpha07" def browser_version = "1.0.0" - def lifecycle_version = "2.1.0-beta01" + def lifecycle_version = "2.1.0-rc01" def room_version = "2.1.0" def paging_version = "2.1.0" - def preference_version = "1.1.0-beta01" + def preference_version = "1.1.0-rc01" def work_version = "2.1.0-rc01" - def exif_version = "1.1.0-alpha01" + def exif_version = "1.1.0-beta01" def billingclient_version = "2.0.1" def javamail_version = "1.6.3" def jsoup_version = "1.12.1" @@ -172,6 +172,8 @@ dependencies { implementation "androidx.browser:browser:$browser_version" // https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-runtime + // https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata + // https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata-core implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" diff --git a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java index b82566d6ad..837a35dbf9 100644 --- a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java +++ b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java @@ -16,8 +16,6 @@ package androidx.lifecycle; -import android.os.SystemClock; - import androidx.annotation.MainThread; import androidx.annotation.NonNull; import androidx.annotation.RestrictTo; @@ -91,22 +89,14 @@ public abstract class ComputableLiveData { @Override public void run() { boolean computed; - long age; 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 { - age = SystemClock.elapsedRealtime(); T value = null; while (mInvalid.compareAndSet(true, false)) { - long now = SystemClock.elapsedRealtime(); - if (age + 1500 < now && value != null) { - eu.faircode.email.Log.i(mLiveData + " post age=" + (now - age)); - age = now; - mLiveData.postValue(value); - } computed = true; value = compute(); } diff --git a/app/src/main/java/androidx/lifecycle/LiveData.java b/app/src/main/java/androidx/lifecycle/LiveData.java index b03476c8c6..43909fa2bf 100644 --- a/app/src/main/java/androidx/lifecycle/LiveData.java +++ b/app/src/main/java/androidx/lifecycle/LiveData.java @@ -69,12 +69,12 @@ public abstract class LiveData { // how many observers are in active state @SuppressWarnings("WeakerAccess") /* synthetic access */ int mActiveCount = 0; - private volatile Object mData = NOT_SET; + private volatile Object mData; // when setData is called, we set the pending data and actual data swap happens on the main // thread @SuppressWarnings("WeakerAccess") /* synthetic access */ volatile Object mPendingData = NOT_SET; - private int mVersion = START_VERSION; + private int mVersion; private boolean mDispatchingValue; @SuppressWarnings("FieldCanBeLocal") @@ -92,6 +92,24 @@ public abstract class LiveData { } }; + /** + * Creates a LiveData initialized with the given {@code value}. + * + * @param value initial value + */ + public LiveData(T value) { + mData = value; + mVersion = START_VERSION + 1; + } + + /** + * Creates a LiveData with no value assigned to it. + */ + public LiveData() { + mData = NOT_SET; + mVersion = START_VERSION; + } + private void considerNotify(ObserverWrapper observer) { if (!observer.mActive) { return; @@ -204,7 +222,7 @@ public abstract class LiveData { assertMainThread("observeForever"); AlwaysActiveObserver wrapper = new AlwaysActiveObserver(observer); ObserverWrapper existing = mObservers.putIfAbsent(observer, wrapper); - if (existing != null && existing instanceof LiveData.LifecycleBoundObserver) { + if (existing instanceof LiveData.LifecycleBoundObserver) { throw new IllegalArgumentException("Cannot add the same observer" + " with different lifecycles"); } @@ -353,7 +371,7 @@ public abstract class LiveData { return mActiveCount > 0; } - class LifecycleBoundObserver extends ObserverWrapper implements GenericLifecycleObserver { + class LifecycleBoundObserver extends ObserverWrapper implements LifecycleEventObserver { @NonNull final LifecycleOwner mOwner; @@ -438,7 +456,7 @@ public abstract class LiveData { } } - private static void assertMainThread(String methodName) { + static void assertMainThread(String methodName) { if (!ArchTaskExecutor.getInstance().isMainThread()) { throw new IllegalStateException("Cannot invoke " + methodName + " on a background" + " thread"); diff --git a/app/src/main/java/androidx/lifecycle/MutableLiveData.java b/app/src/main/java/androidx/lifecycle/MutableLiveData.java index 06014f0ab2..75455e09e9 100644 --- a/app/src/main/java/androidx/lifecycle/MutableLiveData.java +++ b/app/src/main/java/androidx/lifecycle/MutableLiveData.java @@ -23,6 +23,23 @@ package androidx.lifecycle; */ @SuppressWarnings("WeakerAccess") public class MutableLiveData extends LiveData { + + /** + * Creates a MutableLiveData initialized with the given {@code value}. + * + * @param value initial value + */ + public MutableLiveData(T value) { + super(value); + } + + /** + * Creates a MutableLiveData with no value assigned to it. + */ + public MutableLiveData() { + super(); + } + @Override public void postValue(T value) { super.postValue(value);