我有这两项服务:
private Observable<UMapsResponse> requestToServiceGetMaps(int idVenue, String accessToken) {
return mService.getUMaps(idVenue, accessToken);
}
private Observable<UMap> requestToServiceGetMapImageUrl(int idVenue, int idMap, String accessToken) {
return mService.getUMap(idVenue, idMap, accessToken);
}
所以我将这两项服务结合起来:
requestToServiceGetMaps(idVenue, accessToken)
.flatMap(uMapsResponse -> Observable.just(uMapsResponse.getIndoorMaps()))
.flatMapIterable(indoorMap -> indoorMap)
.flatMap(
indoorMap -> requestToServiceGetMapImageUrl(idVenue, indoorMap.getId(), accessToken),
(indoorMap, uMap) -> Log.i(TAG, "MapsItem: " + new MapsItem(indoorMap, uMap))
).toList()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SingleObserver<List<Integer>>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSuccess(List<Integer> integers) {
}
@Override
public void onError(Throwable e) {
}
});
所以我有两个问题:
答案 0 :(得分:2)
你得到一个Integer列表,因为你从观察者链的最后一步发出整数,因为那是Log.i()
返回的。
...
.flatMap(
indoorMap -> requestToServiceGetMapImageUrl(idVenue, indoorMap.getId(), accessToken),
(indoorMap, uMap) -> new MapsItem(indoorMap, uMap)
)
.doOnNext( v -> Log.i(TAG, "MapsItem: " + v) )
.toList()
...
请注意,最终flatMap()
的结果是您要查找的新MapsItem
。