I am trying to implement a screen in Android app using MVP architecture and using RxJava and RxBinding on the View side.
Basically I have 2 Spinners, 1 TextEdit and a button that's disabled by default. I want to enable the button when Spinners have items selected and text field is not empty. Here is the code:
Observable.combineLatest(
RxAdapterView.itemSelections(mFirstSpinner),
RxAdapterView.itemSelections(mSecondSpinner),
RxTextView.textChanges(mEditText),
new Func3<Integer, Integer, CharSequence, Boolean>() {
@Override
public Boolean call(Integer first, Integer second, CharSequence value) {
return !TextUtils.isEmpty(value);
}
}).subscribe(new Action1<Boolean>() {
@Override
public void call(Boolean enable) {
mButton.setEnabled(enable);
}
});
The question now is how to integrate that into MVP pattern. Ideally the "business logic" of enabling the button should be in the presenter. What's the best way to achieve this? I am thinking of passing the original observers into the presenter somehow (side question is how?), and the presenter would combine those observers and it would have the logic of enabling the button. In the end, it would just call View to modify button state.
Are there any better options? Are there any good examples of MVP with RxJava on View side?