Skip to content

Instantly share code, notes, and snippets.

@alex-townsend
Forked from anonymous/MovieActivityPresenter.java
Last active December 16, 2016 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-townsend/90aa87929aba88f8c45803dfc90f4902 to your computer and use it in GitHub Desktop.
Save alex-townsend/90aa87929aba88f8c45803dfc90f4902 to your computer and use it in GitHub Desktop.
public class MovieActivityPresenter extends Presenter<MovieActivityView>
Subscription sub;
public void getSimilarMovies() {
sub = apiInterface.getSimilarMovies(Integer.valueOf(movieID),ApiInterface.KEY)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
moviesResponse -> similarMovies = moviesResponse.getResults(),
throwable -> {},
() -> {
for (Movie m:similarMovies) {
m.setPosterPath(posterURL + m.getPosterPath());
m.setBackdropPath(backdropURL + m.getBackdropPath());
}
view.setMovieDetails();
view.setCastAdapter();
view.setSimilarMoviesAdapter();
}
);
}
@Override
public void onViewDetached() {
super.onViewDetached();
if (sub != null && !sub.isUnsubscribed()) {
sub.unsubscribe();
}
}
}
public abstract class Presenter<V> {
protected V view;
public void onViewAttached(V view) {
this.view = view;
}
public void onViewDetached() {
this.view = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment