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;
|
2017-02-18 05:18:59 +03:00
|
|
|
|
private Action<SettingsPinPage> _pinEnteredAction;
|
2016-06-12 07:49:35 +03:00
|
|
|
|
|
2017-02-18 05:18:59 +03:00
|
|
|
|
public SettingsPinPage(Action<SettingsPinPage> pinEnteredAction)
|
2016-06-12 07:49:35 +03:00
|
|
|
|
{
|
2017-02-18 05:18:59 +03:00
|
|
|
|
_pinEnteredAction = pinEnteredAction;
|
2016-06-12 07:49:35 +03:00
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_settings = Resolver.Resolve<ISettings>();
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PinPageModel Model { get; set; } = new PinPageModel();
|
|
|
|
|
public PinControl PinControl { get; set; }
|
2017-02-18 05:18:59 +03:00
|
|
|
|
public TapGestureRecognizer Tgr { get; set; }
|
2016-06-12 07:49:35 +03:00
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2016-07-23 22:58:50 +03:00
|
|
|
|
var instructionLabel = new Label
|
|
|
|
|
{
|
2016-11-25 21:22:11 +03:00
|
|
|
|
Text = AppResources.SetPINDirection,
|
2016-07-23 22:58:50 +03:00
|
|
|
|
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();
|
2017-05-30 21:13:53 +03:00
|
|
|
|
PinControl.Label.SetBinding(Label.TextProperty, nameof(PinPageModel.LabelText));
|
|
|
|
|
PinControl.Entry.SetBinding(Entry.TextProperty, nameof(PinPageModel.PIN));
|
2016-06-12 07:49:35 +03:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
2017-02-18 05:18:59 +03:00
|
|
|
|
Tgr = new TapGestureRecognizer();
|
|
|
|
|
PinControl.Label.GestureRecognizers.Add(Tgr);
|
|
|
|
|
instructionLabel.GestureRecognizers.Add(Tgr);
|
2016-06-12 07:49:35 +03:00
|
|
|
|
|
2017-10-03 05:15:13 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
|
2017-02-09 03:18:34 +03:00
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Cancel));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 21:22:11 +03:00
|
|
|
|
Title = AppResources.SetPIN;
|
2016-06-12 07:49:35 +03:00
|
|
|
|
Content = stackLayout;
|
2017-02-18 05:18:59 +03:00
|
|
|
|
Content.GestureRecognizers.Add(Tgr);
|
2016-06-12 07:49:35 +03:00
|
|
|
|
BindingContext = Model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2017-02-18 05:18:59 +03:00
|
|
|
|
Tgr.Tapped += Tgr_Tapped;
|
2017-02-15 08:28:05 +03:00
|
|
|
|
PinControl.OnPinEntered += PinEntered;
|
|
|
|
|
PinControl.InitEvents();
|
2016-08-19 07:27:37 +03:00
|
|
|
|
PinControl.Entry.FocusWithDelay();
|
2016-06-12 07:49:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 08:28:05 +03:00
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
|
|
|
|
PinControl.Dispose();
|
2017-02-18 05:18:59 +03:00
|
|
|
|
Tgr.Tapped -= Tgr_Tapped;
|
2017-02-15 08:28:05 +03:00
|
|
|
|
PinControl.OnPinEntered -= PinEntered;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-12 07:49:35 +03:00
|
|
|
|
protected void PinEntered(object sender, EventArgs args)
|
|
|
|
|
{
|
2017-02-18 05:18:59 +03:00
|
|
|
|
_pinEnteredAction?.Invoke(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Tgr_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
PinControl.Entry.Focus();
|
2016-06-12 07:49:35 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|