当前位置: 首页>>代码示例>>Java>>正文


Java Disposable类代码示例

本文整理汇总了Java中io.reactivex.disposables.Disposable的典型用法代码示例。如果您正苦于以下问题:Java Disposable类的具体用法?Java Disposable怎么用?Java Disposable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Disposable类属于io.reactivex.disposables包,在下文中一共展示了Disposable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadInfo

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
public void loadInfo(String user) {
    ApiManager.getInstence().getGithubService()
            .getMyInfo(user).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<UserInfo>() {
                @Override
                public void onSubscribe(Disposable d) {
                    addDisposable(d);
                }

                @Override
                public void onNext(UserInfo value) {
                    mIAboutMeActivity.showMyInfo(value);
                }

                @Override
                public void onError(Throwable e) {
                    mIAboutMeActivity.loadMyInfoFail();
                }

                @Override
                public void onComplete() {

                }
            });
}
 
开发者ID:haihaio,项目名称:AmenEye,代码行数:27,代码来源:AboutMePresenter.java

示例2: disposeOnResume

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
private void disposeOnResume() {
    Disposable d = Observable
            .interval(1, TimeUnit.SECONDS)
            .subscribeWith(new DisposableObserver<Long>() {
                @Override
                public void onNext(Long value) {
                    Log.d(TAG, "Timer A:" + value.toString() + " Seconds");
                }

                @Override
                public void onError(Throwable e) {
                    Log.e(TAG, "onError", e);
                }

                @Override
                public void onComplete() {
                    Log.d(TAG, "onComplete");
                }
            });

    /*
     * Dispose observer on ActivityEvent.RESUME
     */
    dispose(d, ActivityEvent.RESUME);
}
 
开发者ID:mahmed8003,项目名称:RxLifecycle,代码行数:26,代码来源:MainActivity.java

示例3: updateWatchlist

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
private Disposable updateWatchlist(List<WatchlistItem> watchlistItems) {
		return ((LeanbackBaseActivity) getActivity()).getApiServiceObservable()
				.observeOn(AndroidSchedulers.mainThread())
				.subscribe(mediaApiService -> {
					showWatchlist();
					watchListAdapter.clear();
					if(watchlistItems.size() > 0){
//						int i = Math.max(0,mRowsAdapter.indexOf(mConferencesSection));
//						mRowsAdapter.add(i,mRecomendationsSectionsRow);
//						mRowsAdapter.add(i+1,watchListAdapter);
						Observable.fromIterable(watchlistItems)
								.flatMap(watchlistItem -> mediaApiService.getEvent(watchlistItem.getEventId()))
								.observeOn(AndroidSchedulers.mainThread())
								.subscribe(event -> watchListAdapter.add(event));
					} else {
//						watchListAdapter.add("Watchlist empty");
						hideWatchlist();
					}
				});
	}
 
开发者ID:NiciDieNase,项目名称:chaosflix,代码行数:21,代码来源:ConferencesBrowseFragment.java

示例4: clientStreaming_error_break_flow

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
@Test
public void clientStreaming_error_break_flow() throws Exception {
  PublishSubject<Integer> publishSubject = PublishSubject.create();
  Set<Integer> resultsHolder = Sets.newConcurrentHashSet();
  Set<Throwable> exceptionsHolder = Sets.newConcurrentHashSet();
  AtomicBoolean complete = new AtomicBoolean(false);
  Disposable disposable = publishSubject
      .doOnNext(num->resultsHolder.add(num))
      .doOnError(t->exceptionsHolder.add(t))
      .doOnComplete(()->complete.compareAndSet(false,true))
      .subscribe();
  assertThat(disposable.isDisposed()).isFalse();
  RxStreamObserver<Integer> rxStreamObserver = new RxStreamObserver<>(publishSubject);

  rxStreamObserver.onError(new IllegalStateException());

  assertThat(disposable.isDisposed()).isTrue();
  assertThat(resultsHolder).isEmpty();
  assertThat(exceptionsHolder.size()).isEqualTo(1);
  assertThat(exceptionsHolder.iterator().next()).isInstanceOf(IllegalStateException.class);
  assertThat(complete).isFalse();
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:23,代码来源:RxStreamObserverTest.java

示例5: readAndFillContacts

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
private Disposable readAndFillContacts(final int filterType) {
    CQuery cQuery = CQuery.getInstance(getActivity());
    cQuery.filter(filterType);
    return cQuery.build(new IContact() {
        @Override
        public void onContactSuccess(List<CList> mList) {
            //Toast.makeText(getActivity(), " Contacts count " + mList.size(), Toast.LENGTH_SHORT).show();
            if (mList != null && !mList.isEmpty()) {
                for (CList cList : mList) {
                    setUpContactList(filterType, cList);
                }

                mList.clear();
            }

            updateList();
        }

        @Override
        public void onContactError(Throwable throwable) {
            Toast.makeText(getActivity(), "" + throwable.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
        }
    });

}
 
开发者ID:nitiwari-dev,项目名称:android-contact-extractor,代码行数:26,代码来源:ContactInfoFragment.java

示例6: demo1

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
private void demo1() {

        final Disposable subscribe = Observable.create(emitter -> {
            emitter.setCancellable(() -> {
                log("setCancellable");
                helloText.setOnClickListener(null);
            });
            helloText.setOnClickListener(v -> {
                log("listener", "Click");
                emitter.onNext(v);
            });
        })
                .doOnDispose(() -> log("onDispose"))
                .doOnComplete(() -> log("doOnComplete"))
                .subscribe(e -> log("subscribe", "Click"));
        subscribe.dispose();
    }
 
开发者ID:PacktPublishing,项目名称:Reactive-Android-Programming,代码行数:18,代码来源:MainActivity.java

示例7: io_main

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> io_main() {
    return new ObservableTransformer<T, T>() {
        @Override
        public ObservableSource<T> apply(@NonNull Observable<T> upstream) {
            return upstream
                    .subscribeOn(Schedulers.io())
                    .unsubscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            HttpLog.i("+++doOnSubscribe+++" + disposable.isDisposed());
                        }
                    })
                    .doFinally(new Action() {
                        @Override
                        public void run() throws Exception {
                            HttpLog.i("+++doFinally+++");
                        }
                    })
                    .observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:24,代码来源:RxUtil.java

示例8: getOverseaComingMovieList

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
@Override
public void getOverseaComingMovieList(String area, int limit, int offset) {
    mManager.getOverseaComingMovie(area, limit, offset)
            .subscribe(new Observer<OverseaComingMovieBean>() {
                @Override
                public void onSubscribe(@NonNull Disposable d) {
                    mView.showLoading();
                }

                @Override
                public void onNext(@NonNull OverseaComingMovieBean data) {
                    mView.addOverseaComingMovieList(data.getData().getComing());
                }

                @Override
                public void onError(@NonNull Throwable e) {
                    mView.showError(ErrorHanding.handleError(e));
                }

                @Override
                public void onComplete() {
                    mView.showContent();
                }
            });
}
 
开发者ID:coderwjq,项目名称:ZhaZhaShop,代码行数:26,代码来源:MovieMoreRankPresenter.java

示例9: processRepeat

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
private void processRepeat() {
    Observable.just(1, 2, 3)
            .repeat(3)
            .subscribe(new Observer<Integer>() {
                @Override
                public void onSubscribe(Disposable d) {
                    Log.d(TAG, "开始采用subscribe连接");
                }

                @Override
                public void onNext(Integer value) {
                    Log.d(TAG, "接收到了事件" + value);
                }

                @Override
                public void onError(Throwable e) {
                    Log.d(TAG, "对Error事件作出响应");
                }

                @Override
                public void onComplete() {
                    Log.d(TAG, "对Complete事件作出响应");
                }

            });
}
 
开发者ID:penghuanliang,项目名称:Rxjava2.0Demo,代码行数:27,代码来源:DoActivity.java

示例10: getSecondRelaRelateVideoInfo

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
public void getSecondRelaRelateVideoInfo(String path, int id, int startnum) {
    mModel.getSecondRelateVideoInfo(path, id, startnum).compose(RxUtils.applySchedulersWithLifeCycle(mRootView))
            .doOnSubscribe(new Consumer<Disposable>() {
                @Override
                public void accept(@NonNull Disposable disposable) throws Exception {
                    if (startnum==0){
                        mRootView.showLoading();
                    }
                }
            })
            .subscribe(new ErrorHandleSubscriber<VideoListInfo>(mErrorHandler) {
                @Override
                public void onNext(VideoListInfo info) {
                    mRootView.setData(info, true);
                }
            });
}
 
开发者ID:Zweihui,项目名称:Aurora,代码行数:18,代码来源:VideoDetailPresenter.java

示例11: disposeOnDestroy

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
private void disposeOnDestroy() {
    Disposable d = Observable
            .interval(1, TimeUnit.SECONDS)
            .subscribeWith(new DisposableObserver<Long>() {
                @Override
                public void onNext(Long value) {
                    Log.d(TAG, "Timer B:" + value.toString() + " Seconds");
                }

                @Override
                public void onError(Throwable e) {
                    Log.e(TAG, "onError", e);
                }

                @Override
                public void onComplete() {
                    Log.d(TAG, "onComplete");
                }
            });

    /*
     * Dispose observer
     */
    dispose(d);
}
 
开发者ID:mahmed8003,项目名称:RxLifecycle,代码行数:26,代码来源:MainActivity.java

示例12: from

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
private void from() {
    String[] items = new String[]{"1", "2", "3"};
    final Disposable[] mDisposable = new Disposable[1];
    Observable.fromArray(items)
            .doOnSubscribe(new Consumer<Disposable>() {
                @Override
                public void accept(Disposable disposable) throws Exception {
                    mDisposable[0] = disposable;
                }
            }).subscribe(new Consumer<String>() {
        @Override
        public void accept(String s) throws Exception {
            if (s.equals("2")) {
                mDisposable[0].dispose();
            }
            Log.e(TAG, "accept: " + s);
        }
    });

}
 
开发者ID:penghuanliang,项目名称:Rxjava2.0Demo,代码行数:21,代码来源:CreateActivity.java

示例13: applySchedulers

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> applySchedulers(final IView view) {
    return new ObservableTransformer<T, T>() {
        @Override
        public Observable<T> apply(Observable<T> observable) {
            return observable.subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            view.showLoading();//显示进度条
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doAfterTerminate(new Action() {
                        @Override
                        public void run() {
                            view.hideLoading();//隐藏进度条
                        }
                    }).compose(RxUtils.bindToLifecycle(view));
        }
    };
}
 
开发者ID:devzwy,项目名称:NeiHanDuanZiTV,代码行数:23,代码来源:RxUtils.java

示例14: directSchedulePeriodicallyDisposedDoesNotRun

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
@Test @Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.schedulePeriodicallyDirect(counter, 1, 1, MINUTES);

    runUiThreadTasks();
    assertEquals(0, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());

    disposable.dispose();

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:HandlerSchedulerTest.java

示例15: workerSchedulePeriodicallyDisposedDoesNotRun

import io.reactivex.disposables.Disposable; //导入依赖的package包/类
@Test @Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedulePeriodically(counter, 1, 1, MINUTES);

    runUiThreadTasks();
    assertEquals(0, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());

    disposable.dispose();

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:HandlerSchedulerTest.java


注:本文中的io.reactivex.disposables.Disposable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。