2016-06-12 07:49:35 +03:00
|
|
|
|
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
|
|
|
|
|
{
|
2016-06-28 02:53:31 +03:00
|
|
|
|
public class SettingsPinPage : ExtendedContentPage
|
2016-06-12 07:49:35 +03:00
|
|
|
|
{
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
private readonly ISettings _settings;
|
|
|
|
|
|
|
|
|
|
public SettingsPinPage()
|
|
|
|
|
{
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_settings = Resolver.Resolve<ISettings>();
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PinPageModel Model { get; set; } = new PinPageModel();
|
|
|
|
|
public PinControl PinControl { get; set; }
|
|
|
|
|
public EventHandler OnPinEntered;
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2016-07-23 22:58:50 +03:00
|
|
|
|
var instructionLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = "Enter a 4 digit PIN code to unlock the app with.",
|
|
|
|
|
LineBreakMode = LineBreakMode.WordWrap,
|
|
|
|
|
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
Style = (Style)Application.Current.Resources["text-muted"]
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-12 07:49:35 +03:00
|
|
|
|
PinControl = new PinControl();
|
|
|
|
|
PinControl.OnPinEntered += PinEntered;
|
|
|
|
|
PinControl.Label.SetBinding<PinPageModel>(Label.TextProperty, s => s.LabelText);
|
|
|
|
|
PinControl.Entry.SetBinding<PinPageModel>(Entry.TextProperty, s => s.PIN);
|
|
|
|
|
|
|
|
|
|
var stackLayout = new StackLayout
|
|
|
|
|
{
|
|
|
|
|
Padding = new Thickness(30, 40),
|
2016-07-23 22:58:50 +03:00
|
|
|
|
Spacing = 20,
|
|
|
|
|
Children = { PinControl.Label, instructionLabel, PinControl.Entry }
|
2016-06-12 07:49:35 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var tgr = new TapGestureRecognizer();
|
|
|
|
|
tgr.Tapped += Tgr_Tapped;
|
2016-07-01 01:53:43 +03:00
|
|
|
|
PinControl.Label.GestureRecognizers.Add(tgr);
|
2016-07-23 22:58:50 +03:00
|
|
|
|
instructionLabel.GestureRecognizers.Add(tgr);
|
2016-06-12 07:49:35 +03:00
|
|
|
|
|
|
|
|
|
Title = "Set PIN";
|
|
|
|
|
Content = stackLayout;
|
|
|
|
|
Content.GestureRecognizers.Add(tgr);
|
|
|
|
|
BindingContext = Model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Tgr_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
PinControl.Entry.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2016-08-19 07:27:37 +03:00
|
|
|
|
PinControl.Entry.FocusWithDelay();
|
2016-06-12 07:49:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void PinEntered(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
OnPinEntered.Invoke(this, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|