这是我想出的。它似乎工作。如果您发现任何问题,或者我可以做得更好的事情,请回复。
private void handleMenuItemClicks() {
mCompositeDisposable.add(view.menuItemClicks().subscribe(menuItem -> {
if (menuItem.getItemId() == R.id.action_submit) {
mCompositeDisposable.add(Observable.combineLatest(
view.nameTextChanges(),
view.msgTextChanges(),
(CharSequence nameTxt, CharSequence msgTxt) -> {
return new CharSequence[] {nameTxt, msgTxt};
}
).filter(values -> {
boolean isParticipant = participant != null && values[0].toString().equals(participant.toString());
if (!isParticipant) {
view.navigateToInfo();
}
return isParticipant;
}).flatMap(values -> myService.createItem(
participant.participantNumber, values[0].toString(), values[1].toString())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).toObservable()
).subscribe(response -> {
view.showSuccess();
})
);
}
}));
}