Last active
April 24, 2017 20:11
-
-
Save fbencosme/14e76115f9b95302d13b6bd812821a63 to your computer and use it in GitHub Desktop.
Rx Android Xamarin - Signup form
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
// SignUp flow. | |
Observable.CombineLatest( | |
firstName .RxTextChanged(50).StartWith(string.Empty), | |
lastName .RxTextChanged(50).StartWith(string.Empty), | |
email .RxTextChanged(50).StartWith(string.Empty), | |
pwd .RxTextChanged(50).StartWith(string.Empty), | |
confirmPwd.RxTextChanged(50).StartWith(string.Empty), | |
gender .RxSelectedItem() .StartWith(0), | |
, Tuple.Create) | |
.SampleLatest( | |
Observable.Merge( | |
Observable.Merge( | |
firstName .RxKeyPressed(), | |
lastName .RxKeyPressed(), | |
email .RxKeyPressed(), | |
pwd .RxKeyPressed(), | |
confirmPwd.RxKeyPressed() | |
).Where(_ => _ == Keycode.Enter) | |
.Select(_ => Unit.Default) | |
, registerBtn.RxClick() | |
).Do(_ => { | |
email.Error = null; | |
pwd.Error = null; | |
email.Error = null; | |
pwd.Error = null; | |
confirmPwd.Error = null; | |
})) | |
.Do(_ => HideKeyboard()) | |
.Debounce(TimeSpan.FromSeconds(2)) | |
.SelectMany(_ => | |
Service | |
.SignUp(_) | |
.WithProgressDialog()) | |
.Subscribe(_ => | |
_.Match(OnSuccess, OnFailed)); | |
void OnSuccess(User u) {} // Do something | |
void OnFailed (Error e) {} // Do something | |
void HideKeyboard() {} // Code to hide android keyboard. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment