Observable.create(new Observable.OnSubscribe<Member>() { @Override public void call(Subscriber<? super Member> subscriber) { //todo make sure we emit items and complete //todo handle errors } }); } public Observable<Bitmap> getAvatar(final Member member) { //todo } }
Observable.create(new Observable.OnSubscribe<Member>() { @Override public void call(Subscriber<? super Member> subscriber) { //todo make sure we emit items and complete //todo handle errors } }); } public Observable<Bitmap> getAvatar(final Member member) { Observable.create(new Observable.OnSubscribe<Member>() { @Override public void call(Subscriber<? super Member> subscriber) { //todo make sure we emit items and complete //todo handle errors } }); } }
void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); //Get observable that will fetch all the members Observable<Member> membersObservable = service.getMembers(); //for each member, fetch the url, update the model, return the model membersObservable.flatMap(new Func1<Member, Observable<Member>>() { @Override public Observable<Member> call(Member member) { Observable<Member> theMember = Observable.just(member); Observable<Bitmap> theAvatar = service.getAvatar(member); Func2<Member, Bitmap, Member> zipFunc = getZipFunc(); return Observable.zip(theMember, theAvatar, zipFunc); } }) .subscribe(new Action1<Member>() { @Override public void call(Member member) { //adapter.add(member) which will update a ListView? } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { //show an AlertDialog to the user? } }); } /* getZipFunc() omitted */ }