public async void OnAuthenticationCompleted(GoogleOAuthToken token) { // SFSafariViewController doesn't dismiss itself DismissViewController(true, null); var googleService = new GoogleService(); var email = await googleService.GetEmailAsync(token.TokenType, token.AccessToken); GoogleLoginButton.SetTitle($"Connected with {email}", UIControlState.Normal); }
public override void ViewDidLoad() { base.ViewDidLoad(); EmailTextField.Placeholder = Resources.EmailAddress; PasswordTextField.Placeholder = Resources.Password; OrLabel.Text = Resources.Or.ToUpper(); LoginButton.SetTitle(Resources.LoginTitle, UIControlState.Normal); GoogleLoginButton.SetTitle(Resources.GoogleLogin, UIControlState.Normal); DontHaveAnAccountLabel.Text = Resources.DoNotHaveAnAccountWithQuestionMark; SignUpForFreeLabel.Text = Resources.SignUpTitle; NavigationController.NavigationBarHidden = true; UIKeyboard.Notifications.ObserveWillShow(KeyboardWillShow); UIKeyboard.Notifications.ObserveWillHide(KeyboardWillHide); //Text ViewModel.Email .Subscribe(EmailTextField.Rx().TextObserver()) .DisposedBy(DisposeBag); ViewModel.ErrorMessage .Subscribe(ErrorLabel.Rx().Text()) .DisposedBy(DisposeBag); ViewModel.Password .Subscribe(PasswordTextField.Rx().TextObserver()) .DisposedBy(DisposeBag); EmailTextField.Rx().Text() .Select(Email.From) .Subscribe(ViewModel.SetEmail) .DisposedBy(DisposeBag); PasswordTextField.Rx().Text() .Select(Password.From) .Subscribe(ViewModel.SetPassword) .DisposedBy(DisposeBag); ViewModel.IsLoading.Select(loginButtonTitle) .Subscribe(LoginButton.Rx().AnimatedTitle()) .DisposedBy(DisposeBag); //Visibility ViewModel.HasError .Subscribe(ErrorLabel.Rx().AnimatedIsVisible()) .DisposedBy(DisposeBag); ViewModel.IsLoading .Subscribe(ActivityIndicator.Rx().IsVisibleWithFade()) .DisposedBy(DisposeBag); ViewModel.IsPasswordMasked .Skip(1) .Subscribe(PasswordTextField.Rx().SecureTextEntry()) .DisposedBy(DisposeBag); ViewModel.IsShowPasswordButtonVisible .Subscribe(ShowPasswordButton.Rx().IsVisible()) .DisposedBy(DisposeBag); PasswordTextField.FirstResponder .Subscribe(ViewModel.SetIsShowPasswordButtonVisible) .DisposedBy(DisposeBag); //Commands SignupCard.Rx() .BindAction(ViewModel.Signup) .DisposedBy(DisposeBag); LoginButton.Rx().Tap() .Subscribe(ViewModel.Login) .DisposedBy(DisposeBag); GoogleLoginButton.Rx().Tap() .Subscribe(ViewModel.GoogleLogin) .DisposedBy(DisposeBag); ForgotPasswordButton.Rx() .BindAction(ViewModel.ForgotPassword) .DisposedBy(DisposeBag); ShowPasswordButton.Rx().Tap() .Subscribe(ViewModel.TogglePasswordVisibility) .DisposedBy(DisposeBag); //Color ViewModel.HasError .Select(loginButtonTintColor) .Subscribe(LoginButton.Rx().TintColor()) .DisposedBy(DisposeBag); ViewModel.LoginEnabled .Select(loginButtonTitleColor) .Subscribe(LoginButton.Rx().TitleColor()) .DisposedBy(DisposeBag); //Animation ViewModel.Shake .Subscribe(shakeTargets => { if (shakeTargets.HasFlag(LoginViewModel.ShakeTargets.Email)) { EmailTextField.Shake(); } if (shakeTargets.HasFlag(LoginViewModel.ShakeTargets.Password)) { PasswordTextField.Shake(); } }) .DisposedBy(DisposeBag); prepareViews(); UIColor loginButtonTintColor(bool hasError) => hasError ? UIColor.White : UIColor.Black; UIColor loginButtonTitleColor(bool enabled) => enabled ? UIColor.White : UIColor.White.ColorWithAlpha((nfloat)0.5); }