113 lines
4.1 KiB
Java
113 lines
4.1 KiB
Java
package androidx.lifecycle;
|
|
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.annotation.WorkerThread;
|
|
import androidx.arch.core.executor.ArchTaskExecutor;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public abstract class ComputableLiveData<T> {
|
|
public final AtomicBoolean mComputing;
|
|
public final Executor mExecutor;
|
|
public final AtomicBoolean mInvalid;
|
|
@VisibleForTesting
|
|
public final Runnable mInvalidationRunnable;
|
|
public final LiveData<T> mLiveData;
|
|
@VisibleForTesting
|
|
public final Runnable mRefreshRunnable;
|
|
|
|
/* renamed from: androidx.lifecycle.ComputableLiveData$1 reason: invalid class name */
|
|
public class AnonymousClass1 extends LiveData<T> {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // androidx.lifecycle.LiveData
|
|
public void onActive() {
|
|
ComputableLiveData computableLiveData = ComputableLiveData.this;
|
|
computableLiveData.mExecutor.execute(computableLiveData.mRefreshRunnable);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.lifecycle.ComputableLiveData$2 reason: invalid class name */
|
|
public class AnonymousClass2 implements Runnable {
|
|
public AnonymousClass2() {
|
|
}
|
|
|
|
/* JADX INFO: finally extract failed */
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v4, resolved type: androidx.lifecycle.LiveData<T> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // java.lang.Runnable
|
|
@WorkerThread
|
|
public void run() {
|
|
do {
|
|
boolean z2 = false;
|
|
if (ComputableLiveData.this.mComputing.compareAndSet(false, true)) {
|
|
Object obj = null;
|
|
boolean z3 = false;
|
|
while (ComputableLiveData.this.mInvalid.compareAndSet(true, false)) {
|
|
try {
|
|
obj = ComputableLiveData.this.compute();
|
|
z3 = true;
|
|
} catch (Throwable th) {
|
|
ComputableLiveData.this.mComputing.set(false);
|
|
throw th;
|
|
}
|
|
}
|
|
if (z3) {
|
|
ComputableLiveData.this.mLiveData.postValue(obj);
|
|
}
|
|
ComputableLiveData.this.mComputing.set(false);
|
|
z2 = z3;
|
|
}
|
|
if (!z2) {
|
|
return;
|
|
}
|
|
} while (ComputableLiveData.this.mInvalid.get());
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.lifecycle.ComputableLiveData$3 reason: invalid class name */
|
|
public class AnonymousClass3 implements Runnable {
|
|
public AnonymousClass3() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
@MainThread
|
|
public void run() {
|
|
boolean hasActiveObservers = ComputableLiveData.this.mLiveData.hasActiveObservers();
|
|
if (ComputableLiveData.this.mInvalid.compareAndSet(false, true) && hasActiveObservers) {
|
|
ComputableLiveData computableLiveData = ComputableLiveData.this;
|
|
computableLiveData.mExecutor.execute(computableLiveData.mRefreshRunnable);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ComputableLiveData() {
|
|
this(ArchTaskExecutor.getIOThreadExecutor());
|
|
}
|
|
|
|
public ComputableLiveData(@NonNull Executor executor) {
|
|
this.mInvalid = new AtomicBoolean(true);
|
|
this.mComputing = new AtomicBoolean(false);
|
|
this.mRefreshRunnable = new AnonymousClass2();
|
|
this.mInvalidationRunnable = new AnonymousClass3();
|
|
this.mExecutor = executor;
|
|
this.mLiveData = new AnonymousClass1();
|
|
}
|
|
|
|
@WorkerThread
|
|
public abstract T compute();
|
|
|
|
@NonNull
|
|
public LiveData<T> getLiveData() {
|
|
return this.mLiveData;
|
|
}
|
|
|
|
public void invalidate() {
|
|
ArchTaskExecutor.getInstance().executeOnMainThread(this.mInvalidationRunnable);
|
|
}
|
|
}
|