use of io.reactivex.Observable in project RxJava by ReactiveX.
the class RxJavaPluginsTest method observableCreate.
@SuppressWarnings("rawtypes")
@Test
public void observableCreate() {
try {
RxJavaPlugins.setOnObservableAssembly(new Function<Observable, Observable>() {
@Override
public Observable apply(Observable t) {
return new ObservableRange(1, 2);
}
});
Observable.range(10, 3).test().assertValues(1, 2).assertNoErrors().assertComplete();
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
Observable.range(10, 3).test().assertValues(10, 11, 12).assertNoErrors().assertComplete();
}
use of io.reactivex.Observable in project mosby by sockeqwe.
the class MainMenuPresenter method bindIntents.
@Override
protected void bindIntents() {
Observable<List<String>> loadCategories = intent(MainMenuView::loadCategoriesIntent).doOnNext(categoryName -> Timber.d("intent: load category %s", categoryName)).flatMap(ignored -> backendApi.getAllCategories().subscribeOn(Schedulers.io()));
Observable<String> selectCategory = intent(MainMenuView::selectCategoryIntent).doOnNext(categoryName -> Timber.d("intent: select category %s", categoryName)).startWith(MainMenuItem.HOME);
List<Observable<?>> allIntents = new ArrayList<>(2);
allIntents.add(loadCategories);
allIntents.add(selectCategory);
Observable<MenuViewState> menuViewStateObservable = Observable.combineLatest(allIntents, (Function<Object[], MenuViewState>) objects -> {
List<String> categories = (List<String>) objects[0];
String selectedCategory = (String) objects[1];
List<MainMenuItem> categoriesItems = new ArrayList<MainMenuItem>(categories.size() + 1);
categoriesItems.add(new MainMenuItem(MainMenuItem.HOME, selectedCategory.equals(MainMenuItem.HOME)));
for (int i = 0; i < categories.size(); i++) {
String category = categories.get(i);
categoriesItems.add(new MainMenuItem(category, category.equals(selectedCategory)));
}
return new MenuViewState.DataState(categoriesItems);
}).startWith(new MenuViewState.LoadingState()).onErrorReturn(MenuViewState.ErrorState::new).observeOn(AndroidSchedulers.mainThread());
subscribeViewState(menuViewStateObservable, MainMenuView::render);
}
use of io.reactivex.Observable in project nem2-sdk-java by nemtech.
the class AccountHttp method getAccountsInfo.
@Override
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
JsonObject requestBody = new JsonObject();
requestBody.put("addresses", addresses.stream().map(address -> address.plain()).collect(Collectors.toList()));
Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url.toString()).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<AccountInfoDTO>>readValue(json.toString(), new TypeReference<List<AccountInfoDTO>>() {
})).flatMapIterable(item -> item).map(AccountInfoDTO::getAccount).map(accountDTO -> new AccountInfo(Address.createFromRawAddress(accountDTO.getAddressEncoded()), accountDTO.getAddressHeight().extractIntArray(), accountDTO.getPublicKey(), accountDTO.getPublicKeyHeight().extractIntArray(), accountDTO.getImportance().extractIntArray(), accountDTO.getImportanceHeight().extractIntArray(), accountDTO.getMosaics().stream().map(mosaicDTO -> new Mosaic(new MosaicId(mosaicDTO.getId().extractIntArray()), mosaicDTO.getAmount().extractIntArray())).collect(Collectors.toList()))).toList().toObservable());
}
use of io.reactivex.Observable in project nem2-sdk-java by nemtech.
the class TransactionHttp method getTransactionStatuses.
@Override
public Observable<List<TransactionStatus>> getTransactionStatuses(List<String> transactionHashes) {
JsonObject requestBody = new JsonObject();
requestBody.put("hashes", transactionHashes);
return this.client.postAbs(this.url + "/statuses").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<TransactionStatusDTO>>readValue(json.toString(), new TypeReference<List<TransactionStatusDTO>>() {
})).flatMapIterable(item -> item).map(transactionStatusDTO -> new TransactionStatus(transactionStatusDTO.getGroup(), transactionStatusDTO.getStatus(), transactionStatusDTO.getHash(), new Deadline(transactionStatusDTO.getDeadline().extractIntArray()), transactionStatusDTO.getHeight().extractIntArray())).toList().toObservable();
}
use of io.reactivex.Observable in project nem2-sdk-java by nemtech.
the class TransactionHttp method getTransactions.
@Override
public Observable<List<Transaction>> getTransactions(List<String> transactionHashes) {
JsonObject requestBody = new JsonObject();
requestBody.put("transactionIds", transactionHashes);
return this.client.postAbs(this.url.toString()).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> new JsonArray(json.toString()).stream().map(s -> (JsonObject) s).collect(Collectors.toList())).flatMapIterable(item -> item).map(new TransactionMapping()).toList().toObservable();
}
Aggregations