private SingleObserver<Integer> getObserver() { return new SingleObserver<Integer>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onSuccess(Integer value) { textView.append(" onSuccess : value : " + value); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onSuccess : value : " + value); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } }; }
private SingleObserver<String> getSingleObserver() { return new SingleObserver<String>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onSuccess(String value) { textView.append(" onNext : value : " + value); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onNext value : " + value); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } }; }
private SingleObserver<String> getObserver() { return new SingleObserver<String>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onSuccess(String value) { textView.append(" onNext : value : " + value); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onNext value : " + value); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } }; }
@Override protected void subscribeActual(@NonNull SingleObserver<? super GraphResponse> observer) { mObserver = observer; GraphRequest request = GraphRequest.newMeRequest(mAccessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { if (response.getError() == null) { mObserver.onSuccess(response); } else { mObserver.onError(response.getError().getException()); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", mFields); request.setParameters(parameters); request.executeAsync(); }
@Override protected void subscribeActual(SingleObserver<? super T> observer) { ValueSourceDisposable disposable = new ValueSourceDisposable(); valueSource.addCallbacks( result -> { try { observer.onSuccess(result); } catch (Throwable e) { observer.onError(e); } }, ex -> { if (!disposable.isDisposed()) { observer.onError(ex); } } ); observer.onSubscribe(disposable); }
@Override public SingleObserver<? super T> apply(final SingleObserver<? super T> observer) { return new SingleObserver<T>() { @Override public void onSubscribe(Disposable d) { if (subscribedOnce.getAndSet(true)) { throw new NullPointerException("You cannot directly subscribe to a gRPC service multiple times " + "concurrently. Use Flowable.share() instead."); } else { observer.onSubscribe(d); } } @Override public void onSuccess(T t) { observer.onSuccess(t); } @Override public void onError(Throwable e) { observer.onError(e); } }; }
@Test public void subscribeOnlyOnceSingleOperatorErrorsWhenMultipleSubscribe() { SubscribeOnlyOnceSingleOperator<Object> op = new SubscribeOnlyOnceSingleOperator<Object>(); SingleObserver<Object> innerSub = mock(SingleObserver.class); final Disposable disposable = mock(Disposable.class); final SingleObserver<Object> outerSub = op.apply(innerSub); outerSub.onSubscribe(disposable); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() { outerSub.onSubscribe(disposable); } }) .isInstanceOf(NullPointerException.class) .hasMessageContaining("cannot directly subscribe to a gRPC service multiple times"); verify(innerSub, times(1)).onSubscribe(disposable); }
private void refreshBook(){ RemoteRepository .getInstance() .getBookDetail(bookId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<BookDetailBean>() { @Override public void onSubscribe(Disposable d) { addDisposable(d); } @Override public void onSuccess(BookDetailBean value){ mView.finishRefresh(value); mView.complete(); } @Override public void onError(Throwable e) { mView.showError(); } }); }
protected <E> SingleObserver<E> getSingleSubscriber(final RxSingleSubscriberEvents singleSubscriberEvents) { return new SingleObserver<E>() { @Override public void onSubscribe(@NonNull Disposable d) { queueSubscriptionForDisposal(d); } @Override public void onSuccess(E value) { singleSubscriberEvents.onSuccess(value); } @Override public void onError(Throwable error) { singleSubscriberEvents.onError(error); } }; }
@Override public void renameFile(int adapterPosition, String value) { rename(recordingItems.get(adapterPosition), adapterPosition, value).subscribe( new SingleObserver<Integer>() { @Override public void onSubscribe(Disposable d) { } @Override public void onSuccess(Integer position) { getAttachedView().notifyListItemChange(position); } @Override public void onError(Throwable e) { getAttachedView().showError(e.getMessage()); } }); }
@Override protected void subscribeActual(SingleObserver<? super T> s) { SingleObserver<? super T> observer; try { observer = ObjectHelper.requireNonNull(s, "Null Observer"); } catch (Throwable e) { Exceptions.throwIfFatal(e); // can't call onError because no way to know if a Disposable has been set or not // can't call onSubscribe because the call might have set a Disposable already RxJavaPlugins.onError(e); NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS"); npe.initCause(e); throw npe; } source.subscribe(new AttachSingleObserver<>(observer, this.compositeDisposable)); }
public static void getNews(SingleObserver<List<News.ContentBean>> observer) { service.getNews() .subscribeOn(Schedulers.newThread()) .flatMap(new Function<News, Observable<News.ContentBean>>() { @Override public Observable<News.ContentBean> apply(News news) throws Exception { L.e(); return Observable.fromIterable(news.getT1348647853363()); } }) .toList() .observeOn(AndroidSchedulers.mainThread()) .subscribe(observer); }
@Override protected void subscribeActual(@NonNull SingleObserver<? super T> observer) { boolean b; try { b = condition.getAsBoolean(); } catch (Throwable ex) { EmptyDisposable.error(ex, observer); return; } if (b) { then.subscribe(observer); } else { orElse.subscribe(observer); } }
private SingleObserver<Long> getObserver() { return new SingleObserver<Long>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onSuccess(Long value) { textView.append(" onSuccess : value : " + value); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onSuccess : value : " + value); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } }; }
private void getData() { Observable.concat(memory, disk, network) .first("") .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<String>() { @Override public void onSubscribe(Disposable d) { // TODO: 2017/7/5 } @Override public void onSuccess(String s) { Log.d(TAG, "onSuccess: " + s); } @Override public void onError(Throwable e) { // TODO: 2017/7/5 } }); }
private SingleObserver<Boolean> getObserver() { return new SingleObserver<Boolean>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onSuccess(Boolean value) { textView.append(" onNext : value : " + value); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onNext : value : " + value); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } }; }
private SingleObserver<Boolean> getObserver() { return new SingleObserver<Boolean>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onSuccess(Boolean value) { textView.append(" onSuccess : value : " + value); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onSuccess : value : " + value); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } }; }
private SingleObserver<Integer> getObserver() { return new SingleObserver<Integer>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onSuccess(Integer value) { textView.append(" onNext : "); textView.append(AppConstant.LINE_SEPARATOR); textView.append(" value : " + value); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onNext "); Log.d(TAG, " value : " + value); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } }; }
protected <T> SingleObserver<T> failOrCountDownSingleObserver(CountDownLatch latch) { return new SingleObserver<T>() { @Override public void onSubscribe(Disposable d) { } @Override public void onSuccess(T t) { latch.countDown(); } @Override public void onError(Throwable e) { fail(e); } }; }
@Override protected void subscribeActual(SingleObserver<? super Member<T>> observer) { // the action of checking out a member from the pool is implemented as a // subscription to the singleton MemberSingle MemberSingleObserver<T> md = new MemberSingleObserver<T>(observer, this); observer.onSubscribe(md); if (pool.isClosed()) { observer.onError(new PoolClosedException()); return; } add(md); if (md.isDisposed()) { remove(md); } requested.incrementAndGet(); log.debug("subscribed"); drain(); }
@Override protected void subscribeActual(SingleObserver<? super Container> observer) { observer.onSubscribe(EmptyDisposable.INSTANCE); try { Container v = run(); if (v != null) { observer.onSuccess(v); } else { observer.onError(new NullPointerException("The callable returned a null value")); } } catch (Throwable e) { Exceptions.throwIfFatal(e); observer.onError(e); } }
void autoDisable() { Helper.autoDisable(context, appInfo.packageName) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<SparseIntArray>() { @Override public void onSubscribe(Disposable d) { } @Override public void onSuccess(SparseIntArray value) { autoDisabled = true; load(); } @Override public void onError(Throwable e) { autoDisabled = true; load(); } }); }
void reset(){ Helper.resetMode(context, appInfo.packageName) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<OpsResult>(){ @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onSuccess(@NonNull OpsResult opsResult) { load(); } @Override public void onError(@NonNull Throwable e) { } }); }
private void loadAppinfo(String pkgName){ Helper.getAppInfo(getApplicationContext(),pkgName) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<AppInfo>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onSuccess(@NonNull AppInfo appInfo) { setTitle(appInfo.appName); } @Override public void onError(@NonNull Throwable e) { } }); }
private void loadUsers(){ Helper.getUsers(getApplicationContext(),true).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<List<UserInfo>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onSuccess(List<UserInfo> userInfos) { Users.getInstance().updateUsers(userInfos); invalidateOptionsMenu(); } @Override public void onError(Throwable e) { } }); }
private void closeServer() { Helper.closeBgServer(getActivity().getApplicationContext()).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<Boolean>() { @Override public void onSubscribe(Disposable d) { } @Override public void onSuccess(Boolean value) { Activity activity = getActivity(); if (activity != null) { Toast.makeText(activity, R.string.bg_closed, Toast.LENGTH_SHORT).show(); } } @Override public void onError(Throwable e) { } }); }
private void showDlg(final Context context, String pkg) { Helper.getAppInfo(context, pkg) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new SingleObserver<AppInfo>() { @Override public void onSubscribe(Disposable d) { } @Override public void onSuccess(AppInfo value) { Intent intent = new Intent(context, AlertInstalledPremActivity.class); intent.putExtra(AlertInstalledPremActivity.EXTRA_APP, value); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); context.startActivity(intent); } @Override public void onError(Throwable e) { } }); }
/** * Performs the opposite translation from * {@link MaybeConsumers#fromSingleObserver(SingleObserver)} */ public static <T> SingleObserver<T> toSingleObserver(final MaybeConsumer<T> c) { return new SingleObserver<T>() { @Override public void onSubscribe(@NonNull Disposable d) { // do nothing } @Override public void onSuccess(@NonNull T t) { c.success(t); } @Override public void onError(@NonNull Throwable e) { c.fail(new RuntimeException(e)); } }; }
private void getProfile(String fields, String userId) { ReactiveRequest.getProfile(fields, userId) .map(this::parseProfile) .subscribe(new SingleObserver<Profile>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, "onSubscribe"); } @Override public void onSuccess(Profile value) { Log.d(TAG, "onSuccess"); fillProfile(value); } @Override public void onError(Throwable e) { Log.d(TAG, "onError " + e.getMessage()); } }); }
/** * get the user list of firends who also use the app */ public void getFriends() { final String bundleAsString = "picture.width(147).height(147),name,first_name"; ReactiveRequest.getFriends(bundleAsString) .map(this::transform) .subscribe(new SingleObserver<List<Profile>>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, "onSubscribe"); } @Override public void onSuccess(List<Profile> profiles) { Log.d(TAG, "onSuccess"); fillList(profiles); } @Override public void onError(Throwable e) { Log.e(TAG, "onError :" + e.getMessage()); } }); }
public void getPhotos() { final String photoFields = "album,images,name"; // fields passed to GraphAPI like "?fields=x,x" ReactiveRequest .getMyPhotos(photoFields, 20) // get albums .map(this::transform) // parse json to list of Album .subscribe(new SingleObserver<List<Photo>>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, "onSubscribe"); } @Override public void onSuccess(List<Photo> value) { Log.d(TAG, "onNext"); appendPhotos(value); } @Override public void onError(Throwable e) { Log.d(TAG, "onError " + e.getMessage()); } }); }
@Override public ServerCall.Listener<ReqT> startCall(ServerCall<ReqT, RespT> call, Metadata headers) { final SingleObserver<RespT> responseObserver = new ResponseObserver<RespT>(call); return new SingleRequestListener<ReqT>(call) { @Override protected void invoke(ReqT request) { Single<RespT> response; try { response = method.unaryInvoke(request); } catch (Throwable t) { response = Single.error(t); } response.subscribe(responseObserver); } }; }