@Override public void subscribe(SingleEmitter<Integer> s) throws Exception { calls[0]++; s.onSuccess(1); } });
@Override public void onSuccess(T t) { emitter.onSuccess(t); }
@Override public void subscribe(SingleEmitter<Integer> s) throws Exception { calls[0]++; s.onSuccess(1); } });
@Override public void subscribe(SingleEmitter<Object> s) throws Exception { s.onSuccess(1); } }));
@Override public void subscribe(@NonNull SingleEmitter<Boolean> emitter) { emitter.onSuccess(isConnected(host, port, timeoutInMs, httpResponse, errorHandler)); } });
@Override public void subscribe(@NonNull SingleEmitter<Boolean> emitter) throws Exception { emitter.onSuccess(isConnected(host, port, timeoutInMs, errorHandler)); } });
@Override public void subscribe(SingleEmitter<Object> e) throws Exception { e.onSuccess(1); response[0] = e.tryOnError(new TestException()); } })
@Override public void subscribe(SingleEmitter<Integer> e) throws Exception { e.setDisposable(d1); e.setCancellable(new Cancellable() { @Override public void cancel() throws Exception { d2.dispose(); } }); e.onSuccess(1); e.onError(new TestException()); e.onSuccess(2); e.onError(new TestException()); } })
@Override public void subscribe(SingleEmitter<Integer> e) throws Exception { e.setDisposable(d); e.onError(new TestException()); e.onSuccess(2); e.onError(new TestException()); } })
private static Single<String> single(String input) { RequestContext.current(); return Single.create(emitter -> { RequestContext.current(); emitter.onSuccess(input); }); }
@Test public void deferredResultSubscriberWithOneValue() throws Exception { // Mono MonoProcessor<String> mono = MonoProcessor.create(); testDeferredResultSubscriber(mono, Mono.class, forClass(String.class), () -> mono.onNext("foo"), "foo"); // Mono empty MonoProcessor<String> monoEmpty = MonoProcessor.create(); testDeferredResultSubscriber(monoEmpty, Mono.class, forClass(String.class), monoEmpty::onComplete, null); // RxJava 1 Single AtomicReference<SingleEmitter<String>> ref = new AtomicReference<>(); Single<String> single = Single.fromEmitter(ref::set); testDeferredResultSubscriber(single, Single.class, forClass(String.class), () -> ref.get().onSuccess("foo"), "foo"); // RxJava 2 Single AtomicReference<io.reactivex.SingleEmitter<String>> ref2 = new AtomicReference<>(); io.reactivex.Single<String> single2 = io.reactivex.Single.create(ref2::set); testDeferredResultSubscriber(single2, io.reactivex.Single.class, forClass(String.class), () -> ref2.get().onSuccess("foo"), "foo"); }
public static Single<Bitmap> combineBitmaps (final Context context, final List<String> urls) { return Single.create(e -> { final ArrayList<Bitmap> bitmaps = new ArrayList<>(); ArrayList<Single<Bitmap>> singles = new ArrayList<>(); for(String url : urls) { if(singles.size() >= 4) { break; } singles.add(bitmapForURL(context, url).onErrorResumeNext(throwable -> null)); } Single.merge(singles).observeOn(AndroidSchedulers.mainThread()) .doOnComplete(() -> { int size = context.getResources().getDimensionPixelSize(R.dimen.chat_sdk_chat_action_barcircle_image_view_size); Bitmap bitmap = ImageUtils.getMixImagesBitmap(size, size, bitmaps); if(bitmap == null) { e.onError(new Throwable(context.getString(R.string.thread_image_could_not_be_created))); } else { e.onSuccess(bitmap); } }) .subscribe(bitmaps::add, throwable -> { e.onError(throwable); ChatSDK.logError(throwable); }); }); }
public Single<List<Message>> loadMoreMessagesForThread(final Message fromMessage, final Thread thread) { return Single.create((SingleOnSubscribe<List<Message>>) e -> { // Date messageDate = fromMessage != null ? fromMessage.getDate().toDate() : null; // First try to load the messages from the database List<Message> list = StorageManager.shared().fetchMessagesForThreadWithID(thread.getId(), ChatSDK.config().messagesToLoadPerBatch + 1, messageDate); e.onSuccess(list); }).subscribeOn(Schedulers.single()); }
public Completable deleteThreadWithEntityID(final String entityID) { return Single.create((SingleOnSubscribe<Thread>) e -> { final Thread thread = DaoCore.fetchEntityWithEntityID(Thread.class, entityID); e.onSuccess(thread); }).flatMapCompletable(thread -> new ThreadWrapper(thread).deleteThread()).subscribeOn(Schedulers.single()); }
/** * Get the date when the thread was deleted * @return Single On success return the date or -1 if the thread hasn't been deleted **/ private Single<Long> threadDeletedDate() { return Single.create((SingleOnSubscribe<Long>) e -> { User user = ChatSDK.currentUser(); DatabaseReference currentThreadUser = FirebasePaths.threadRef(model.getEntityID()) .child(FirebasePaths.UsersPath) .child(user.getEntityID()) .child(Keys.Deleted); currentThreadUser.addListenerForSingleValueEvent(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if(hasValue) { e.onSuccess((Long) snapshot.getValue()); } else { e.onSuccess(Long.valueOf(-1)); } })); }).subscribeOn(Schedulers.single()); }
@Override public Completable loginWithGoogle(final Activity activity) { return Single.create((SingleOnSubscribe<AuthCredential>) e -> { googleClient = new GoogleApiClient.Builder(activity) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleClient); activity.startActivityForResult(signInIntent, RC_GOOGLE_SIGN_IN); googleSignInCompleteListener = result -> { if(result.isSuccess()) { AuthCredential credential = GoogleAuthProvider.getCredential(result.getSignInAccount().getIdToken(), null); e.onSuccess(credential); } else { e.onError(new Exception(result.getStatus().toString())); } }; }).flatMapCompletable(authCredential -> signInWithCredential(activity, authCredential)); }
public Completable authenticateWithCachedToken() { return Single.create((SingleOnSubscribe<FirebaseUser>) emitter-> { if (isAuthenticating()) { emitter.onError(ChatError.getError(ChatError.Code.AUTH_IN_PROCESS, "Cant execute two auth in parallel")); } else { setAuthStatus(AuthStatus.CHECKING_IF_AUTH); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { emitter.onSuccess(user); } else { emitter.onError(ChatError.getError(ChatError.Code.NO_AUTH_DATA, "No auth bundle found")); } } }) .flatMapCompletable(this::authenticateWithUser) .doOnTerminate(this::setAuthStateToIdle) // Whether we complete successfully or not, we set the status to idle .subscribeOn(Schedulers.single()); }