Created
January 5, 2017 09:31
-
-
Save rohmanhakim/6c5de1fe93eb828478f6ddf912c50fc9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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