use of io.reactivex.disposables.CompositeDisposable in project Shuttle by timusus.
the class AestheticTextInputEditText method onAttachedToWindow.
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
subs = new CompositeDisposable();
subs.add(Aesthetic.get(getContext()).textColorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this), onErrorLogAndRethrow()));
subs.add(Aesthetic.get(getContext()).textColorSecondary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewHintTextColorAction.create(this), onErrorLogAndRethrow()));
// noinspection ConstantConditions
subs.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {
@Override
public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
invalidateColors(colorIsDarkState);
}
}, onErrorLogAndRethrow()));
}
use of io.reactivex.disposables.CompositeDisposable in project Tangram-Android by alibaba.
the class RxExposureSupportTest method testDestroyExposure.
@Test
@SmallTest
@UiThreadTest
public void testDestroyExposure() {
ExposureSupport exposureSupport = new ExposureSupport() {
private CompositeDisposable mCompositeDisposable = new CompositeDisposable();
Consumer<ClickExposureCellOp> consumer = new Consumer<ClickExposureCellOp>() {
@Override
public void accept(ClickExposureCellOp clickEvent) throws Exception {
// should not execute here
assertTrue(false);
assertTrue(Looper.myLooper() == Looper.getMainLooper());
assertEquals(clickEvent.getArg1(), mView1);
assertEquals(clickEvent.getArg2(), mBaseCell1);
assertEquals(clickEvent.getArg3().intValue(), 10);
Log.d("RxExposureSupportTest", "testExposureTaskAsyncThenCancelItButResubscribe mEventType " + clickEvent.getArg3());
Log.d("RxExposureSupportTest", "testDestroyExposure thread " + Thread.currentThread().getId() + ": " + Thread.currentThread().getName());
}
};
@Override
public void onExposure(@NonNull Card card, int offset, int position) {
}
};
mServiceManager.register(ExposureSupport.class, exposureSupport);
mBaseCell1.exposure(mView1);
mBaseCell1.exposure(mView1);
exposureSupport.destroy();
}
use of io.reactivex.disposables.CompositeDisposable in project BaseProject by fly803.
the class RxBus method registerSubscriber.
public <T> void registerSubscriber(@NonNull Object observer, @NonNull CustomSubscriber<T> subscriber) {
ObjectHelper.requireNonNull(observer, "Observer to register must not be null.");
ObjectHelper.requireNonNull(subscriber, "Subscriber to register must not be null.");
SUBSCRIBERS.putIfAbsent(observer.getClass(), new CopyOnWriteArraySet<CustomSubscriber<?>>());
Set<CustomSubscriber<?>> subscribers = SUBSCRIBERS.get(observer.getClass());
if (subscribers.contains(subscriber))
throw new IllegalArgumentException("Subscriber has already been registered.");
else
subscribers.add(subscriber);
Observable<T> observable = bus.ofType(subscriber.getEventClass()).observeOn(subscriber.getScheduler() == null ? AndroidSchedulers.mainThread() : subscriber.getScheduler());
Class<?> observerClass = observer.getClass();
OBSERVERS.putIfAbsent(observerClass, new CompositeDisposable());
CompositeDisposable composite = OBSERVERS.get(observerClass);
composite.add(((subscriber.getFilter() == null) ? observable : observable.filter(subscriber.getFilter())).subscribe(subscriber));
}
use of io.reactivex.disposables.CompositeDisposable in project BaseProject by fly803.
the class RxBus method register.
public void register(@NonNull Object observer) {
ObjectHelper.requireNonNull(observer, "Observer to register must not be null.");
Class<?> observerClass = observer.getClass();
if (OBSERVERS.putIfAbsent(observerClass, new CompositeDisposable()) != null) {
return;
}
// if (OBSERVERS.putIfAbsent(observerClass, new CompositeDisposable()) != null)
// throw new IllegalArgumentException("Observer has already been registered.");
CompositeDisposable composite = OBSERVERS.get(observerClass);
Set<Class<?>> events = new HashSet<>();
for (Method method : observerClass.getDeclaredMethods()) {
if (method.isBridge() || method.isSynthetic())
continue;
if (!method.isAnnotationPresent(Subscribe.class))
continue;
int mod = method.getModifiers();
if (Modifier.isStatic(mod) || !Modifier.isPublic(mod))
throw new IllegalArgumentException("Method " + method.getName() + " has @Subscribe annotation must be public, non-static");
Class<?>[] params = method.getParameterTypes();
if (params.length != 1)
throw new IllegalArgumentException("Method " + method.getName() + " has @Subscribe annotation must require a single argument");
Class<?> eventClass = params[0];
if (eventClass.isInterface())
throw new IllegalArgumentException("Event class must be on a concrete class type.");
if (!events.add(eventClass))
throw new IllegalArgumentException("Subscriber for " + eventClass.getSimpleName() + " has already been registered.");
composite.add(bus.ofType(eventClass).observeOn(AndroidSchedulers.mainThread()).subscribe(new AnnotatedSubscriber<>(observer, method)));
}
}
use of io.reactivex.disposables.CompositeDisposable in project seven_develop by seven123456.
the class RxLifeManager method setCompositeDisposableOnDestroy.
public void setCompositeDisposableOnDestroy(Disposable s) {
if (compositeDisposableOnDestroy != null) {
compositeDisposableOnDestroy.add(s);
} else {
compositeDisposableOnDestroy = new CompositeDisposable();
compositeDisposableOnDestroy.add(s);
}
}
Aggregations