Skip to content

Instantly share code, notes, and snippets.

@lawloretienne
Created February 29, 2020 17:32
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/ee8fc5a8f375355c5ee58bd2a51c7ade to your computer and use it in GitHub Desktop.
Save lawloretienne/ee8fc5a8f375355c5ee58bd2a51c7ade to your computer and use it in GitHub Desktop.
PasswordChangeObservable
Subscription passwordSubscription =
passwordChangeObservable
.doOnNext(new Action1<CharSequence>() {
@Override
public void call(CharSequence charSequence) {
hidePasswordError();
}
})
.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 isPasswordValid = validatePassword(charSequence.toString());
if (!isPasswordValid) {
showPasswordError();
} else {
hidePasswordError();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment