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

            Title = Resources.LoginTitle;
            ResetSuccessLabel.Text        = Resources.APITokenResetSuccess;
            InstructionLabel.Text         = Resources.TokenResetInstruction;
            PasswordTextField.Placeholder = Resources.Password;
            SignOutButton.SetTitle(Resources.OrSignOut, UIControlState.Normal);

            prepareViews();

            ViewModel.Error
            .Subscribe(ErrorLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            ViewModel.Email
            .SelectToString()
            .Subscribe(EmailLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            ViewModel.Password
            .Subscribe(PasswordTextField.Rx().TextObserver())
            .DisposedBy(DisposeBag);

            PasswordTextField.Rx().Text()
            .Subscribe(ViewModel.Password)
            .DisposedBy(DisposeBag);

            ViewModel.IsPasswordMasked
            .Subscribe(PasswordTextField.Rx().SecureTextEntry())
            .DisposedBy(DisposeBag);

            SignOutButton.Rx()
            .BindAction(ViewModel.SignOut)
            .DisposedBy(DisposeBag);

            ShowPasswordButton.Rx()
            .BindAction(ViewModel.TogglePasswordVisibility)
            .DisposedBy(DisposeBag);

            nextButton.Rx().Tap()
            .Subscribe(ViewModel.Done.Inputs)
            .DisposedBy(DisposeBag);

            PasswordTextField.Rx().ShouldReturn()
            .Subscribe(ViewModel.Done.Inputs)
            .DisposedBy(DisposeBag);

            //Enabled
            ViewModel.NextIsEnabled
            .Subscribe(nextButton.Rx().Enabled())
            .DisposedBy(DisposeBag);

            //Visibility
            ViewModel.HasError
            .Subscribe(ErrorView.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.Done.Executing
            .Invert()
            .Subscribe(ShowPasswordButton.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.Done.Executing
            .Subscribe(ActivityIndicatorView.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            PasswordTextField.BecomeFirstResponder();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = Resources.LoginTitle;
            ResetSuccessLabel.Text        = Resources.APITokenResetSuccess;
            InstructionLabel.Text         = Resources.TokenResetInstruction;
            PasswordTextField.Placeholder = Resources.Password;
            SignOutButton.SetTitle(Resources.OrSignOut, UIControlState.Normal);

            EmailLabel.Text = ViewModel.Email.ToString();

            ViewModel.Error
            .Subscribe(ErrorLabel.Rx().Text())
            .DisposedBy(DisposeBag);

            ViewModel.Password
            .Subscribe(PasswordTextField.Rx().TextObserver())
            .DisposedBy(DisposeBag);

            PasswordTextField.Rx().Text()
            .Subscribe(ViewModel.Password)
            .DisposedBy(DisposeBag);

            SignOutButton.Rx()
            .BindAction(ViewModel.SignOut)
            .DisposedBy(DisposeBag);

            ViewModel.SignOut.Elements
            .Subscribe(IosDependencyContainer.Instance.IntentDonationService.ClearAll)
            .DisposedBy(DisposeBag);

            ShowPasswordButton.Rx().Tap()
            .Subscribe(_ =>
            {
                PasswordTextField.ResignFirstResponder();
                PasswordTextField.SecureTextEntry = !PasswordTextField.SecureTextEntry;
                PasswordTextField.BecomeFirstResponder();
            })
            .DisposedBy(DisposeBag);

            LoginButton.Rx().Tap()
            .Subscribe(ViewModel.Done.Inputs)
            .DisposedBy(DisposeBag);

            PasswordTextField.Rx().ShouldReturn()
            .Subscribe(ViewModel.Done.Inputs)
            .DisposedBy(DisposeBag);

            //Enabled
            ViewModel.NextIsEnabled
            .Subscribe(LoginButton.Rx().Enabled())
            .DisposedBy(DisposeBag);

            //Visibility
            ErrorLabel.Hidden = true;
            ViewModel.HasError
            .Subscribe(ErrorLabel.Rx().AnimatedIsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.Done.Executing
            .Invert()
            .Subscribe(ShowPasswordButton.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.Done.Executing
            .Subscribe(ActivityIndicatorView.Rx().IsVisibleWithFade())
            .DisposedBy(DisposeBag);

            ViewModel.Done.Executing.Select(loginButtonTitle)
            .Subscribe(LoginButton.Rx().AnimatedTitle())
            .DisposedBy(DisposeBag);

            PasswordTextField.BecomeFirstResponder();
            ShowPasswordButton.SetupShowPasswordButton();

            //Color
            ViewModel.HasError
            .Select(loginButtonTintColor)
            .Subscribe(LoginButton.Rx().TintColor())
            .DisposedBy(DisposeBag);

            ViewModel.NextIsEnabled
            .Select(loginButtonTitleColor)
            .Subscribe(LoginButton.Rx().TitleColor())
            .DisposedBy(DisposeBag);

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

            UIColor loginButtonTitleColor(bool enabled) => enabled
                ? Core.UI.Helper.Colors.Login.EnabledButtonColor.ToNativeColor()
                : Core.UI.Helper.Colors.Login.DisabledButtonColor.ToNativeColor();
        }