Search in sources :

Example 41 with CompositeDisposable

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()));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 42 with CompositeDisposable

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();
}
Also used : ExposureSupport(com.tmall.wireless.tangram.support.ExposureSupport) Consumer(io.reactivex.functions.Consumer) NonNull(android.support.annotation.NonNull) ClickExposureCellOp(com.tmall.wireless.tangram.op.ClickExposureCellOp) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Card(com.tmall.wireless.tangram.dataparser.concrete.Card) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 43 with CompositeDisposable

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));
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 44 with CompositeDisposable

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)));
    }
}
Also used : Method(java.lang.reflect.Method) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) HashSet(java.util.HashSet)

Example 45 with CompositeDisposable

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);
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

CompositeDisposable (io.reactivex.disposables.CompositeDisposable)81 Nullable (android.support.annotation.Nullable)15 Test (org.junit.Test)11 Bundle (android.os.Bundle)10 View (android.view.View)10 Consumer (io.reactivex.functions.Consumer)10 TimeUnit (java.util.concurrent.TimeUnit)10 Flowable (io.reactivex.Flowable)9 NonNull (android.support.annotation.NonNull)8 TextUtils (android.text.TextUtils)7 ViewGroup (android.view.ViewGroup)7 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)7 TextView (android.widget.TextView)6 BindView (butterknife.BindView)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Intent (android.content.Intent)5 LayoutInflater (android.view.LayoutInflater)5 Task (bolts.Task)5 TaskCompletionSource (bolts.TaskCompletionSource)5