public void Init() { UppercaseCell = new ExtendedSwitchCell { Text = "A-Z", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorUppercase, true) }; UppercaseCell.OnChanged += UppercaseCell_OnChanged; LowercaseCell = new ExtendedSwitchCell { Text = "a-z", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorLowercase, true) }; LowercaseCell.OnChanged += LowercaseCell_OnChanged; SpecialCell = new ExtendedSwitchCell { Text = "!@#$%^&*", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorSpecial, true) }; SpecialCell.OnChanged += SpecialCell_OnChanged; NumbersCell = new ExtendedSwitchCell { Text = "0-9", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorNumbers, true) }; NumbersCell.OnChanged += NumbersCell_OnChanged; AvoidAmbiguousCell = new ExtendedSwitchCell { Text = AppResources.AvoidAmbiguousCharacters, On = !_settings.GetValueOrDefault(Constants.PasswordGeneratorAmbiguous, false) }; AvoidAmbiguousCell.OnChanged += AvoidAmbiguousCell_OnChanged;; NumbersMinCell = new StepperCell(AppResources.MinNumbers, _settings.GetValueOrDefault(Constants.PasswordGeneratorMinNumbers, 1), 0, 5, 1); SpecialMinCell = new StepperCell(AppResources.MinSpecial, _settings.GetValueOrDefault(Constants.PasswordGeneratorMinSpecial, 1), 0, 5, 1); var table = new ExtendedTableView { EnableScrolling = true, Intent = TableIntent.Settings, HasUnevenRows = true, EnableSelection = false, Root = new TableRoot { new TableSection { UppercaseCell, LowercaseCell, NumbersCell, SpecialCell }, new TableSection { NumbersMinCell, SpecialMinCell }, new TableSection { AvoidAmbiguousCell } } }; if (Device.OS == TargetPlatform.iOS) { table.RowHeight = -1; table.EstimatedRowHeight = 44; } Title = AppResources.Settings; Content = table; }
public void Init() { Password = new Label { FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), Margin = new Thickness(15, 30, 15, 30), HorizontalTextAlignment = TextAlignment.Center, FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier"), LineBreakMode = LineBreakMode.TailTruncation, VerticalOptions = LayoutOptions.Start, TextColor = Color.Black }; Tgr = new TapGestureRecognizer(); Password.GestureRecognizers.Add(Tgr); Password.SetBinding(Label.TextProperty, nameof(PasswordGeneratorPageModel.Password)); SliderCell = new SliderViewCell(this, _passwordGenerationService, _settings); RegenerateCell = new ExtendedTextCell { Text = AppResources.RegeneratePassword, TextColor = Colors.Primary }; CopyCell = new ExtendedTextCell { Text = AppResources.CopyPassword, TextColor = Colors.Primary }; UppercaseCell = new ExtendedSwitchCell { Text = "A-Z", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorUppercase, true) }; LowercaseCell = new ExtendedSwitchCell { Text = "a-z", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorLowercase, true) }; SpecialCell = new ExtendedSwitchCell { Text = "!@#$%^&*", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorSpecial, true) }; NumbersCell = new ExtendedSwitchCell { Text = "0-9", On = _settings.GetValueOrDefault(Constants.PasswordGeneratorNumbers, true) }; AvoidAmbiguousCell = new ExtendedSwitchCell { Text = AppResources.AvoidAmbiguousCharacters, On = !_settings.GetValueOrDefault(Constants.PasswordGeneratorAmbiguous, false) }; NumbersMinCell = new StepperCell(AppResources.MinNumbers, _settings.GetValueOrDefault(Constants.PasswordGeneratorMinNumbers, 1), 0, 5, 1, () => { _settings.AddOrUpdateValue(Constants.PasswordGeneratorMinNumbers, Convert.ToInt32(NumbersMinCell.Stepper.Value)); Model.Password = _passwordGenerationService.GeneratePassword(); }); SpecialMinCell = new StepperCell(AppResources.MinSpecial, _settings.GetValueOrDefault(Constants.PasswordGeneratorMinSpecial, 1), 0, 5, 1, () => { _settings.AddOrUpdateValue(Constants.PasswordGeneratorMinSpecial, Convert.ToInt32(SpecialMinCell.Stepper.Value)); Model.Password = _passwordGenerationService.GeneratePassword(); }); var table = new ExtendedTableView { VerticalOptions = LayoutOptions.Start, EnableScrolling = false, Intent = TableIntent.Settings, HasUnevenRows = true, NoHeader = true, Root = new TableRoot { new TableSection(Helpers.GetEmptyTableSectionTitle()) { RegenerateCell, CopyCell }, new TableSection(AppResources.Options) { SliderCell, UppercaseCell, LowercaseCell, NumbersCell, SpecialCell }, new TableSection(Helpers.GetEmptyTableSectionTitle()) { NumbersMinCell, SpecialMinCell }, new TableSection(Helpers.GetEmptyTableSectionTitle()) { AvoidAmbiguousCell } } }; if (Device.RuntimePlatform == Device.iOS) { table.RowHeight = -1; table.EstimatedRowHeight = 44; if (_passwordValueAction != null) { ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel)); } } else if (Device.RuntimePlatform == Device.Android) { table.BottomPadding = 50; } var stackLayout = new RedrawableStackLayout { Orientation = StackOrientation.Vertical, Children = { Password, table }, VerticalOptions = LayoutOptions.FillAndExpand, Spacing = 0 }; table.WrappingStackLayout = () => stackLayout; var scrollView = new ScrollView { Content = stackLayout, Orientation = ScrollOrientation.Vertical, VerticalOptions = LayoutOptions.FillAndExpand }; if (_passwordValueAction != null) { var selectToolBarItem = new ToolbarItem(AppResources.Select, Helpers.ToolbarImage("ion_chevron_right.png"), async() => { if (_fromAutofill) { _googleAnalyticsService.TrackExtensionEvent("SelectedGeneratedPassword"); } else { _googleAnalyticsService.TrackAppEvent("SelectedGeneratedPassword"); } _passwordValueAction(Password.Text); await Navigation.PopForDeviceAsync(); }, ToolbarItemOrder.Default, 0); ToolbarItems.Add(selectToolBarItem); } Title = AppResources.PasswordGenerator; Content = scrollView; BindingContext = Model; }