I'm using the foursquare API to retrieve photos of nearby venues and display them. I'm doing it by RxJava and Retrofit. The first time I need to request a list of venues with proper ids and the second request should be with ids as parameters to retrieve photos for every single venue. I wanna do everything with single RxJava call because that's the best practice, isn't it? Below is my code, unfortunately, I stuck at the place when I should do the second request. Any hint how should I solve it?
Observable<VenuesResponse> observable = mApiService.getVenues();
observable
.map(new Function<VenuesResponse, List<VenuesItem>>() {
@Override
public List<VenuesItem> apply(VenuesResponse venuesResponse) throws Exception {
return venuesResponse.getResponse().getVenues();
}
})
.flatMap(new Function<List<VenuesItem>, ObservableSource<VenuesItem>>() {
@Override
public ObservableSource<VenuesItem> apply(List<VenuesItem> venuesItems) throws Exception {
return Observable.fromIterable(venuesItems);
}
})
//TODO code that requests for photo and adds url to VenuesItem
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
}