Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Created April 14, 2017 15:48
Show Gist options
  • Save benigumocom/612a80f4140afd8bda2eaecae0de8c5a to your computer and use it in GitHub Desktop.
Save benigumocom/612a80f4140afd8bda2eaecae0de8c5a to your computer and use it in GitHub Desktop.
Reactive State 2
disposables.add(RxView.clicks(submitView)
.map(ignored -> new SubmitEvent(nameView.getText().toString()))
.doOnNext(ignored -> {
submitView.setEnabled(false);
progressView.setVisibility(VISIBLE);
})
.flatMap(event -> service.setName(event.name))
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(ignored -> progressView.setVisibility(GONE))
.subscribe(s -> finish(), t -> {
submitView.setEnabled(true);
Toast.makeText(this, "Failed to set name: " + t.getMessage(), LENGTH_SHORT).show();
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment