Skip to content

Instantly share code, notes, and snippets.

@lawloretienne
Last active February 29, 2020 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawloretienne/ce46823d89db3ea0afd7010deede66b5 to your computer and use it in GitHub Desktop.
Save lawloretienne/ce46823d89db3ea0afd7010deede66b5 to your computer and use it in GitHub Desktop.
EmailChangeObservable
Subscription emailSubscription =
emailChangeObservable
.doOnNext(new Action1<CharSequence>() {
@Override
public void call(CharSequence charSequence) {
hideEmailError();
}
})
.debounce(400, TimeUnit.MILLISECONDS)
.filter(new Func1<CharSequence, Boolean>() {
@Override
public Boolean call(CharSequence charSequence) {
return !TextUtils.isEmpty(charSequence);
}
})
.observeOn(AndroidSchedulers.mainThread()) // UI Thread
.subscribe(new Subscriber<CharSequence>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(CharSequence charSequence) {
boolean isEmailValid = validateEmail(charSequence.toString());
if (!isEmailValid) {
showEmailError();
} else {
hideEmailError();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment