Search in sources :

Example 1 with ProductDetail

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);
    });
}
Also used : ProductDetail(com.hannesdorfmann.mosby3.sample.mvi.businesslogic.model.ProductDetail) Product(com.hannesdorfmann.mosby3.sample.mvi.businesslogic.model.Product) List(java.util.List) Observable(io.reactivex.Observable)

Aggregations

Product (com.hannesdorfmann.mosby3.sample.mvi.businesslogic.model.Product)1 ProductDetail (com.hannesdorfmann.mosby3.sample.mvi.businesslogic.model.ProductDetail)1 Observable (io.reactivex.Observable)1 List (java.util.List)1