Skip to content

Instantly share code, notes, and snippets.

@fbencosme
Last active April 24, 2017 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbencosme/14e76115f9b95302d13b6bd812821a63 to your computer and use it in GitHub Desktop.
Save fbencosme/14e76115f9b95302d13b6bd812821a63 to your computer and use it in GitHub Desktop.
Rx Android Xamarin - Signup form
// 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