Skip to content

Instantly share code, notes, and snippets.

@rohmanhakim
Created January 5, 2017 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rohmanhakim/6c5de1fe93eb828478f6ddf912c50fc9 to your computer and use it in GitHub Desktop.
Save rohmanhakim/6c5de1fe93eb828478f6ddf912c50fc9 to your computer and use it in GitHub Desktop.
// Return true jika password yang diketik user < 6 karakter
Observable<Boolean> passwordStream = RxTextView.textChanges(etPassword)
.map(new Func1<CharSequence, Boolean>() {
@Override
public Boolean call(CharSequence charSequence) {
return !TextUtils.isEmpty(charSequence)
&& charSequence.toString().trim().length() < 6;
}
});
Observer<Boolean> passwordObserver = new Observer<Boolean>() {
@Override
public void onCompleted() {
Log.d("rx","Password stream completed");
}
@Override
public void onError(Throwable e) {
Log.d("rx",e.getMessage());
}
@Override
public void onNext(Boolean passwordLessThanLimit) {
Log.d("passwordObserver",String.valueOf(passwordLessThanLimit.booleanValue()));
showPasswordMinimalAlert(passwordLessThanLimit.booleanValue());
}
};
public void showPasswordMinimalAlert(boolean value){
if(value) {
textPasswordAlert.setText(getString(R.string.password_minimal_alert));
textPasswordAlert.setVisibility(View.VISIBLE);
} else {
textPasswordAlert.setVisibility(View.GONE);
}
}
passwordStream.subscribe(passwordObserver);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment