Search in sources :

Example 31 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project Rocket.Chat.Android by RocketChat.

the class DDPClientImpl method ping.

public void ping(final TaskCompletionSource<DDPClientCallback.Ping> task, @Nullable final String id) {
    final boolean requested = (TextUtils.isEmpty(id)) ? sendMessage("ping", null) : sendMessage("ping", json -> json.put("id", id));
    if (requested) {
        CompositeDisposable subscriptions = new CompositeDisposable();
        subscriptions.add(flowable.filter(callback -> callback instanceof RxWebSocketCallback.Message).map(callback -> ((RxWebSocketCallback.Message) callback).responseBodyString).map(DDPClientImpl::toJson).timeout(4, TimeUnit.SECONDS).subscribe(response -> {
            String msg = extractMsg(response);
            if ("pong".equals(msg)) {
                if (response.isNull("id")) {
                    task.setResult(new DDPClientCallback.Ping(client, null));
                    subscriptions.dispose();
                } else {
                    String _id = response.optString("id");
                    if (id.equals(_id)) {
                        task.setResult(new DDPClientCallback.Ping(client, id));
                        subscriptions.dispose();
                    }
                }
            }
        }, err -> task.setError(new DDPClientCallback.Ping.Timeout(client))));
        addErrorCallback(subscriptions, task);
    } else {
        task.trySetError(new DDPClientCallback.Closed(client));
    }
}
Also used : RxWebSocketCallback(chat.rocket.android_ddp.rx.RxWebSocketCallback) TimeoutException(java.util.concurrent.TimeoutException) TextUtils(android.text.TextUtils) NonNull(android.support.annotation.NonNull) RCLog(chat.rocket.android.log.RCLog) TaskCompletionSource(bolts.TaskCompletionSource) TimeUnit(java.util.concurrent.TimeUnit) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) JSONException(org.json.JSONException) RxWebSocket(chat.rocket.android_ddp.rx.RxWebSocket) JSONObject(org.json.JSONObject) OkHttpClient(okhttp3.OkHttpClient) Flowable(io.reactivex.Flowable) Nullable(android.support.annotation.Nullable) Task(bolts.Task) JSONArray(org.json.JSONArray) RxWebSocketCallback(chat.rocket.android_ddp.rx.RxWebSocketCallback) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 32 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project mosby by sockeqwe.

the class MviBasePresenter method bindIntentActually.

@MainThread
private <I> Observable<I> bindIntentActually(@NonNull V view, @NonNull IntentRelayBinderPair<?> relayBinderPair) {
    if (view == null) {
        throw new NullPointerException("View is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
    }
    if (relayBinderPair == null) {
        throw new NullPointerException("IntentRelayBinderPair is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
    }
    Subject<I> intentRelay = (Subject<I>) relayBinderPair.intentRelaySubject;
    if (intentRelay == null) {
        throw new NullPointerException("IntentRelay from binderPair is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
    }
    ViewIntentBinder<V, I> intentBinder = (ViewIntentBinder<V, I>) relayBinderPair.intentBinder;
    if (intentBinder == null) {
        throw new NullPointerException(ViewIntentBinder.class.getSimpleName() + " is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
    }
    Observable<I> intent = intentBinder.bind(view);
    if (intent == null) {
        throw new NullPointerException("Intent Observable returned from Binder " + intentBinder + " is null");
    }
    if (intentDisposables == null) {
        intentDisposables = new CompositeDisposable();
    }
    intentDisposables.add(intent.subscribeWith(new DisposableIntentObserver<I>(intentRelay)));
    return intentRelay;
}
Also used : Subject(io.reactivex.subjects.Subject) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) ReplaySubject(io.reactivex.subjects.ReplaySubject) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) MainThread(android.support.annotation.MainThread)

Example 33 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project Shuttle by timusus.

the class AestheticCheckBox method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subscriptions = new CompositeDisposable();
    // noinspection ConstantConditions
    subscriptions.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()));
    subscriptions.add(Aesthetic.get(getContext()).textColorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this)));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 34 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project DevRing by LJYcoder.

the class RxBus method register.

/**
 * 注册事件监听
 *
 * @param object
 */
public void register(Object object) {
    if (object == null) {
        throw new NullPointerException("Object to register must not be null.");
    }
    CompositeDisposable compositeDisposable = new CompositeDisposable();
    EventComposite subscriberMethods = EventFind.findAnnotatedSubscriberMethods(object, compositeDisposable);
    mEventCompositeMap.put(object, subscriberMethods);
    if (!STICKY_EVENT_MAP.isEmpty()) {
        // 如果有粘性事件,则发送粘性事件
        subscriberMethods.subscriberSticky(STICKY_EVENT_MAP);
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

CompositeDisposable (io.reactivex.disposables.CompositeDisposable)34 Nullable (android.support.annotation.Nullable)11 TimeUnit (java.util.concurrent.TimeUnit)10 Flowable (io.reactivex.Flowable)9 Test (org.junit.Test)9 NonNull (android.support.annotation.NonNull)6 TextUtils (android.text.TextUtils)6 Task (bolts.Task)6 TaskCompletionSource (bolts.TaskCompletionSource)6 RCLog (chat.rocket.android.log.RCLog)6 RxWebSocket (chat.rocket.android_ddp.rx.RxWebSocket)6 RxWebSocketCallback (chat.rocket.android_ddp.rx.RxWebSocketCallback)6 Consumer (io.reactivex.functions.Consumer)6 Bundle (android.os.Bundle)5 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)5 BindView (butterknife.BindView)5 ButterKnife (butterknife.ButterKnife)5 MainActivity (com.morihacky.android.rxjava.MainActivity)5