2016-07-02 09:01:47 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Controls;
|
|
|
|
|
using Bit.App.Models.Page;
|
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Plugin.Settings.Abstractions;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using XLabs.Ioc;
|
2017-05-30 21:13:53 +03:00
|
|
|
|
using Bit.App.Utilities;
|
2016-07-02 09:01:47 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public class ToolsPasswordGeneratorPage : ExtendedContentPage
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
private readonly IPasswordGenerationService _passwordGenerationService;
|
|
|
|
|
private readonly ISettings _settings;
|
2017-07-13 06:09:44 +03:00
|
|
|
|
private readonly IDeviceActionService _clipboardService;
|
2016-08-04 07:32:37 +03:00
|
|
|
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
2016-07-07 07:27:29 +03:00
|
|
|
|
private readonly Action<string> _passwordValueAction;
|
2017-02-06 07:55:46 +03:00
|
|
|
|
private readonly bool _fromAutofill;
|
2016-07-02 09:01:47 +03:00
|
|
|
|
|
2017-02-06 07:55:46 +03:00
|
|
|
|
public ToolsPasswordGeneratorPage(Action<string> passwordValueAction = null, bool fromAutofill = false)
|
2016-07-02 09:01:47 +03:00
|
|
|
|
{
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_passwordGenerationService = Resolver.Resolve<IPasswordGenerationService>();
|
|
|
|
|
_settings = Resolver.Resolve<ISettings>();
|
2017-07-13 06:09:44 +03:00
|
|
|
|
_clipboardService = Resolver.Resolve<IDeviceActionService>();
|
2016-08-04 07:32:37 +03:00
|
|
|
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
2016-07-07 07:27:29 +03:00
|
|
|
|
_passwordValueAction = passwordValueAction;
|
2017-02-06 07:55:46 +03:00
|
|
|
|
_fromAutofill = fromAutofill;
|
2016-07-02 09:01:47 +03:00
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PasswordGeneratorPageModel Model { get; private set; } = new PasswordGeneratorPageModel();
|
|
|
|
|
public Label Password { get; private set; }
|
|
|
|
|
public SliderViewCell SliderCell { get; private set; }
|
2017-02-18 05:18:59 +03:00
|
|
|
|
public TapGestureRecognizer Tgr { get; set; }
|
|
|
|
|
public ExtendedTextCell RegenerateCell { get; set; }
|
|
|
|
|
public ExtendedTextCell CopyCell { get; set; }
|
2017-12-20 17:55:19 +03:00
|
|
|
|
public ExtendedSwitchCell UppercaseCell { get; set; }
|
|
|
|
|
public ExtendedSwitchCell LowercaseCell { get; set; }
|
|
|
|
|
public ExtendedSwitchCell SpecialCell { get; set; }
|
|
|
|
|
public ExtendedSwitchCell NumbersCell { get; set; }
|
|
|
|
|
public ExtendedSwitchCell AvoidAmbiguousCell { get; set; }
|
|
|
|
|
public StepperCell SpecialMinCell { get; set; }
|
|
|
|
|
public StepperCell NumbersMinCell { get; set; }
|
2016-07-02 09:01:47 +03:00
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
|
|
|
|
Password = new Label
|
|
|
|
|
{
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
|
2016-07-06 02:07:56 +03:00
|
|
|
|
Margin = new Thickness(15, 40, 15, 40),
|
2016-07-02 09:01:47 +03:00
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
2017-12-11 07:26:58 +03:00
|
|
|
|
FontFamily = Helpers.OnPlatform(iOS: "Menlo-Regular", Android: "monospace", Windows: "Courier"),
|
2016-07-03 09:57:09 +03:00
|
|
|
|
LineBreakMode = LineBreakMode.TailTruncation,
|
|
|
|
|
VerticalOptions = LayoutOptions.Start
|
2016-07-02 09:01:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-02-18 05:18:59 +03:00
|
|
|
|
Tgr = new TapGestureRecognizer();
|
|
|
|
|
Password.GestureRecognizers.Add(Tgr);
|
2017-05-30 21:13:53 +03:00
|
|
|
|
Password.SetBinding(Label.TextProperty, nameof(PasswordGeneratorPageModel.Password));
|
2016-07-02 09:01:47 +03:00
|
|
|
|
|
|
|
|
|
SliderCell = new SliderViewCell(this, _passwordGenerationService, _settings);
|
|
|
|
|
|
|
|
|
|
var buttonColor = Color.FromHex("3c8dbc");
|
2017-02-18 05:18:59 +03:00
|
|
|
|
RegenerateCell = new ExtendedTextCell { Text = AppResources.RegeneratePassword, TextColor = buttonColor };
|
|
|
|
|
CopyCell = new ExtendedTextCell { Text = AppResources.CopyPassword, TextColor = buttonColor };
|
2016-07-02 09:01:47 +03:00
|
|
|
|
|
2017-12-20 17:55:19 +03:00
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-02 09:01:47 +03:00
|
|
|
|
var table = new ExtendedTableView
|
|
|
|
|
{
|
2016-07-06 02:07:56 +03:00
|
|
|
|
VerticalOptions = LayoutOptions.Start,
|
2016-07-02 09:01:47 +03:00
|
|
|
|
EnableScrolling = false,
|
2016-07-05 05:31:15 +03:00
|
|
|
|
Intent = TableIntent.Settings,
|
2016-07-02 09:01:47 +03:00
|
|
|
|
HasUnevenRows = true,
|
2016-07-06 02:07:56 +03:00
|
|
|
|
NoHeader = true,
|
2016-07-02 09:01:47 +03:00
|
|
|
|
Root = new TableRoot
|
|
|
|
|
{
|
2017-11-21 06:39:49 +03:00
|
|
|
|
new TableSection(Helpers.GetEmptyTableSectionTitle())
|
2016-07-02 09:01:47 +03:00
|
|
|
|
{
|
2017-02-18 05:18:59 +03:00
|
|
|
|
RegenerateCell,
|
|
|
|
|
CopyCell
|
2016-07-29 05:07:48 +03:00
|
|
|
|
},
|
2016-11-26 00:32:13 +03:00
|
|
|
|
new TableSection(AppResources.Options)
|
2016-07-29 05:07:48 +03:00
|
|
|
|
{
|
|
|
|
|
SliderCell,
|
2017-12-20 17:55:19 +03:00
|
|
|
|
UppercaseCell,
|
|
|
|
|
LowercaseCell,
|
|
|
|
|
NumbersCell,
|
|
|
|
|
SpecialCell
|
|
|
|
|
},
|
|
|
|
|
new TableSection(Helpers.GetEmptyTableSectionTitle())
|
|
|
|
|
{
|
|
|
|
|
NumbersMinCell,
|
|
|
|
|
SpecialMinCell
|
|
|
|
|
},
|
|
|
|
|
new TableSection(Helpers.GetEmptyTableSectionTitle())
|
|
|
|
|
{
|
|
|
|
|
AvoidAmbiguousCell
|
2016-07-02 09:01:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-13 00:03:25 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
2016-07-02 09:01:47 +03:00
|
|
|
|
{
|
|
|
|
|
table.RowHeight = -1;
|
|
|
|
|
table.EstimatedRowHeight = 44;
|
2016-11-26 00:32:13 +03:00
|
|
|
|
ToolbarItems.Add(new DismissModalToolBarItem(this,
|
|
|
|
|
_passwordValueAction == null ? AppResources.Close : AppResources.Cancel));
|
2016-07-02 09:01:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Orientation = StackOrientation.Vertical,
|
2016-07-05 05:31:15 +03:00
|
|
|
|
Children = { Password, table },
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand,
|
|
|
|
|
Spacing = 0
|
2016-07-02 09:01:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var scrollView = new ScrollView
|
|
|
|
|
{
|
|
|
|
|
Content = stackLayout,
|
2016-07-05 05:31:15 +03:00
|
|
|
|
Orientation = ScrollOrientation.Vertical,
|
|
|
|
|
VerticalOptions = LayoutOptions.FillAndExpand
|
2016-07-02 09:01:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-07-07 07:35:39 +03:00
|
|
|
|
if(_passwordValueAction != null)
|
2016-07-07 07:27:29 +03:00
|
|
|
|
{
|
2017-12-11 23:51:16 +03:00
|
|
|
|
var selectToolBarItem = new ToolbarItem(AppResources.Select, Helpers.ToolbarImage("ion_chevron_right.png"), async () =>
|
2016-07-07 07:35:39 +03:00
|
|
|
|
{
|
2017-02-06 07:55:46 +03:00
|
|
|
|
if(_fromAutofill)
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackExtensionEvent("SelectedGeneratedPassword");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackAppEvent("SelectedGeneratedPassword");
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 07:35:39 +03:00
|
|
|
|
_passwordValueAction(Password.Text);
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await Navigation.PopForDeviceAsync();
|
2016-07-07 07:35:39 +03:00
|
|
|
|
}, ToolbarItemOrder.Default, 0);
|
2016-07-07 07:27:29 +03:00
|
|
|
|
|
2016-07-07 07:35:39 +03:00
|
|
|
|
ToolbarItems.Add(selectToolBarItem);
|
|
|
|
|
}
|
2016-07-07 07:27:29 +03:00
|
|
|
|
|
2017-12-20 17:39:38 +03:00
|
|
|
|
Title = AppResources.PasswordGenerator;
|
2016-07-02 09:01:47 +03:00
|
|
|
|
Content = scrollView;
|
|
|
|
|
BindingContext = Model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Tgr_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CopyPassword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2017-02-18 05:18:59 +03:00
|
|
|
|
Tgr.Tapped += Tgr_Tapped;
|
|
|
|
|
RegenerateCell.Tapped += RegenerateCell_Tapped;
|
|
|
|
|
CopyCell.Tapped += CopyCell_Tapped;
|
|
|
|
|
SliderCell.InitEvents();
|
2017-12-20 17:55:19 +03:00
|
|
|
|
SpecialCell.OnChanged += SpecialCell_OnChanged;
|
|
|
|
|
AvoidAmbiguousCell.OnChanged += AvoidAmbiguousCell_OnChanged;
|
|
|
|
|
UppercaseCell.OnChanged += UppercaseCell_OnChanged;
|
|
|
|
|
LowercaseCell.OnChanged += LowercaseCell_OnChanged;
|
|
|
|
|
NumbersCell.OnChanged += NumbersCell_OnChanged;
|
|
|
|
|
NumbersMinCell.InitEvents();
|
|
|
|
|
SpecialMinCell.InitEvents();
|
2017-02-18 05:18:59 +03:00
|
|
|
|
|
2017-02-06 07:55:46 +03:00
|
|
|
|
if(_fromAutofill)
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackExtensionEvent("GeneratedPassword");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackAppEvent("GeneratedPassword");
|
|
|
|
|
}
|
2016-08-04 07:44:53 +03:00
|
|
|
|
Model.Password = _passwordGenerationService.GeneratePassword();
|
2016-08-04 07:32:37 +03:00
|
|
|
|
Model.Length = _settings.GetValueOrDefault(Constants.PasswordGeneratorLength, 10).ToString();
|
2016-07-02 09:01:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 05:18:59 +03:00
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
|
|
|
|
Tgr.Tapped -= Tgr_Tapped;
|
|
|
|
|
RegenerateCell.Tapped -= RegenerateCell_Tapped;
|
2017-12-20 17:55:19 +03:00
|
|
|
|
SpecialCell.OnChanged -= SpecialCell_OnChanged;
|
|
|
|
|
AvoidAmbiguousCell.OnChanged -= AvoidAmbiguousCell_OnChanged;
|
|
|
|
|
UppercaseCell.OnChanged -= UppercaseCell_OnChanged;
|
|
|
|
|
LowercaseCell.OnChanged -= LowercaseCell_OnChanged;
|
|
|
|
|
NumbersCell.OnChanged -= NumbersCell_OnChanged;
|
|
|
|
|
NumbersMinCell.Dispose();
|
|
|
|
|
SpecialMinCell.Dispose();
|
2017-02-18 05:18:59 +03:00
|
|
|
|
CopyCell.Tapped -= CopyCell_Tapped;
|
|
|
|
|
SliderCell.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-02 09:01:47 +03:00
|
|
|
|
private void RegenerateCell_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-08-04 07:44:53 +03:00
|
|
|
|
Model.Password = _passwordGenerationService.GeneratePassword();
|
2017-02-06 07:55:46 +03:00
|
|
|
|
if(_fromAutofill)
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackExtensionEvent("RegeneratedPassword");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackAppEvent("RegeneratedPassword");
|
|
|
|
|
}
|
2016-07-02 09:01:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CopyCell_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CopyPassword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CopyPassword()
|
|
|
|
|
{
|
2017-02-06 07:55:46 +03:00
|
|
|
|
if(_fromAutofill)
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackExtensionEvent("CopiedGeneratedPassword");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_googleAnalyticsService.TrackAppEvent("CopiedGeneratedPassword");
|
|
|
|
|
}
|
2016-07-02 09:01:47 +03:00
|
|
|
|
_clipboardService.CopyToClipboard(Password.Text);
|
2016-07-26 07:38:41 +03:00
|
|
|
|
_userDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, AppResources.Password));
|
2016-07-02 09:01:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:55:19 +03:00
|
|
|
|
private void AvoidAmbiguousCell_OnChanged(object sender, ToggledEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorAmbiguous, !AvoidAmbiguousCell.On);
|
|
|
|
|
Model.Password = _passwordGenerationService.GeneratePassword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NumbersCell_OnChanged(object sender, ToggledEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorNumbers, NumbersCell.On);
|
|
|
|
|
|
|
|
|
|
if(InvalidState())
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorLowercase, true);
|
|
|
|
|
LowercaseCell.On = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Model.Password = _passwordGenerationService.GeneratePassword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SpecialCell_OnChanged(object sender, ToggledEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorSpecial, SpecialCell.On);
|
|
|
|
|
|
|
|
|
|
if(InvalidState())
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorLowercase, true);
|
|
|
|
|
LowercaseCell.On = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Model.Password = _passwordGenerationService.GeneratePassword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LowercaseCell_OnChanged(object sender, ToggledEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorLowercase, LowercaseCell.On);
|
|
|
|
|
|
|
|
|
|
if(InvalidState())
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorUppercase, true);
|
|
|
|
|
UppercaseCell.On = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Model.Password = _passwordGenerationService.GeneratePassword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UppercaseCell_OnChanged(object sender, ToggledEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorUppercase, UppercaseCell.On);
|
|
|
|
|
|
|
|
|
|
if(InvalidState())
|
|
|
|
|
{
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorLowercase, true);
|
|
|
|
|
LowercaseCell.On = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Model.Password = _passwordGenerationService.GeneratePassword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool InvalidState()
|
|
|
|
|
{
|
|
|
|
|
return !LowercaseCell.On && !UppercaseCell.On && !NumbersCell.On && !SpecialCell.On;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 01:59:09 +03:00
|
|
|
|
// TODO: move to standalone reusable control
|
2017-02-18 05:18:59 +03:00
|
|
|
|
public class SliderViewCell : ExtendedViewCell, IDisposable
|
2016-07-02 09:01:47 +03:00
|
|
|
|
{
|
|
|
|
|
private readonly ToolsPasswordGeneratorPage _page;
|
|
|
|
|
private readonly IPasswordGenerationService _passwordGenerationService;
|
|
|
|
|
private readonly ISettings _settings;
|
|
|
|
|
|
|
|
|
|
public Label Value { get; set; }
|
|
|
|
|
public Slider LengthSlider { get; set; }
|
|
|
|
|
|
|
|
|
|
public SliderViewCell(
|
|
|
|
|
ToolsPasswordGeneratorPage page,
|
|
|
|
|
IPasswordGenerationService passwordGenerationService,
|
|
|
|
|
ISettings settings)
|
|
|
|
|
{
|
|
|
|
|
_page = page;
|
|
|
|
|
_passwordGenerationService = passwordGenerationService;
|
|
|
|
|
_settings = settings;
|
|
|
|
|
|
|
|
|
|
var label = new Label
|
|
|
|
|
{
|
2016-08-23 01:59:15 +03:00
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
|
2016-11-26 00:32:13 +03:00
|
|
|
|
Text = AppResources.Length,
|
2016-07-02 09:01:47 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.Start,
|
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LengthSlider = new Slider(5, 64, _settings.GetValueOrDefault(Constants.PasswordGeneratorLength, 10))
|
|
|
|
|
{
|
|
|
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Value = new Label
|
|
|
|
|
{
|
2016-08-23 01:59:15 +03:00
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
|
2016-07-02 09:01:47 +03:00
|
|
|
|
HorizontalOptions = LayoutOptions.End,
|
|
|
|
|
VerticalOptions = LayoutOptions.CenterAndExpand,
|
|
|
|
|
Style = (Style)Application.Current.Resources["text-muted"]
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
Value.SetBinding(Label.TextProperty, nameof(PasswordGeneratorPageModel.Length));
|
2016-07-02 09:01:47 +03:00
|
|
|
|
|
|
|
|
|
var stackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Orientation = StackOrientation.Horizontal,
|
|
|
|
|
Spacing = 15,
|
|
|
|
|
Children = { label, LengthSlider, Value },
|
2017-05-30 21:13:53 +03:00
|
|
|
|
Padding = Helpers.OnPlatform(
|
2016-08-23 05:59:42 +03:00
|
|
|
|
iOS: new Thickness(15, 8),
|
|
|
|
|
Android: new Thickness(16, 10),
|
2017-12-11 07:26:58 +03:00
|
|
|
|
Windows: new Thickness(15, 8))
|
2016-07-02 09:01:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-26 04:43:47 +03:00
|
|
|
|
stackLayout.AdjustPaddingForDevice();
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.Android)
|
2016-08-23 05:59:42 +03:00
|
|
|
|
{
|
|
|
|
|
label.TextColor = Color.Black;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-02 09:01:47 +03:00
|
|
|
|
View = stackLayout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var length = Convert.ToInt32(LengthSlider.Value);
|
|
|
|
|
_settings.AddOrUpdateValue(Constants.PasswordGeneratorLength, length);
|
|
|
|
|
_page.Model.Length = length.ToString();
|
|
|
|
|
_page.Model.Password = _passwordGenerationService.GeneratePassword();
|
|
|
|
|
}
|
2017-02-18 05:18:59 +03:00
|
|
|
|
|
|
|
|
|
public void InitEvents()
|
|
|
|
|
{
|
|
|
|
|
LengthSlider.ValueChanged += Slider_ValueChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
LengthSlider.ValueChanged -= Slider_ValueChanged;
|
|
|
|
|
}
|
2016-07-02 09:01:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|