void ReleaseDesignerOutlets()
        {
            if (ContainerView != null)
            {
                ContainerView.Dispose();
                ContainerView = null;
            }

            if (Domain != null)
            {
                Domain.Dispose();
                Domain = null;
            }

            if (LoginButton != null)
            {
                LoginButton.Dispose();
                LoginButton = null;
            }

            if (Logo != null)
            {
                Logo.Dispose();
                Logo = null;
            }

            if (Password != null)
            {
                Password.Dispose();
                Password = null;
            }

            if (ScrollView != null)
            {
                ScrollView.Dispose();
                ScrollView = null;
            }

            if (User != null)
            {
                User.Dispose();
                User = null;
            }

            if (StackView != null)
            {
                StackView.Dispose();
                StackView = null;
            }

            if (TokenTextField != null)
            {
                TokenTextField.Dispose();
                TokenTextField = null;
            }

            if (AuthenticationSelector != null)
            {
                AuthenticationSelector.Dispose();
                AuthenticationSelector = null;
            }

            if (DescriptionLabel != null)
            {
                DescriptionLabel.Dispose();
                DescriptionLabel = null;
            }
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var scopes = string.Join(", ", OctokitClientFactory.Scopes);

            DescriptionLabel.Text      = string.Format("The provided Personal Access Token must allow access to the following scopes: {0}", scopes);
            DescriptionLabel.TextColor = ComponentTextColor;

            AuthenticationSelector.TintColor = ComponentTextColor.ColorWithAlpha(0.9f);

            View.BackgroundColor = EnterpriseBackgroundColor;
            Logo.Image           = Images.Logos.EnterpriseMascot;

            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);
            LoginButton.Enabled = true;

            //Set some generic shadowing
            LoginButton.Layer.ShadowColor   = UIColor.Black.CGColor;
            LoginButton.Layer.ShadowOffset  = new CGSize(0, 1);
            LoginButton.Layer.ShadowOpacity = 0.2f;

            var attributes = new UIStringAttributes {
                ForegroundColor = UIColor.LightGray,
            };

            Domain.AttributedPlaceholder         = new NSAttributedString("Domain", attributes);
            User.AttributedPlaceholder           = new NSAttributedString("Username", attributes);
            Password.AttributedPlaceholder       = new NSAttributedString("Password", attributes);
            TokenTextField.AttributedPlaceholder = new NSAttributedString("Token", attributes);

            foreach (var i in new [] { Domain, User, Password, TokenTextField })
            {
                i.Layer.BorderColor  = UIColor.Black.CGColor;
                i.Layer.BorderWidth  = 1;
                i.Layer.CornerRadius = 4;
            }

            SelectAuthenticationScheme(0);

            Domain.ShouldReturn = delegate {
                User.BecomeFirstResponder();
                return(true);
            };

            User.ShouldReturn = delegate {
                Password.BecomeFirstResponder();
                return(true);
            };

            Password.ShouldReturn = delegate {
                Password.ResignFirstResponder();
                LoginButton.SendActionForControlEvents(UIControlEvent.TouchUpInside);
                return(true);
            };

            OnActivation(d =>
            {
                d(User.GetChangedObservable()
                  .Subscribe(x => ViewModel.Username = x));

                d(Password.GetChangedObservable()
                  .Subscribe(x => ViewModel.Password = x));

                d(Domain.GetChangedObservable()
                  .Subscribe(x => ViewModel.Domain = x));

                d(TokenTextField.GetChangedObservable()
                  .Subscribe(x => ViewModel.Token = x));

                d(LoginButton.GetClickedObservable()
                  .InvokeReactiveCommand(ViewModel.LoginCommand));

                d(AuthenticationSelector.GetChangedObservable()
                  .Do(x => ViewModel.TokenAuthentication = x == 1)
                  .Subscribe(SelectAuthenticationScheme));

                d(this.WhenAnyObservable(x => x.ViewModel.LoginCommand.CanExecute)
                  .Subscribe(x => LoginButton.Enabled = x));

                d(this.WhenAnyValue(x => x.ViewModel.TokenAuthentication)
                  .Subscribe(x => AuthenticationSelector.SelectedSegment = x ? 1 : 0));
            });
        }