55 lines
2.2 KiB
Java
55 lines
2.2 KiB
Java
package com.discord.utilities.viewcontroller;
|
|
|
|
import android.content.Context;
|
|
import android.view.View;
|
|
import androidx.annotation.MainThread;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import d0.z.d.m;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.Ref$ObjectRef;
|
|
import rx.Observable;
|
|
import rx.Subscription;
|
|
/* compiled from: RxViewController.kt */
|
|
public abstract class RxViewController<V extends View, T> {
|
|
private Subscription subscription;
|
|
private final V view;
|
|
|
|
public RxViewController(V v) {
|
|
m.checkNotNullParameter(v, "view");
|
|
this.view = v;
|
|
}
|
|
|
|
private final <T> Subscription connectViewRx(View view, Observable<T> observable, Function1<? super T, Unit> function1) {
|
|
Ref$ObjectRef ref$ObjectRef = new Ref$ObjectRef();
|
|
ref$ObjectRef.element = null;
|
|
Observable<T> a02 = observable.a0(new ViewDetachedFromWindowObservable(view).observe());
|
|
m.checkNotNullExpressionValue(a02, "observable\n .take…servable(view).observe())");
|
|
Observable<T> x2 = ObservableExtensionsKt.ui(ObservableExtensionsKt.computationLatest(a02)).x(new RxViewController$connectViewRx$1(view));
|
|
m.checkNotNullExpressionValue(x2, "observable\n .take…view.isAttachedToWindow }");
|
|
ObservableExtensionsKt.appSubscribe$default(x2, getClass(), (Context) null, new RxViewController$connectViewRx$2(ref$ObjectRef), (Function1) null, (Function0) null, (Function0) null, new RxViewController$connectViewRx$3(function1), 58, (Object) null);
|
|
T t = ref$ObjectRef.element;
|
|
if (t == null) {
|
|
m.throwUninitializedPropertyAccessException("subscriptionResult");
|
|
}
|
|
return t;
|
|
}
|
|
|
|
@MainThread
|
|
public final void bind() {
|
|
Subscription subscription = this.subscription;
|
|
if (subscription != null) {
|
|
subscription.unsubscribe();
|
|
}
|
|
this.subscription = connectViewRx(this.view, observeState(), new RxViewController$bind$1(this));
|
|
}
|
|
|
|
public abstract void configureView(T t);
|
|
|
|
public final V getView() {
|
|
return this.view;
|
|
}
|
|
|
|
public abstract Observable<T> observeState();
|
|
}
|