Updated AndroidX

pull/163/head
M66B 6 years ago
parent 7135ee7e0b
commit 1e9a77e249

@ -162,15 +162,19 @@ configurations.all {
exclude group: "androidx.room", module: "room-runtime" exclude group: "androidx.room", module: "room-runtime"
// Workaround https://issuetracker.google.com/issues/134685570 // Workaround https://issuetracker.google.com/issues/134685570
exclude group: "androidx.lifecycle", module: "lifecycle-livedata" exclude group: "androidx.lifecycle", module: "lifecycle-livedata"
exclude group: "androidx.lifecycle", module: "lifecycle-livedata-core"
// lifecycle-livedata: ComputableLiveData, MediatorLiveData, Transformations
// lifecycle-livedata-core: LiveData, MutableLiveData, Observer
} }
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
def core_version = "1.2.0-alpha04" def core_version = "1.2.0-beta01"
def appcompat_version = "1.1.0" def appcompat_version = "1.1.0"
def fragment_version = "1.1.0" def fragment_version = "1.2.0-beta01"
def recyclerview_version = "1.1.0-beta04" def recyclerview_version = "1.1.0-beta05"
def coordinatorlayout_version = "1.1.0-beta01" def coordinatorlayout_version = "1.1.0-beta01"
def constraintlayout_version = "2.0.0-beta2" def constraintlayout_version = "2.0.0-beta2"
def material_version = "1.1.0-alpha10" def material_version = "1.1.0-alpha10"
@ -178,13 +182,13 @@ dependencies {
def lbm_version = "1.0.0" def lbm_version = "1.0.0"
def swiperefresh_version = "1.0.0" def swiperefresh_version = "1.0.0"
def documentfile_version = "1.0.1" def documentfile_version = "1.0.1"
def lifecycle_version = "2.1.0" def lifecycle_version = "2.2.0-beta01"
def room_version = "2.2.0-rc01" def room_version = "2.2.0"
def paging_version = "2.1.0" def paging_version = "2.1.0"
def preference_version = "1.1.0" def preference_version = "1.1.0"
def work_version = "2.2.0" def work_version = "2.2.0"
def exif_version = "1.1.0-beta01" def exif_version = "1.1.0-rc01"
def biometric_version = "1.0.0-beta02" def biometric_version = "1.0.0-rc01"
def billingclient_version = "2.0.3" def billingclient_version = "2.0.3"
def javamail_version = "1.6.4" def javamail_version = "1.6.4"
def jsoup_version = "1.12.1" def jsoup_version = "1.12.1"

@ -37,7 +37,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* @param <T> The type of the live data * @param <T> The type of the live data
* @hide internal * @hide internal
*/ */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public abstract class ComputableLiveData<T> { public abstract class ComputableLiveData<T> {
@SuppressWarnings("WeakerAccess") /* synthetic access */ @SuppressWarnings("WeakerAccess") /* synthetic access */
final Executor mExecutor; final Executor mExecutor;
@ -152,8 +152,7 @@ public abstract class ComputableLiveData<T> {
ArchTaskExecutor.getInstance().executeOnMainThread(mInvalidationRunnable); ArchTaskExecutor.getInstance().executeOnMainThread(mInvalidationRunnable);
} }
// TODO https://issuetracker.google.com/issues/112197238 @SuppressWarnings("WeakerAccess")
@SuppressWarnings({"WeakerAccess", "UnknownNullness"})
@WorkerThread @WorkerThread
protected abstract T compute(); protected abstract T compute();
} }

@ -80,6 +80,7 @@ public abstract class LiveData<T> {
@SuppressWarnings("FieldCanBeLocal") @SuppressWarnings("FieldCanBeLocal")
private boolean mDispatchInvalidated; private boolean mDispatchInvalidated;
private final Runnable mPostValueRunnable = new Runnable() { private final Runnable mPostValueRunnable = new Runnable() {
@SuppressWarnings("unchecked")
@Override @Override
public void run() { public void run() {
Object newValue; Object newValue;
@ -87,7 +88,6 @@ public abstract class LiveData<T> {
newValue = mPendingData; newValue = mPendingData;
mPendingData = NOT_SET; mPendingData = NOT_SET;
} }
//noinspection unchecked
setValue((T) newValue); setValue((T) newValue);
} }
}; };
@ -110,6 +110,7 @@ public abstract class LiveData<T> {
mVersion = START_VERSION; mVersion = START_VERSION;
} }
@SuppressWarnings("unchecked")
private void considerNotify(ObserverWrapper observer) { private void considerNotify(ObserverWrapper observer) {
if (!observer.mActive) { if (!observer.mActive) {
return; return;
@ -127,7 +128,6 @@ public abstract class LiveData<T> {
return; return;
} }
observer.mLastVersion = mVersion; observer.mLastVersion = mVersion;
//noinspection unchecked
observer.mObserver.onChanged((T) mData); observer.mObserver.onChanged((T) mData);
} }
@ -314,11 +314,11 @@ public abstract class LiveData<T> {
* *
* @return the current value * @return the current value
*/ */
@SuppressWarnings("unchecked")
@Nullable @Nullable
public T getValue() { public T getValue() {
Object data = mData; Object data = mData;
if (data != NOT_SET) { if (data != NOT_SET) {
//noinspection unchecked
return (T) data; return (T) data;
} }
return null; return null;
@ -386,7 +386,8 @@ public abstract class LiveData<T> {
} }
@Override @Override
public void onStateChanged(LifecycleOwner source, Lifecycle.Event event) { public void onStateChanged(@NonNull LifecycleOwner source,
@NonNull Lifecycle.Event event) {
if (mOwner.getLifecycle().getCurrentState() == DESTROYED) { if (mOwner.getLifecycle().getCurrentState() == DESTROYED) {
removeObserver(mObserver); removeObserver(mObserver);
return; return;

@ -65,7 +65,6 @@ public class Transformations {
* {@code mapFunction} to each value set. * {@code mapFunction} to each value set.
*/ */
@MainThread @MainThread
@NonNull
public static <X, Y> LiveData<Y> map( public static <X, Y> LiveData<Y> map(
@NonNull LiveData<X> source, @NonNull LiveData<X> source,
@NonNull final Function<X, Y> mapFunction) { @NonNull final Function<X, Y> mapFunction) {
@ -130,7 +129,6 @@ public class Transformations {
* value set * value set
*/ */
@MainThread @MainThread
@NonNull
public static <X, Y> LiveData<Y> switchMap( public static <X, Y> LiveData<Y> switchMap(
@NonNull LiveData<X> source, @NonNull LiveData<X> source,
@NonNull final Function<X, LiveData<Y>> switchMapFunction) { @NonNull final Function<X, LiveData<Y>> switchMapFunction) {
@ -160,35 +158,4 @@ public class Transformations {
}); });
return result; 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 <X> the generic type parameter of {@code source}
* @return a new {@link LiveData} of type {@code X}
*/
@MainThread
@NonNull
public static <X> LiveData<X> distinctUntilChanged(@NonNull LiveData<X> source) {
final MediatorLiveData<X> outputLiveData = new MediatorLiveData<>();
outputLiveData.addSource(source, new Observer<X>() {
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;
}
} }

Loading…
Cancel
Save