Skip to content

Instantly share code, notes, and snippets.

@rghwang
Created May 2, 2015 13:46
Show Gist options
  • Save rghwang/bc707d879c637c8d7233 to your computer and use it in GitHub Desktop.
Save rghwang/bc707d879c637c8d7233 to your computer and use it in GitHub Desktop.
Func1<OnTextChangeEvent, Boolean> isNotEmpty = t -> t.text().length() != 0;
rx.Observable.combineLatest(
WidgetObservable.text(mNameTextView).map(isNotEmpty),
WidgetObservable.text(mCompanyTextView).map(isNotEmpty),
WidgetObservable.text(mTitleTextView).map(isNotEmpty),
(a, b, c) -> a && b && c
).subscribe(result -> {
Button btn = ((SignUpActivity) getActivity()).mDoneBtn;
if (result) {
btn.getBackground().setColorFilter(getResources().getColor(R.color.accent), PorterDuff.Mode.MULTIPLY);
} else {
btn.getBackground().clearColorFilter();
}
btn.setEnabled(result);
}
);
Observable.combineLatest(
WidgetObservable.text(mNameTextView).map(isNotEmpty),
Observable.create(new Observable.OnSubscribe<Boolean>() {
@Override
public void call(final Subscriber<? super Boolean> subscriber) {
mNameTextView.setOnFocusChangeListener((v, hasFocus) -> {
if (subscriber.isUnsubscribed()) return;
subscriber.onNext(hasFocus);
});
}
}),
(a, b) -> a && b ? View.VISIBLE : View.INVISIBLE
).subscribe(
mNameClearBtn::setVisibility
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment