I use Retrofit 2 and I'm learning RxJava. I download a list of items from somewhere. I want to make an api call for each item and create a new list of extended items. Both calls return an Observable. It looks something like this:
getItemsService.getItems()
.concatMap(Observable::from)
.map(item -> new ExtendedItem(item, someOtherService.getDetails(item.somedetail)))
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(activity);
The details service:
public interface IGetDetailsService {
@GET(BuildConfig.GET_DETAILS_ENDPOINT)
Observable<Detail> getDetails(@Query("q") String someDetail);
}
The problem is that getDetails returns an Observable and I cannot use it to construct ExtendedItem. Changing the getDetails call to return an object does not work in the rxJava chain, I guess because it returns the result to the main thread. How do I get the object itself? I tried a lot of other things but nothing works so far.