Forked from anonymous/MovieActivityPresenter.java
Last active
December 16, 2016 19:07
-
-
Save alex-townsend/90aa87929aba88f8c45803dfc90f4902 to your computer and use it in GitHub Desktop.
This file contains 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
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(); | |
} | |
} | |
} |
This file contains 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
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