Last active
February 1, 2017 21:21
-
-
Save feresr/cfd04d37dae2ec693ce088d573cb1a06 to your computer and use it in GitHub Desktop.
using rx storage
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 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