Last active
June 18, 2016 05:53
-
-
Save Diolor/abde6dd10354b849a77b7a9060b3338c to your computer and use it in GitHub Desktop.
Final example
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
private final PublishSubject<Void> viewClickedSubject = PublishSubject.create(); | |
private final CompositeSubscription startStopCompositeSubscription = new CompositeSubscription(); | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
view.setOnClickListener(v-> viewClickedSubject.onNext(null)); | |
Subscription subscription = viewClickedSubject | |
.throttleFirst(200, TimeUnit.MILLISECONDS) | |
.switchMap(aVoid-> api.getAlert() | |
.retryWhen(RetryWithNetwork.create(context)) | |
.retryWhen(RetryExponetialy.create()) | |
) | |
.subscribe( | |
this::makeAlertToast, | |
throwable -> { | |
throw new OnErrorFailedException(" Unsubscribed from View click events.", throwable); | |
} | |
); | |
startStopCompositeSubscription.add(subscription); | |
} | |
@Override | |
protected void onStop() { | |
super.onStop(); | |
startStopCompositeSubscription.clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment