Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            EmailTextField.Placeholder    = Resources.EmailAddress;
            PasswordTextField.Placeholder = Resources.Password;
            SignUpCardTitleLabel.Text     = Resources.AlreadyHaveAnAccountQuestionMark;
            SignUpCardLoginLabel.Text     = Resources.LoginTitle;
            OrLabel.Text = Resources.Or.ToUpper();
            GoogleSignupButton.SetTitle(Resources.GoogleSignUp, UIControlState.Normal);

            NavigationController.NavigationBarHidden = true;

            UIKeyboard.Notifications.ObserveWillShow(KeyboardWillShow);
            UIKeyboard.Notifications.ObserveWillHide(KeyboardWillHide);

            ViewModel.SuccessfulSignup
            .Subscribe(logAdjustSignupEvent)
            .DisposedBy(DisposeBag);

            //Text
            ViewModel.ErrorMessage
            .Subscribe(ErrorLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            ViewModel.Email
            .Subscribe(EmailTextField.Rx().TextObserver())
            .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(signupButtonTitle)
            .Subscribe(SignupButton.Rx().AnimatedTitle())
            .DisposedBy(DisposeBag);

            ViewModel.CountryButtonTitle
            .Subscribe(SelectCountryButton.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);

            ViewModel.IsCountryErrorVisible
            .Subscribe(CountryNotSelectedImageView.Rx().AnimatedIsVisible())
            .DisposedBy(DisposeBag);

            //Commands
            LoginCard.Rx()
            .BindAction(ViewModel.Login)
            .DisposedBy(DisposeBag);

            SignupButton.Rx()
            .BindAction(ViewModel.Signup)
            .DisposedBy(DisposeBag);

            GoogleSignupButton.Rx()
            .BindAction(ViewModel.GoogleSignup)
            .DisposedBy(DisposeBag);

            ShowPasswordButton.Rx().Tap()
            .Subscribe(ViewModel.TogglePasswordVisibility)
            .DisposedBy(DisposeBag);

            SelectCountryButton.Rx()
            .BindAction(ViewModel.PickCountry)
            .DisposedBy(DisposeBag);

            //Color
            ViewModel.HasError
            .Select(signupButtonTintColor)
            .Subscribe(SignupButton.Rx().TintColor())
            .DisposedBy(DisposeBag);

            ViewModel.SignupEnabled
            .Select(signupButtonTitleColor)
            .Subscribe(SignupButton.Rx().TitleColor())
            .DisposedBy(DisposeBag);

            //Animation
            ViewModel.Shake
            .Subscribe(shakeTargets =>
            {
                if (shakeTargets.HasFlag(SignupViewModel.ShakeTargets.Email))
                {
                    EmailTextField.Shake();
                }

                if (shakeTargets.HasFlag(SignupViewModel.ShakeTargets.Password))
                {
                    PasswordTextField.Shake();
                }

                if (shakeTargets.HasFlag(SignupViewModel.ShakeTargets.Country))
                {
                    SelectCountryButton.Shake();
                }
            })
            .DisposedBy(DisposeBag);

            prepareViews();

            UIColor signupButtonTintColor(bool hasError)
            => hasError ? UIColor.White : UIColor.Black;

            UIColor signupButtonTitleColor(bool enabled) => enabled
                ? Core.UI.Helper.Colors.Login.EnabledButtonColor.ToNativeColor()
                : Core.UI.Helper.Colors.Login.DisabledButtonColor.ToNativeColor();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationController.NavigationBarHidden = true;

            UIKeyboard.Notifications.ObserveWillShow(KeyboardWillShow);
            UIKeyboard.Notifications.ObserveWillHide(KeyboardWillHide);

            //Text
            this.Bind(ViewModel.ErrorMessage, ErrorLabel.Rx().Text());
            this.Bind(ViewModel.Email, EmailTextField.Rx().TextObserver());
            this.Bind(ViewModel.Password, PasswordTextField.Rx().TextObserver());
            this.Bind(EmailTextField.Rx().Text().Select(Email.From), ViewModel.SetEmail);
            this.Bind(PasswordTextField.Rx().Text().Select(Password.From), ViewModel.SetPassword);
            this.Bind(ViewModel.IsLoading.Select(signupButtonTitle), SignupButton.Rx().AnimatedTitle());
            this.Bind(ViewModel.CountryButtonTitle, SelectCountryButton.Rx().AnimatedTitle());

            //Visibility
            this.Bind(ViewModel.HasError, ErrorLabel.Rx().AnimatedIsVisible());
            this.Bind(ViewModel.IsLoading, ActivityIndicator.Rx().IsVisibleWithFade());
            this.Bind(ViewModel.IsPasswordMasked.Skip(1), PasswordTextField.Rx().SecureTextEntry());
            this.Bind(ViewModel.IsShowPasswordButtonVisible, ShowPasswordButton.Rx().IsVisible());
            this.Bind(PasswordTextField.FirstResponder, ViewModel.SetIsShowPasswordButtonVisible);
            this.Bind(ViewModel.IsCountryErrorVisible, CountryNotSelectedImageView.Rx().AnimatedIsVisible());

            //Commands
            this.Bind(LoginCard.Rx().Tap(), ViewModel.Login);
            this.Bind(SignupButton.Rx().Tap(), ViewModel.Signup);
            this.BindVoid(GoogleSignupButton.Rx().Tap(), ViewModel.GoogleSignup);
            this.BindVoid(ShowPasswordButton.Rx().Tap(), ViewModel.TogglePasswordVisibility);
            this.Bind(SelectCountryButton.Rx().Tap(), ViewModel.PickCountry);

            //Color
            this.Bind(ViewModel.HasError.Select(signupButtonTintColor), SignupButton.Rx().TintColor());
            this.Bind(ViewModel.SignupEnabled.Select(signupButtonTitleColor), SignupButton.Rx().TitleColor());

            //Animation
            this.Bind(ViewModel.Shake, shakeTargets =>
            {
                if (shakeTargets.HasFlag(SignupViewModel.ShakeTargets.Email))
                {
                    EmailTextField.Shake();
                }

                if (shakeTargets.HasFlag(SignupViewModel.ShakeTargets.Password))
                {
                    PasswordTextField.Shake();
                }

                if (shakeTargets.HasFlag(SignupViewModel.ShakeTargets.Country))
                {
                    SelectCountryButton.Shake();
                }
            });

            prepareViews();

            UIColor signupButtonTintColor(bool hasError)
            => hasError ? UIColor.White : UIColor.Black;

            UIColor signupButtonTitleColor(bool enabled) => enabled
                ? Color.Login.EnabledButtonColor.ToNativeColor()
                : Color.Login.DisabledButtonColor.ToNativeColor();
        }