Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Username.BackgroundColor       = ComponentBackgroundColor;
            Username.AttributedPlaceholder = new Foundation.NSAttributedString("Username", foregroundColor: ComponentPlaceholderColor);
            Username.TextColor             = ComponentTextColor;
            Username.EditingChanged       += (sender, args) =>
                                             ViewModel.Username = Username.Text;
            ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => Username.Text = x);

            Password.BackgroundColor       = ComponentBackgroundColor;
            Password.AttributedPlaceholder = new Foundation.NSAttributedString("Password", foregroundColor: ComponentPlaceholderColor);
            Password.TextColor             = ComponentTextColor;
            Password.EditingChanged       += (sender, args) =>
                                             ViewModel.Password = Password.Text;
            ViewModel.WhenAnyValue(x => x.Password).Subscribe(x => Password.Text = x);

            Domain.BackgroundColor       = ComponentBackgroundColor;
            Domain.AttributedPlaceholder = new Foundation.NSAttributedString("Domain", foregroundColor: ComponentPlaceholderColor);
            Domain.TextColor             = ComponentTextColor;
            Domain.EditingChanged       += (sender, args) =>
                                           ViewModel.Domain = Domain.Text;
            ViewModel.WhenAnyValue(x => x.Domain).Subscribe(x => Domain.Text = x);

            LoginButton.TouchUpInside += (sender, args) => ViewModel.LoginCommand.ExecuteIfCan();
            ViewModel.LoginCommand.CanExecuteObservable.Subscribe(x => LoginButton.Enabled = x);

            View.BackgroundColor = BackgroundColor;
            LogoImageView.Image  = Images.Logos.Enterprise;

            LoginButton.SetTitleColor(ComponentTextColor, UIControlState.Normal);
            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

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

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

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

            this.ViewportObservable().Subscribe(x => ScrollView.Frame = x);

            ImageHeight.Constant = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 192 : 86;
        }
        public async void CheckUsername_Click(object sender, EventArgs e)
        {
            if (Username.Text.Trim() == "")
            {
                Username.BecomeFirstResponder();
                c.Snack(LangEnglish.UsernameEmpty);
                return;
            }

            if (Username.Text.Trim() == Session.Username)
            {
                c.Snack(LangEnglish.UsernameSame);
                return;
            }

            context.View.EndEditing(true);

            CheckUsername.Enabled = false;
            CheckUsername.Alpha   = 0.5f;

            string responseString = await c.MakeRequest("action=usercheck&Username="******"OK")
            {
                c.Snack(LangEnglish.UsernameAvailable);
            }
            else if (responseString.Substring(0, 6) == "ERROR_")
            {
                c.Snack(c.GetLang(responseString.Substring(6)));
            }
            else
            {
                c.ReportError(responseString);
            }

            CheckUsername.Enabled = true;
            CheckUsername.Alpha   = 1;
        }
Пример #3
0
        private bool CheckFields()
        {
            if (DescriptionText.Text.Trim() == "")
            {
                checkFormMessage = LangEnglish.DescriptionEmpty;
                DescriptionText.BecomeFirstResponder();
                return(false);
            }
            if (DescriptionText.Text.Substring(DescriptionText.Text.Length - 1) == "\\")
            {
                checkFormMessage = LangEnglish.DescriptionBackslash;
                DescriptionText.BecomeFirstResponder();
                return(false);
            }

            if (AccountDataSection.Frame.Height != 0)
            {
                if (Email.Text.Trim() == "")
                {
                    checkFormMessage = LangEnglish.EmailEmpty;
                    Email.BecomeFirstResponder();
                    return(false);
                }
                //If the extension is long, the regex will freeze the app.
                int lastDotPos = Email.Text.LastIndexOf(".");
                if (lastDotPos < Email.Text.Length - 5)
                {
                    checkFormMessage = LangEnglish.EmailWrong;
                    return(false);
                }
                Regex regex = new Regex(Constants.EmailFormat); //when the email extension is long, it will take ages for the regex to finish
                if (!regex.IsMatch(Email.Text))
                {
                    checkFormMessage = LangEnglish.EmailWrong;
                    Email.BecomeFirstResponder();
                    return(false);
                }
                if (Username.Text.Trim() == "")
                {
                    checkFormMessage = LangEnglish.UsernameEmpty;
                    Username.BecomeFirstResponder();
                    return(false);
                }
                if (Username.Text.Trim().Substring(Username.Text.Trim().Length - 1) == "\\")
                {
                    checkFormMessage = LangEnglish.UsernameBackslash;
                    Username.BecomeFirstResponder();
                    return(false);
                }
                if (Name.Text.Trim() == "")
                {
                    checkFormMessage = LangEnglish.NameEmpty;
                    Name.BecomeFirstResponder();
                    return(false);
                }
                if (Name.Text.Trim().Substring(Name.Text.Trim().Length - 1) == "\\")
                {
                    checkFormMessage = LangEnglish.NameBackslash;
                    Name.BecomeFirstResponder();
                    return(false);
                }
            }

            if (ChangePasswordSection.Frame.Height != 0)
            {
                if (OldPassword.Text.Trim().Length < 6)
                {
                    checkFormMessage = LangEnglish.PasswordShort;
                    OldPassword.BecomeFirstResponder();
                    return(false);
                }
                if (NewPassword.Text.Trim().Length < 6)
                {
                    checkFormMessage = LangEnglish.PasswordShort;
                    NewPassword.BecomeFirstResponder();
                    return(false);
                }
                if (OldPassword.Text.Trim() == NewPassword.Text.Trim())
                {
                    checkFormMessage = LangEnglish.PasswordNotChanged;
                    NewPassword.BecomeFirstResponder();
                    return(false);
                }
                if (NewPassword.Text.Trim() != ConfirmPassword.Text.Trim())
                {
                    checkFormMessage = LangEnglish.ConfirmPasswordNoMatch;
                    ConfirmPassword.BecomeFirstResponder();
                    return(false);
                }
            }
            return(true);
        }
Пример #4
0
        private bool CheckFields() //need to resize window on keyboard appereance, otherwise Snackbar will be covered
        {
            if (Sex.SelectedRowInComponent(0) == 0)
            {
                checkFormMessage = LangEnglish.SexEmpty;
                Sex.BecomeFirstResponder();
                return(false);
            }
            if (Email.Text.Trim() == "")
            {
                checkFormMessage = LangEnglish.EmailEmpty;
                Email.BecomeFirstResponder();
                return(false);
            }
            int lastDotPos = Email.Text.LastIndexOf(".");

            if (lastDotPos < Email.Text.Length - 5)
            {
                checkFormMessage = LangEnglish.EmailWrong;
                Email.BecomeFirstResponder();
                return(false);
            }
            //If the extension is long, the regex will freeze the app.
            Regex regex = new Regex(Constants.EmailFormat);

            if (!regex.IsMatch(Email.Text))
            {
                checkFormMessage = LangEnglish.EmailWrong;
                Email.BecomeFirstResponder();
                return(false);
            }
            if (Password.Text.Trim().Length < 6)
            {
                checkFormMessage = LangEnglish.PasswordShort;
                Password.BecomeFirstResponder();
                return(false);
            }
            if (Password.Text.Trim() != ConfirmPassword.Text.Trim())
            {
                checkFormMessage = LangEnglish.ConfirmPasswordNoMatch;
                ConfirmPassword.BecomeFirstResponder();
                return(false);
            }
            if (Username.Text.Trim() == "")
            {
                checkFormMessage = LangEnglish.UsernameEmpty;
                Username.BecomeFirstResponder();
                return(false);
            }
            if (Username.Text.Trim().Substring(Username.Text.Trim().Length - 1) == "\\")
            {
                checkFormMessage = LangEnglish.UsernameBackslash;
                return(false);
            }
            if (Name.Text.Trim() == "")
            {
                checkFormMessage = LangEnglish.NameEmpty;
                Name.BecomeFirstResponder();
                return(false);
            }
            if (Name.Text.Trim().Substring(Name.Text.Trim().Length - 1) == "\\")
            {
                checkFormMessage = LangEnglish.NameBackslash;
                return(false);
            }
            if (rc.uploadedImages.Count == 0)
            {
                checkFormMessage = LangEnglish.ImagesEmpty;
                Images.BecomeFirstResponder();
                return(false);
            }
            if (DescriptionText.Text.Trim() == "")
            {
                checkFormMessage = LangEnglish.DescriptionEmpty;
                DescriptionText.BecomeFirstResponder();
                return(false);
            }
            if (DescriptionText.Text.Substring(DescriptionText.Text.Length - 1) == "\\")
            {
                checkFormMessage = LangEnglish.DescriptionBackslash;
                return(false);
            }
            return(true);
        }
Пример #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Username.BackgroundColor       = ComponentBackgroundColor;
            Username.AttributedPlaceholder = new Foundation.NSAttributedString("Username", foregroundColor: ComponentPlaceholderColor);
            Username.TextColor             = ComponentTextColor;

            Password.BackgroundColor       = ComponentBackgroundColor;
            Password.AttributedPlaceholder = new Foundation.NSAttributedString("Password", foregroundColor: ComponentPlaceholderColor);
            Password.TextColor             = ComponentTextColor;

            Domain.BackgroundColor       = ComponentBackgroundColor;
            Domain.AttributedPlaceholder = new Foundation.NSAttributedString("Domain", foregroundColor: ComponentPlaceholderColor);
            Domain.TextColor             = ComponentTextColor;

            View.BackgroundColor = BackgroundColor;
            LogoImageView.Image  = Images.Logos.Enterprise;

            LoginButton.SetTitleColor(ComponentTextColor, UIControlState.Normal);
            LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

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

            this.ViewportObservable().Subscribe(x => ScrollView.Frame = x);

            ImageHeight.Constant = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 192 : 86;

            OnActivation(d => {
                d(Username.GetChangedObservable().Subscribe(x => ViewModel.Username         = x));
                d(this.WhenAnyValue(x => x.ViewModel.Username).Subscribe(x => Username.Text = x));
                d(Password.GetChangedObservable().Subscribe(x => ViewModel.Password         = x));
                d(this.WhenAnyValue(x => x.ViewModel.Password).Subscribe(x => Password.Text = x));
                d(Domain.GetChangedObservable().Subscribe(x => ViewModel.Domain             = x));
                d(this.WhenAnyValue(x => x.ViewModel.Domain).Subscribe(x => Domain.Text     = x));
                d(LoginButton.GetClickedObservable().InvokeCommand(ViewModel.LoginCommand));
                d(ViewModel.LoginCommand.CanExecuteObservable.Subscribe(x => LoginButton.Enabled = x));

                d(this.WhenAnyValue(x => x.ViewModel.ShowLoginOptionsCommand)
                  .ToBarButtonItem(UIBarButtonSystemItem.Action, x => NavigationItem.RightBarButtonItem = x));

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

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

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

                d(Disposable.Create(() => {
                    Domain.ShouldReturn   = null;
                    Username.ShouldReturn = null;
                    Password.ShouldReturn = null;
                }));
            });
        }