Пример #1
0
        public async override void ViewDidLoad()
        {
            _passwordGenerationService = ServiceContainer.Resolve <IPasswordGenerationService>(
                "passwordGenerationService");

            BaseNavItem.Title         = AppResources.PasswordGenerator;
            BaseCancelButton.Title    = AppResources.Cancel;
            BaseSelectBarButton.Title = AppResources.Select;

            var descriptor = UIFontDescriptor.PreferredBody;

            BasePasswordLabel.Font                      = UIFont.FromName("Menlo-Regular", descriptor.PointSize * 1.3f);
            BasePasswordLabel.LineBreakMode             = UILineBreakMode.TailTruncation;
            BasePasswordLabel.Lines                     = 0;
            BasePasswordLabel.AdjustsFontSizeToFitWidth = false;
            BasePasswordLabel.TextColor                 = ThemeHelpers.TextColor;

            var controller = ChildViewControllers.LastOrDefault();

            if (controller != null)
            {
                OptionsTableViewController = controller as UITableViewController;
            }

            if (OptionsTableViewController != null)
            {
                OptionsTableViewController.TableView.RowHeight          = UITableView.AutomaticDimension;
                OptionsTableViewController.TableView.EstimatedRowHeight = 70;
                OptionsTableViewController.TableView.Source             = new TableSource(this);
                OptionsTableViewController.TableView.AllowsSelection    = true;
                OptionsTableViewController.View.BackgroundColor         = ThemeHelpers.BackgroundColor;
                OptionsTableViewController.TableView.SeparatorColor     = ThemeHelpers.SeparatorColor;
            }

            TypePickerCell.Items         = TypeOptions;
            TypePickerCell.ValueChanged += Type_ValueChanged;
            SetPassType();

            var(options, enforcedPolicyOptions) = await _passwordGenerationService.GetOptionsAsync();

            UppercaseCell.Switch.On = options.Uppercase.GetValueOrDefault();
            LowercaseCell.Switch.On = options.Lowercase.GetValueOrDefault(true);
            SpecialCell.Switch.On   = options.Special.GetValueOrDefault();
            NumbersCell.Switch.On   = options.Number.GetValueOrDefault();
            MinNumbersCell.Value    = options.MinNumber.GetValueOrDefault(1);
            MinSpecialCell.Value    = options.MinSpecial.GetValueOrDefault(1);
            LengthCell.Value        = options.Length.GetValueOrDefault(14);
            AmbiguousCell.Switch.On = options.Ambiguous.GetValueOrDefault();

            NumWordsCell.Value = options.NumWords.GetValueOrDefault(3);
            WordSeparatorCell.TextField.Text = options.WordSeparator ?? "";
            CapitalizeCell.Switch.On         = options.Capitalize.GetValueOrDefault();
            IncludeNumberCell.Switch.On      = options.IncludeNumber.GetValueOrDefault();

            UppercaseCell.ValueChanged  += Options_ValueChanged;
            LowercaseCell.ValueChanged  += Options_ValueChanged;
            NumbersCell.ValueChanged    += Options_ValueChanged;
            SpecialCell.ValueChanged    += Options_ValueChanged;
            MinNumbersCell.ValueChanged += Options_ValueChanged;
            MinSpecialCell.ValueChanged += Options_ValueChanged;
            LengthCell.ValueChanged     += Options_ValueChanged;
            AmbiguousCell.ValueChanged  += Options_ValueChanged;

            NumWordsCell.ValueChanged      += Options_ValueChanged;
            WordSeparatorCell.ValueChanged += Options_ValueChanged;
            CapitalizeCell.ValueChanged    += Options_ValueChanged;
            IncludeNumberCell.ValueChanged += Options_ValueChanged;

            // Adjust based on context password options
            if (PasswordOptions != null)
            {
                if (PasswordOptions.RequireDigits)
                {
                    NumbersCell.Switch.On      = true;
                    NumbersCell.Switch.Enabled = false;

                    if (MinNumbersCell.Value < 1)
                    {
                        MinNumbersCell.Value = 1;
                    }

                    MinNumbersCell.Stepper.MinimumValue = 1;
                }

                if (PasswordOptions.RequireSymbols)
                {
                    SpecialCell.Switch.On      = true;
                    SpecialCell.Switch.Enabled = false;

                    if (MinSpecialCell.Value < 1)
                    {
                        MinSpecialCell.Value = 1;
                    }

                    MinSpecialCell.Stepper.MinimumValue = 1;
                }

                if (PasswordOptions.MinLength < PasswordOptions.MaxLength)
                {
                    if (PasswordOptions.MinLength > 0 && PasswordOptions.MinLength > LengthCell.Slider.MinValue)
                    {
                        if (LengthCell.Value < PasswordOptions.MinLength)
                        {
                            LengthCell.Slider.Value = PasswordOptions.MinLength;
                        }

                        LengthCell.Slider.MinValue = PasswordOptions.MinLength;
                    }

                    if (PasswordOptions.MaxLength > 5 && PasswordOptions.MaxLength < LengthCell.Slider.MaxValue)
                    {
                        if (LengthCell.Value > PasswordOptions.MaxLength)
                        {
                            LengthCell.Slider.Value = PasswordOptions.MaxLength;
                        }

                        LengthCell.Slider.MaxValue = PasswordOptions.MaxLength;
                    }
                }
            }

            var task = GeneratePasswordAsync();

            base.ViewDidLoad();
        }