bitwarden-android/src/App/Pages/Settings/SettingsPinPage.cs
Hicham Boushaba d651606800 Add UWP support (#139)
* Add UWP project, and generate services boilerplate

* SqliteService implementation and sqlite-net-pcl update (#bug https://stackoverflow.com/questions/45418669/xamarin-forms-pcl-assemly-issue)

* Important services implementation

* Create a shared project to host images for UWP (to keep code project clean)

* Add extensions to image names referenced by the pcl project

* Add DismissModalToolBarItem to modal pages

* moving UWP folders inside src folder

* Add DeviceInfoService implementation

* Remove dependency on BouncyCastle, and calculate key derivation using native support

* changes requested by project maintener

* Fix HasCamera property

* DeviceActionService implementation
2017-10-02 22:15:13 -04:00

97 lines
3.1 KiB
C#

using System;
using System.Threading.Tasks;
using Acr.UserDialogs;
using Bit.App.Abstractions;
using Bit.App.Resources;
using Xamarin.Forms;
using XLabs.Ioc;
using Plugin.Settings.Abstractions;
using Bit.App.Models.Page;
using Bit.App.Controls;
namespace Bit.App.Pages
{
public class SettingsPinPage : ExtendedContentPage
{
private readonly IUserDialogs _userDialogs;
private readonly ISettings _settings;
private Action<SettingsPinPage> _pinEnteredAction;
public SettingsPinPage(Action<SettingsPinPage> pinEnteredAction)
{
_pinEnteredAction = pinEnteredAction;
_userDialogs = Resolver.Resolve<IUserDialogs>();
_settings = Resolver.Resolve<ISettings>();
Init();
}
public PinPageModel Model { get; set; } = new PinPageModel();
public PinControl PinControl { get; set; }
public TapGestureRecognizer Tgr { get; set; }
public void Init()
{
var instructionLabel = new Label
{
Text = AppResources.SetPINDirection,
LineBreakMode = LineBreakMode.WordWrap,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
HorizontalTextAlignment = TextAlignment.Center,
Style = (Style)Application.Current.Resources["text-muted"]
};
PinControl = new PinControl();
PinControl.Label.SetBinding(Label.TextProperty, nameof(PinPageModel.LabelText));
PinControl.Entry.SetBinding(Entry.TextProperty, nameof(PinPageModel.PIN));
var stackLayout = new StackLayout
{
Padding = new Thickness(30, 40),
Spacing = 20,
Children = { PinControl.Label, instructionLabel, PinControl.Entry }
};
Tgr = new TapGestureRecognizer();
PinControl.Label.GestureRecognizers.Add(Tgr);
instructionLabel.GestureRecognizers.Add(Tgr);
if(Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
{
ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
}
Title = AppResources.SetPIN;
Content = stackLayout;
Content.GestureRecognizers.Add(Tgr);
BindingContext = Model;
}
protected override void OnAppearing()
{
base.OnAppearing();
Tgr.Tapped += Tgr_Tapped;
PinControl.OnPinEntered += PinEntered;
PinControl.InitEvents();
PinControl.Entry.FocusWithDelay();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
PinControl.Dispose();
Tgr.Tapped -= Tgr_Tapped;
PinControl.OnPinEntered -= PinEntered;
}
protected void PinEntered(object sender, EventArgs args)
{
_pinEnteredAction?.Invoke(this);
}
private void Tgr_Tapped(object sender, EventArgs e)
{
PinControl.Entry.Focus();
}
}
}