Created
March 16, 2017 11:09
Subscriber only called when the validity changes. For this, we’d need to call distinctUntilChanged() method on our Observables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isUsernameValid.distinctUntilChanged().doOnNext(new Consumer<Boolean>() { | |
@Override | |
public void accept(Boolean valid) throws Exception { | |
Log.d(TAG, "Username " + (valid ? "Valid" : "Invalid")); | |
} | |
}).map(new Function<Boolean, Integer>() { | |
@Override | |
public Integer apply(Boolean valid) throws Exception { | |
return valid?Color.WHITE:Color.RED; | |
} | |
}).subscribe(new Consumer<Integer>() { | |
@Override | |
public void accept(Integer color) throws Exception { | |
mUsernameEditText.setTextColor(color); | |
} | |
}); | |
isEmailValid.distinctUntilChanged().doOnNext(new Consumer<Boolean>() { | |
@Override | |
public void accept(Boolean valid) throws Exception { | |
Log.d(TAG, "Email " + (valid ? "Valid" : "Invalid")); | |
} | |
}).map(new Function<Boolean, Integer>() { | |
@Override | |
public Integer apply(Boolean valid) throws Exception { | |
return valid?Color.WHITE:Color.RED; | |
} | |
}).subscribe(new Consumer<Integer>() { | |
@Override | |
public void accept(Integer color) throws Exception { | |
mEmailEditText.setTextColor(color); | |
} | |
}); | |
registerButtonObservable.distinctUntilChanged().subscribe(new Consumer<Boolean>() { | |
@Override | |
public void accept(Boolean aBoolean) throws Exception { | |
mRegisterButton.setEnabled(aBoolean); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment