From 2e8f6ebbd09b881454e573b22bcfa62d351df891 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 23 Oct 2019 20:59:13 +0200 Subject: [PATCH] Updated AndroidX --- app/build.gradle | 14 ++++---- .../lifecycle/ComputableLiveData.java | 2 +- .../androidx/lifecycle/Transformations.java | 33 +++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7fa2b4f8c2..155b86159d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -175,22 +175,22 @@ dependencies { def core_version = "1.2.0-beta01" def appcompat_version = "1.1.0" - def fragment_version = "1.2.0-beta02" - def recyclerview_version = "1.1.0-beta05" - def coordinatorlayout_version = "1.1.0-beta01" + def fragment_version = "1.2.0-rc01" + def recyclerview_version = "1.1.0-rc01" + def coordinatorlayout_version = "1.1.0-rc01" def constraintlayout_version = "2.0.0-beta2" def material_version = "1.1.0-beta01" - def browser_version = "1.2.0-alpha08" + def browser_version = "1.2.0-alpha09" def lbm_version = "1.0.0" def swiperefresh_version = "1.0.0" def documentfile_version = "1.0.1" - def lifecycle_version = "2.2.0-beta01" - def room_version = "2.2.0" + def lifecycle_version = "2.2.0-rc01" + def room_version = "2.2.1" def paging_version = "2.1.0" def preference_version = "1.1.0" def work_version = "2.2.0" def exif_version = "1.1.0-rc01" - def biometric_version = "1.0.0-rc01" + def biometric_version = "1.0.0-rc02" def billingclient_version = "2.0.3" def javamail_version = "1.6.5-SNAPSHOT" def jsoup_version = "1.12.1" diff --git a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java index 9dd0123c42..92016a24b6 100644 --- a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java +++ b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java @@ -37,7 +37,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * @param The type of the live data * @hide internal */ -@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) +@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public abstract class ComputableLiveData { @SuppressWarnings("WeakerAccess") /* synthetic access */ final Executor mExecutor; diff --git a/app/src/main/java/androidx/lifecycle/Transformations.java b/app/src/main/java/androidx/lifecycle/Transformations.java index 7b2ad3c244..10261e9352 100644 --- a/app/src/main/java/androidx/lifecycle/Transformations.java +++ b/app/src/main/java/androidx/lifecycle/Transformations.java @@ -65,6 +65,7 @@ public class Transformations { * {@code mapFunction} to each value set. */ @MainThread + @NonNull public static LiveData map( @NonNull LiveData source, @NonNull final Function mapFunction) { @@ -129,6 +130,7 @@ public class Transformations { * value set */ @MainThread + @NonNull public static LiveData switchMap( @NonNull LiveData source, @NonNull final Function> switchMapFunction) { @@ -158,4 +160,35 @@ public class Transformations { }); return result; } + + /** + * Creates a new {@link LiveData} object that does not emit a value until the source LiveData + * value has been changed. The value is considered changed if {@code equals()} yields + * {@code false}. + * + * @param source the input {@link LiveData} + * @param the generic type parameter of {@code source} + * @return a new {@link LiveData} of type {@code X} + */ + @MainThread + @NonNull + public static LiveData distinctUntilChanged(@NonNull LiveData source) { + final MediatorLiveData outputLiveData = new MediatorLiveData<>(); + outputLiveData.addSource(source, new Observer() { + + boolean mFirstTime = true; + + @Override + public void onChanged(X currentValue) { + final X previousValue = outputLiveData.getValue(); + if (mFirstTime + || (previousValue == null && currentValue != null) + || (previousValue != null && !previousValue.equals(currentValue))) { + mFirstTime = false; + outputLiveData.setValue(currentValue); + } + } + }); + return outputLiveData; + } }