Skip to content

Instantly share code, notes, and snippets.

@feresr
Last active February 1, 2017 21:21
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 feresr/cfd04d37dae2ec693ce088d573cb1a06 to your computer and use it in GitHub Desktop.
Save feresr/cfd04d37dae2ec693ce088d573cb1a06 to your computer and use it in GitHub Desktop.
using rx storage
public class JokesPresenter extends BasePresenter<JokesView> {
private JokesStore store;
private Subscription subscription;
@Inject
public JokesPresenter(JokesStore jokesStore) { this.store = jokesStore; }
@Override
public void onCreate() {
super.onCreate();
fetchNewJoke();
}
@Override
public void onStart() {
super.onStart();
subscription = store.register(new JokeSubscriber());
}
@Override
public void onStop() {
store.unregister(subscription);
super.onStop();
}
void fetchNewJoke() {
store.onNext(new JokeRequest());
}
private class JokeSubscriber extends Subscriber<JokeResponse> {
//onComplete, onError
@Override
public void onNext(JokeResponse jokeResponse) {
if (jokeResponse.isSuccessful()) {
view.displayJoke(jokeResponse.getJoke().getValue().getJoke());
} else {
view.displayError(jokeResponse.getErrorString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment