- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
214 lines
9.4 KiB
Java
214 lines
9.4 KiB
Java
package androidx.lifecycle;
|
|
|
|
import androidx.annotation.CheckResult;
|
|
import androidx.annotation.MainThread;
|
|
import androidx.arch.core.util.Function;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlin.jvm.internal.Ref;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Transformations {
|
|
@CheckResult
|
|
@MainThread
|
|
public static final <X, Y> LiveData<Y> map(LiveData<X> liveData, final Function1 transform) {
|
|
Intrinsics.checkNotNullParameter(liveData, "<this>");
|
|
Intrinsics.checkNotNullParameter(transform, "transform");
|
|
final MediatorLiveData mediatorLiveData = new MediatorLiveData();
|
|
mediatorLiveData.addSource(liveData, new Transformations$sam$androidx_lifecycle_Observer$0(new Function1() { // from class: androidx.lifecycle.Transformations$map$1
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
{
|
|
super(1);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj) {
|
|
m159invoke((Transformations$map$1) obj);
|
|
return Unit.INSTANCE;
|
|
}
|
|
|
|
/* renamed from: invoke, reason: collision with other method in class */
|
|
public final void m159invoke(X x) {
|
|
mediatorLiveData.setValue(transform.invoke(x));
|
|
}
|
|
}));
|
|
return mediatorLiveData;
|
|
}
|
|
|
|
@CheckResult
|
|
@MainThread
|
|
public static final /* synthetic */ LiveData map(LiveData liveData, final Function mapFunction) {
|
|
Intrinsics.checkNotNullParameter(liveData, "<this>");
|
|
Intrinsics.checkNotNullParameter(mapFunction, "mapFunction");
|
|
final MediatorLiveData mediatorLiveData = new MediatorLiveData();
|
|
mediatorLiveData.addSource(liveData, new Transformations$sam$androidx_lifecycle_Observer$0(new Function1() { // from class: androidx.lifecycle.Transformations$map$2
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
{
|
|
super(1);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj) {
|
|
m160invoke(obj);
|
|
return Unit.INSTANCE;
|
|
}
|
|
|
|
/* renamed from: invoke, reason: collision with other method in class */
|
|
public final void m160invoke(Object obj) {
|
|
MediatorLiveData.this.setValue(mapFunction.apply(obj));
|
|
}
|
|
}));
|
|
return mediatorLiveData;
|
|
}
|
|
|
|
@CheckResult
|
|
@MainThread
|
|
public static final <X, Y> LiveData<Y> switchMap(LiveData<X> liveData, final Function1 transform) {
|
|
Intrinsics.checkNotNullParameter(liveData, "<this>");
|
|
Intrinsics.checkNotNullParameter(transform, "transform");
|
|
final MediatorLiveData mediatorLiveData = new MediatorLiveData();
|
|
mediatorLiveData.addSource(liveData, new Observer<X>() { // from class: androidx.lifecycle.Transformations$switchMap$1
|
|
private LiveData<Y> liveData;
|
|
|
|
public final LiveData<Y> getLiveData() {
|
|
return this.liveData;
|
|
}
|
|
|
|
public final void setLiveData(LiveData<Y> liveData2) {
|
|
this.liveData = liveData2;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // androidx.lifecycle.Observer
|
|
public void onChanged(X x) {
|
|
LiveData<Y> liveData2 = (LiveData) Function1.this.invoke(x);
|
|
Object obj = this.liveData;
|
|
if (obj == liveData2) {
|
|
return;
|
|
}
|
|
if (obj != null) {
|
|
MediatorLiveData<Y> mediatorLiveData2 = mediatorLiveData;
|
|
Intrinsics.checkNotNull(obj);
|
|
mediatorLiveData2.removeSource(obj);
|
|
}
|
|
this.liveData = liveData2;
|
|
if (liveData2 != 0) {
|
|
MediatorLiveData<Y> mediatorLiveData3 = mediatorLiveData;
|
|
Intrinsics.checkNotNull(liveData2);
|
|
final MediatorLiveData<Y> mediatorLiveData4 = mediatorLiveData;
|
|
mediatorLiveData3.addSource(liveData2, new Transformations$sam$androidx_lifecycle_Observer$0(new Function1() { // from class: androidx.lifecycle.Transformations$switchMap$1$onChanged$1
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
{
|
|
super(1);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj2) {
|
|
m161invoke((Transformations$switchMap$1$onChanged$1) obj2);
|
|
return Unit.INSTANCE;
|
|
}
|
|
|
|
/* renamed from: invoke, reason: collision with other method in class */
|
|
public final void m161invoke(Y y) {
|
|
mediatorLiveData4.setValue(y);
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
});
|
|
return mediatorLiveData;
|
|
}
|
|
|
|
@CheckResult
|
|
@MainThread
|
|
public static final /* synthetic */ LiveData switchMap(LiveData liveData, final Function switchMapFunction) {
|
|
Intrinsics.checkNotNullParameter(liveData, "<this>");
|
|
Intrinsics.checkNotNullParameter(switchMapFunction, "switchMapFunction");
|
|
final MediatorLiveData mediatorLiveData = new MediatorLiveData();
|
|
mediatorLiveData.addSource(liveData, new Observer() { // from class: androidx.lifecycle.Transformations$switchMap$2
|
|
private LiveData liveData;
|
|
|
|
public final LiveData getLiveData() {
|
|
return this.liveData;
|
|
}
|
|
|
|
public final void setLiveData(LiveData liveData2) {
|
|
this.liveData = liveData2;
|
|
}
|
|
|
|
@Override // androidx.lifecycle.Observer
|
|
public void onChanged(Object obj) {
|
|
LiveData liveData2 = (LiveData) Function.this.apply(obj);
|
|
LiveData liveData3 = this.liveData;
|
|
if (liveData3 == liveData2) {
|
|
return;
|
|
}
|
|
if (liveData3 != null) {
|
|
MediatorLiveData mediatorLiveData2 = mediatorLiveData;
|
|
Intrinsics.checkNotNull(liveData3);
|
|
mediatorLiveData2.removeSource(liveData3);
|
|
}
|
|
this.liveData = liveData2;
|
|
if (liveData2 != null) {
|
|
MediatorLiveData mediatorLiveData3 = mediatorLiveData;
|
|
Intrinsics.checkNotNull(liveData2);
|
|
final MediatorLiveData mediatorLiveData4 = mediatorLiveData;
|
|
mediatorLiveData3.addSource(liveData2, new Transformations$sam$androidx_lifecycle_Observer$0(new Function1() { // from class: androidx.lifecycle.Transformations$switchMap$2$onChanged$1
|
|
{
|
|
super(1);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj2) {
|
|
m162invoke(obj2);
|
|
return Unit.INSTANCE;
|
|
}
|
|
|
|
/* renamed from: invoke, reason: collision with other method in class */
|
|
public final void m162invoke(Object obj2) {
|
|
MediatorLiveData.this.setValue(obj2);
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
});
|
|
return mediatorLiveData;
|
|
}
|
|
|
|
@CheckResult
|
|
@MainThread
|
|
public static final <X> LiveData<X> distinctUntilChanged(LiveData<X> liveData) {
|
|
Intrinsics.checkNotNullParameter(liveData, "<this>");
|
|
final MediatorLiveData mediatorLiveData = new MediatorLiveData();
|
|
final Ref.BooleanRef booleanRef = new Ref.BooleanRef();
|
|
booleanRef.element = true;
|
|
if (liveData.isInitialized()) {
|
|
mediatorLiveData.setValue(liveData.getValue());
|
|
booleanRef.element = false;
|
|
}
|
|
mediatorLiveData.addSource(liveData, new Transformations$sam$androidx_lifecycle_Observer$0(new Function1() { // from class: androidx.lifecycle.Transformations$distinctUntilChanged$1
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
{
|
|
super(1);
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public /* bridge */ /* synthetic */ Object invoke(Object obj) {
|
|
m158invoke((Transformations$distinctUntilChanged$1) obj);
|
|
return Unit.INSTANCE;
|
|
}
|
|
|
|
/* renamed from: invoke, reason: collision with other method in class */
|
|
public final void m158invoke(X x) {
|
|
Object value = mediatorLiveData.getValue();
|
|
if (booleanRef.element || ((value == null && x != 0) || !(value == null || Intrinsics.areEqual(value, x)))) {
|
|
booleanRef.element = false;
|
|
mediatorLiveData.setValue(x);
|
|
}
|
|
}
|
|
}));
|
|
return mediatorLiveData;
|
|
}
|
|
}
|