Initial commit
This commit is contained in:
33
sources/io/reactivex/android/MainThreadDisposable.java
Normal file
33
sources/io/reactivex/android/MainThreadDisposable.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package io.reactivex.android;
|
||||
|
||||
import android.os.Looper;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public abstract class MainThreadDisposable implements Disposable {
|
||||
private final AtomicBoolean a = new AtomicBoolean();
|
||||
|
||||
public final boolean a() {
|
||||
return this.a.get();
|
||||
}
|
||||
|
||||
protected abstract void b();
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public final void dispose() {
|
||||
if (this.a.compareAndSet(false, true)) {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
b();
|
||||
} else {
|
||||
AndroidSchedulers.a().a(new Runnable() { // from class: io.reactivex.android.MainThreadDisposable.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
MainThreadDisposable.this.b();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
sources/io/reactivex/android/plugins/RxAndroidPlugins.java
Normal file
58
sources/io/reactivex/android/plugins/RxAndroidPlugins.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package io.reactivex.android.plugins;
|
||||
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.exceptions.Exceptions;
|
||||
import io.reactivex.functions.Function;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class RxAndroidPlugins {
|
||||
private static volatile Function<Callable<Scheduler>, Scheduler> a;
|
||||
private static volatile Function<Scheduler, Scheduler> b;
|
||||
|
||||
public static Scheduler a(Scheduler scheduler) {
|
||||
if (scheduler == null) {
|
||||
throw new NullPointerException("scheduler == null");
|
||||
}
|
||||
Function<Scheduler, Scheduler> function = b;
|
||||
return function == null ? scheduler : (Scheduler) a((Function<Scheduler, R>) function, scheduler);
|
||||
}
|
||||
|
||||
public static Scheduler b(Callable<Scheduler> callable) {
|
||||
if (callable == null) {
|
||||
throw new NullPointerException("scheduler == null");
|
||||
}
|
||||
Function<Callable<Scheduler>, Scheduler> function = a;
|
||||
return function == null ? a(callable) : a(function, callable);
|
||||
}
|
||||
|
||||
static Scheduler a(Callable<Scheduler> callable) {
|
||||
try {
|
||||
Scheduler call = callable.call();
|
||||
if (call != null) {
|
||||
return call;
|
||||
}
|
||||
throw new NullPointerException("Scheduler Callable returned null");
|
||||
} catch (Throwable th) {
|
||||
Exceptions.a(th);
|
||||
throw null;
|
||||
}
|
||||
}
|
||||
|
||||
static Scheduler a(Function<Callable<Scheduler>, Scheduler> function, Callable<Scheduler> callable) {
|
||||
Scheduler scheduler = (Scheduler) a((Function<Callable<Scheduler>, R>) function, callable);
|
||||
if (scheduler != null) {
|
||||
return scheduler;
|
||||
}
|
||||
throw new NullPointerException("Scheduler Callable returned null");
|
||||
}
|
||||
|
||||
static <T, R> R a(Function<T, R> function, T t) {
|
||||
try {
|
||||
return function.apply(t);
|
||||
} catch (Throwable th) {
|
||||
Exceptions.a(th);
|
||||
throw null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package io.reactivex.android.schedulers;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.android.plugins.RxAndroidPlugins;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class AndroidSchedulers {
|
||||
private static final Scheduler a = RxAndroidPlugins.b(new Callable<Scheduler>() { // from class: io.reactivex.android.schedulers.AndroidSchedulers.1
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // java.util.concurrent.Callable
|
||||
public Scheduler call() throws Exception {
|
||||
return MainHolder.a;
|
||||
}
|
||||
});
|
||||
|
||||
private static final class MainHolder {
|
||||
static final Scheduler a = new HandlerScheduler(new Handler(Looper.getMainLooper()), false);
|
||||
}
|
||||
|
||||
public static Scheduler a() {
|
||||
return RxAndroidPlugins.a(a);
|
||||
}
|
||||
}
|
106
sources/io/reactivex/android/schedulers/HandlerScheduler.java
Normal file
106
sources/io/reactivex/android/schedulers/HandlerScheduler.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package io.reactivex.android.schedulers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.disposables.Disposables;
|
||||
import io.reactivex.plugins.RxJavaPlugins;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
final class HandlerScheduler extends Scheduler {
|
||||
private final Handler b;
|
||||
private final boolean c;
|
||||
|
||||
private static final class HandlerWorker extends Scheduler.Worker {
|
||||
private final Handler a;
|
||||
private final boolean b;
|
||||
private volatile boolean c;
|
||||
|
||||
HandlerWorker(Handler handler, boolean z) {
|
||||
this.a = handler;
|
||||
this.b = z;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler.Worker
|
||||
@SuppressLint({"NewApi"})
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
if (runnable == null) {
|
||||
throw new NullPointerException("run == null");
|
||||
}
|
||||
if (timeUnit == null) {
|
||||
throw new NullPointerException("unit == null");
|
||||
}
|
||||
if (this.c) {
|
||||
return Disposables.a();
|
||||
}
|
||||
ScheduledRunnable scheduledRunnable = new ScheduledRunnable(this.a, RxJavaPlugins.a(runnable));
|
||||
Message obtain = Message.obtain(this.a, scheduledRunnable);
|
||||
obtain.obj = this;
|
||||
if (this.b) {
|
||||
obtain.setAsynchronous(true);
|
||||
}
|
||||
this.a.sendMessageDelayed(obtain, timeUnit.toMillis(j));
|
||||
if (!this.c) {
|
||||
return scheduledRunnable;
|
||||
}
|
||||
this.a.removeCallbacks(scheduledRunnable);
|
||||
return Disposables.a();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
this.c = true;
|
||||
this.a.removeCallbacksAndMessages(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ScheduledRunnable implements Runnable, Disposable {
|
||||
private final Handler a;
|
||||
private final Runnable b;
|
||||
|
||||
ScheduledRunnable(Handler handler, Runnable runnable) {
|
||||
this.a = handler;
|
||||
this.b = runnable;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.disposables.Disposable
|
||||
public void dispose() {
|
||||
this.a.removeCallbacks(this);
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
this.b.run();
|
||||
} catch (Throwable th) {
|
||||
RxJavaPlugins.b(th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HandlerScheduler(Handler handler, boolean z) {
|
||||
this.b = handler;
|
||||
this.c = z;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Disposable a(Runnable runnable, long j, TimeUnit timeUnit) {
|
||||
if (runnable == null) {
|
||||
throw new NullPointerException("run == null");
|
||||
}
|
||||
if (timeUnit == null) {
|
||||
throw new NullPointerException("unit == null");
|
||||
}
|
||||
ScheduledRunnable scheduledRunnable = new ScheduledRunnable(this.b, RxJavaPlugins.a(runnable));
|
||||
this.b.postDelayed(scheduledRunnable, timeUnit.toMillis(j));
|
||||
return scheduledRunnable;
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Scheduler
|
||||
public Scheduler.Worker a() {
|
||||
return new HandlerWorker(this.b, this.c);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user