Last active
August 18, 2016 13:28
-
-
Save NikolaDespotoski/eb7cbb3122ff702081bb7cd14900f4b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Observable<DiffUtil.DiffResult> getAllStoreProducts(final List<Product> oldData) { | |
return mApi.getAllStores().flatMap(new Func1<List<Store>, Observable<Store>>() { | |
@Override | |
public Observable<Store> call(List<Store> stores) { | |
return Observable.from(stores); | |
} | |
}).flatMap(new Func1<Store, Observable<List<Product>>>() { | |
@Override | |
public Observable<List<Product>> call(Store store) { | |
return mApi.getStoreProducts(store.getStoreId()); | |
} | |
}, new Func2<Store, List<Product>, List<Product>>() { | |
@Override | |
public List<Product> call(Store store, List<Product> products) { | |
for (int i = 0; i < products.size(); i++) { | |
Product product = products.get(i); | |
product.setStore(store); | |
products.set(i, product); | |
} | |
return products; | |
} | |
}).flatMap(new Func1<List<Product>, Observable<DiffUtil.DiffResult>>() { | |
@Override | |
public Observable<DiffUtil.DiffResult> call(List<Product> products) { | |
return Observable.just(DiffUtil.calculateDiff(new ProductListDiffCallback(oldData, products))); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment