本文整理汇总了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() {
}
});
}
示例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);
}
示例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();
}
});
}
示例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();
}
示例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();
}
});
}
示例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();
}
示例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());
}
};
}
示例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();
}
});
}
示例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事件作出响应");
}
});
}
示例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);
}
});
}
示例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);
}
示例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);
}
});
}
示例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));
}
};
}
示例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());
}
示例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());
}