Created
May 20, 2018 12:46
-
-
Save Orange168/aad753ab0a4ce67d7a8ff4292907fca8 to your computer and use it in GitHub Desktop.
RX 登录实例
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
private void rxEditText() { | |
Observable.combineLatest(RxTextView.textChanges(mEditName).map(new Function<CharSequence, String>() { | |
@Override | |
public String apply(CharSequence charSequence) throws Exception { | |
return String.valueOf(charSequence); | |
} | |
}), RxTextView.textChanges(mEditPwd).map(new Function<CharSequence, String>() { | |
@Override | |
public String apply(CharSequence charSequence) throws Exception { | |
return String.valueOf(charSequence); | |
} | |
}), new BiFunction<String, String, Boolean>() { | |
@Override | |
public Boolean apply(String name, String password) throws Exception { | |
return isNameValid(name) && isPwdValid(password); | |
} | |
}).subscribe(new Consumer<Boolean>() { | |
@Override | |
public void accept(Boolean aBoolean) throws Exception { | |
if (aBoolean) { | |
mBtnLogin.setEnabled(true); | |
RxView.clicks(mBtnLogin).subscribe(new Consumer<Object>() { | |
@Override | |
public void accept(Object o) throws Exception { | |
Toast.makeText(MainActivity.this, "Login Success!", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
} | |
}); | |
} | |
private boolean isNameValid(String name) { | |
return "RxBind".equals(name); | |
} | |
private boolean isPwdValid(String pwd) { | |
return "123".equals(pwd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment