Search in sources :

Example 96 with Disposable

use of io.reactivex.disposables.Disposable in project Varis-Android by dkhmelenko.

the class SearchResultsPresenter method startRepoSearch.

/**
     * Starts repository search
     *
     * @param query Query string for search
     */
public void startRepoSearch(String query) {
    Single<List<Repo>> reposSingle;
    if (!TextUtils.isEmpty(query)) {
        reposSingle = mTravisRestClient.getApiService().getRepos(query);
    } else {
        reposSingle = mTravisRestClient.getApiService().getRepos();
    }
    Disposable subscription = reposSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((repos, throwable) -> {
        getView().hideProgress();
        if (throwable == null) {
            getView().setSearchResults(repos);
        } else {
            getView().showLoadingError(throwable.getMessage());
        }
    });
    mSubscriptions.add(subscription);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List)

Example 97 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava-Android-Samples by kaushikgopal.

the class PaginationAutoFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    _disposables = new CompositeDisposable();
    Disposable d2 = _paginator.onBackpressureDrop().doOnNext(i -> {
        _requestUnderWay = true;
        _progressBar.setVisibility(View.VISIBLE);
    }).concatMap(this::_itemsFromNetworkCall).observeOn(AndroidSchedulers.mainThread()).map(items -> {
        _adapter.addItems(items);
        _adapter.notifyDataSetChanged();
        return items;
    }).doOnNext(i -> {
        _requestUnderWay = false;
        _progressBar.setVisibility(View.INVISIBLE);
    }).subscribe();
    // I'm using an RxBus purely to hear from a nested button click
    // we don't really need Rx for this part. it's just easy ¯\_(ツ)_/¯
    Disposable d1 = _bus.asFlowable().filter(o -> !_requestUnderWay).subscribe(event -> {
        if (event instanceof PaginationAutoAdapter.PageEvent) {
            int nextPage = _adapter.getItemCount();
            _paginator.onNext(nextPage);
        }
    });
    _disposables.add(d1);
    _disposables.add(d2);
    _paginator.onNext(0);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) ButterKnife(butterknife.ButterKnife) RxBus(com.morihacky.android.rxjava.rxbus.RxBus) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MainActivity(com.morihacky.android.rxjava.MainActivity) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) R(com.morihacky.android.rxjava.R) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) BaseFragment(com.morihacky.android.rxjava.fragments.BaseFragment) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Flowable(io.reactivex.Flowable) View(android.view.View) Nullable(android.support.annotation.Nullable) PublishProcessor(io.reactivex.processors.PublishProcessor) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 98 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava-Android-Samples by kaushikgopal.

the class PollingFragment method onStartSimplePollingClicked.

@OnClick(R.id.btn_start_simple_polling)
public void onStartSimplePollingClicked() {
    final int pollCount = POLL_COUNT;
    Disposable d = Flowable.interval(INITIAL_DELAY, POLLING_INTERVAL, TimeUnit.MILLISECONDS).map(this::_doNetworkCallAndGetStringResult).take(pollCount).doOnSubscribe(subscription -> {
        _log(String.format("Start simple polling - %s", _counter));
    }).subscribe(taskName -> {
        _log(String.format(Locale.US, "Executing polled task [%s] now time : [xx:%02d]", taskName, _getSecondHand()));
    });
    _disposables.add(d);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Context(android.content.Context) Bundle(android.os.Bundle) ButterKnife(butterknife.ButterKnife) OnClick(butterknife.OnClick) BindView(butterknife.BindView) R(com.morihacky.android.rxjava.R) ArrayList(java.util.ArrayList) Flowable(io.reactivex.Flowable) Locale(java.util.Locale) Handler(android.os.Handler) Looper(android.os.Looper) View(android.view.View) Unbinder(butterknife.Unbinder) LayoutInflater(android.view.LayoutInflater) Publisher(org.reactivestreams.Publisher) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) TimeUnit(java.util.concurrent.TimeUnit) ArrayAdapter(android.widget.ArrayAdapter) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Function(io.reactivex.functions.Function) ListView(android.widget.ListView) Nullable(android.support.annotation.Nullable) OnClick(butterknife.OnClick)

Example 99 with Disposable

use of io.reactivex.disposables.Disposable in project camel by apache.

the class BasicPublisherTest method testMultipleSubscriptions.

@Test
public void testMultipleSubscriptions() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("timer:tick?period=50").setBody().header(Exchange.TIMER_COUNTER).to("reactive-streams:unbounded");
        }
    }.addRoutesToCamelContext(context);
    CountDownLatch latch1 = new CountDownLatch(5);
    Disposable disp1 = Observable.fromPublisher(CamelReactiveStreams.get(context).fromStream("unbounded", Integer.class)).subscribe(n -> latch1.countDown());
    context.start();
    // Add another subscription
    CountDownLatch latch2 = new CountDownLatch(5);
    Disposable disp2 = Observable.fromPublisher(CamelReactiveStreams.get(context).fromStream("unbounded", Integer.class)).subscribe(n -> latch2.countDown());
    assertTrue(latch1.await(5, TimeUnit.SECONDS));
    assertTrue(latch2.await(5, TimeUnit.SECONDS));
    // Unsubscribe both
    disp1.dispose();
    disp2.dispose();
    // No active subscriptions, warnings expected
    Thread.sleep(60);
    // Add another subscription
    CountDownLatch latch3 = new CountDownLatch(5);
    Disposable disp3 = Observable.fromPublisher(CamelReactiveStreams.get(context).fromStream("unbounded", Integer.class)).subscribe(n -> latch3.countDown());
    assertTrue(latch3.await(5, TimeUnit.SECONDS));
    disp3.dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) RouteBuilder(org.apache.camel.builder.RouteBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 100 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class SingleSubscribeOn method subscribeActual.

@Override
protected void subscribeActual(final SingleObserver<? super T> s) {
    final SubscribeOnObserver<T> parent = new SubscribeOnObserver<T>(s, source);
    s.onSubscribe(parent);
    Disposable f = scheduler.scheduleDirect(parent);
    parent.task.replace(f);
}
Also used : Disposable(io.reactivex.disposables.Disposable)

Aggregations

Disposable (io.reactivex.disposables.Disposable)199 Test (org.junit.Test)95 Logger (chat.rocket.android.helper.Logger)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)17 Worker (io.reactivex.Scheduler.Worker)15 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)13 CountingRunnable (io.reactivex.android.testutil.CountingRunnable)10 EmptyDisposable (io.reactivex.internal.disposables.EmptyDisposable)10 TestSubscriber (io.reactivex.subscribers.TestSubscriber)10 Optional (com.fernandocejas.arrow.optional.Optional)9 Single (io.reactivex.Single)9 Nullable (android.support.annotation.Nullable)8 Function (io.reactivex.functions.Function)8 Bundle (android.os.Bundle)7 Pair (android.support.v4.util.Pair)7 ANError (com.androidnetworking.error.ANError)7 AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)7 List (java.util.List)7 NonNull (android.support.annotation.NonNull)6