use of com.hannesdorfmann.mosby3.sample.mvi.businesslogic.model.ProductDetail in project mosby by sockeqwe.
the class DetailsInteractor method getProductWithShoppingCartInfo.
private Observable<ProductDetail> getProductWithShoppingCartInfo(int productId) {
List<Observable<?>> observables = Arrays.asList(backendApi.getProduct(productId), shoppingCart.itemsInShoppingCart());
return Observable.combineLatest(observables, objects -> {
Product product = (Product) objects[0];
List<Product> productsInShoppingCart = (List<Product>) objects[1];
boolean inShoppingCart = false;
for (Product p : productsInShoppingCart) {
if (p.getId() == productId) {
inShoppingCart = true;
break;
}
}
return new ProductDetail(product, inShoppingCart);
});
}
Aggregations