Files
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

92 lines
2.8 KiB
Java

package androidx.lifecycle;
import androidx.annotation.CallSuper;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.arch.core.internal.SafeIterableMap;
import java.util.Iterator;
import java.util.Map;
/* loaded from: classes.dex */
public class MediatorLiveData<T> extends MutableLiveData<T> {
private SafeIterableMap<LiveData<?>, Source<?>> mSources;
public MediatorLiveData() {
this.mSources = new SafeIterableMap<>();
}
public MediatorLiveData(T t) {
super(t);
this.mSources = new SafeIterableMap<>();
}
@MainThread
public <S> void addSource(@NonNull LiveData<S> liveData, @NonNull Observer<? super S> observer) {
if (liveData == null) {
throw new NullPointerException("source cannot be null");
}
Source<?> source = new Source<>(liveData, observer);
Source<?> putIfAbsent = this.mSources.putIfAbsent(liveData, source);
if (putIfAbsent != null && putIfAbsent.mObserver != observer) {
throw new IllegalArgumentException("This source was already added with the different observer");
}
if (putIfAbsent == null && hasActiveObservers()) {
source.plug();
}
}
@MainThread
public <S> void removeSource(@NonNull LiveData<S> liveData) {
Source<?> remove = this.mSources.remove(liveData);
if (remove != null) {
remove.unplug();
}
}
@Override // androidx.lifecycle.LiveData
@CallSuper
public void onActive() {
Iterator<Map.Entry<LiveData<?>, Source<?>>> it = this.mSources.iterator();
while (it.hasNext()) {
it.next().getValue().plug();
}
}
@Override // androidx.lifecycle.LiveData
@CallSuper
public void onInactive() {
Iterator<Map.Entry<LiveData<?>, Source<?>>> it = this.mSources.iterator();
while (it.hasNext()) {
it.next().getValue().unplug();
}
}
public static class Source<V> implements Observer<V> {
final LiveData<V> mLiveData;
final Observer<? super V> mObserver;
int mVersion = -1;
public Source(LiveData<V> liveData, Observer<? super V> observer) {
this.mLiveData = liveData;
this.mObserver = observer;
}
public void plug() {
this.mLiveData.observeForever(this);
}
public void unplug() {
this.mLiveData.removeObserver(this);
}
@Override // androidx.lifecycle.Observer
public void onChanged(@Nullable V v) {
if (this.mVersion != this.mLiveData.getVersion()) {
this.mVersion = this.mLiveData.getVersion();
this.mObserver.onChanged(v);
}
}
}
}