Last active
January 4, 2017 10:19
-
-
Save rohmanhakim/8072ede69fda5cd4589260668859f947 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; | |
} | |
}); | |
Subscriber<Boolean> passwordSubscriber = new Subscriber<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("passwordSubscriber",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(passwordSubscriber); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment