My suggestion:
You are on the right track. However, the RxBinding logic must still be in the view. I would move the logic around deciding whether to enable the button or not in the presenter.
Determine the value to save the model from all the fields you want to check:
private class ViewValuesModel { public Integer adapter1Value; public Integer adapter2Value; public CharSequence textValue; public ViewValuesModel(Integer adapter1Value, Integer adapter2Value, CharSequence textValue) { this.adapter1Value = adapter1Value; this.adapter2Value = adapter2Value; this.textValue = textValue; } }
Inside the view, create an Observable :
Observable observable = Observable.combineLatest( RxAdapterView.itemSelections(mFirstSpinner), RxAdapterView.itemSelections(mSecondSpinner), RxTextView.textChanges(mEditText), new Func3<Integer, Integer, CharSequence, ViewValuesModel>() { @Override public ViewValuesModel call(Integer first, Integer second, CharSequence value) { return new ViewValuesModel(first, second, value); } } )
Then pass this Observable master:
mPresenter.observeChoosableFieldChanges(observable).
Inside the presenter, do the rest:
observable .map(new Func1<ViewValuesModel, Boolean>() { @Override public Booleancall(ViewValuesModel viewStates) { return !TextUtils.isEmpty(viewStates.textValue); } }) .subscribe(new Action1<Boolean>() { @Override public void call(Boolean enable) { if (enable) { view.enableButton(); } } });
source share