Created
April 14, 2017 15:55
-
-
Save benigumocom/976e2cde30b6b66219ff409b9e682b8a to your computer and use it in GitHub Desktop.
Reactive State 4
This file contains hidden or 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
disposables.add(RxView.clicks(submitView) | |
.map(ignored -> new SubmitEvent(nameView.getText().toString())) | |
.flatMap(event -> service.setName(event.name) | |
.map(response -> SubmitUiModel.success()) | |
.onErrorReturn(t -> SubmitUiModel.failure(t.getMessage())) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.startWith(SubmitUiModel.inProgress())) | |
.subscribe(model -> { | |
submitView.setEnabled(!model.inProgress); | |
progressView.setVisibility(model.inProgress ? VISIBLE : GONE); | |
if (!model.inProgress) { | |
if (model.success) finish() | |
else Toast.makeText(this, "Failed to set name: " + model.errorMessage, LENGTH_SHORT).show(); | |
} | |
}, t -> { throw new OnErrorNotImplementedException(t); })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment