Last active
April 6, 2018 12:29
-
-
Save passiondroid/01286719bc3acd1d79f9e815932519e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private List<Movies> movies = new ArrayList<>(); | |
movieService.getMovies() | |
.flatMap(new Function<List<Movie>, ObservableSource<Movie>>() { | |
@Override | |
public ObservableSource<Movie> apply(List<Movie> movies) | |
throws Exception { | |
return Observable.fromIterable(movies); | |
} | |
}) | |
.flatMap(new Function<Movie, ObservableSource<Pair<Movie, List<Cast>>>() { | |
@Override | |
public ObservableSource<Pair<Movie, List<Cast>>> apply(Movie movie) | |
throws Exception { | |
return Observable.zip(movieService.getMovieCasts(movie.getId()), | |
Observable.just(movie), | |
new BiFunction<List<Cast>, Movie, Pair<Movie, List<Cast>>>() { | |
@Override | |
public Pair<Movie, List<Cast>> apply(List<Cast> casts, Movie movie) | |
throws Exception { | |
return new Pair<>(movie,casts); | |
} | |
}); | |
} | |
}) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(new Observer<Pair<Movie, List<Cast>>>() { | |
@Override | |
public void onSubscribe(Disposable d) { | |
} | |
@Override | |
public void onNext(Pair<Movie, List<Cast>> value) { | |
Movie movie = value.first; | |
movie.setCasts(value.second); | |
movies.add(movie); | |
} | |
@Override | |
public void onError(Throwable e) { | |
} | |
@Override | |
public void onComplete() { | |
updateUI(movies) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment