我有一个函数,它返回一个包含来自 html 页面的列表的对象:
@Override
public Observable<MediaList> getMediaListFromUrl(String url) {
return getHtml(url)
.map(new Func1<String, MediaList>() {
@Override
public MediaList call(String s) {
return interpreter.interpretMediaResultsFromHtml(s);
}
});
}
接下来我想做的是:
for(Media media : mediaList.getMedias()) {
if (media.getImageUrl().contains("couvertureAjax")) {
// fetch media.getImageUrl
// replace the image url with the result
}
}
最后,返回带有替换图像 url 的原始 MediaList 对象。我想我应该在某个地方使用flatmap
and from
,但我不知道具体如何。
媒体列表.java:
import android.os.Parcel;
import android.os.Parcelable;
import java.util.List;
public class MediaList implements Parcelable {
public static final String TAG = MediaList.class.getSimpleName();
private List<Media> medias;
private String nextPageUrl;
public MediaList() {}
protected MediaList(Parcel in) {
medias = in.createTypedArrayList(Media.CREATOR);
nextPageUrl = in.readString();
}
public List<Media> getMedias() {
return medias;
}
public void setMedias(List<Media> medias) {
this.medias = medias;
}
public String getNextPageUrl() {
return nextPageUrl;
}
public void setNextPageUrl(String nextPageUrl) {
this.nextPageUrl = nextPageUrl;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(medias);
dest.writeString(nextPageUrl);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<MediaList> CREATOR = new Creator<MediaList>() {
@Override
public MediaList createFromParcel(Parcel in) {
return new MediaList(in);
}
@Override
public MediaList[] newArray(int size) {
return new MediaList[size];
}
};
}