2016-07-21 03:57:00 +03:00
|
|
|
|
using System;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
using Bit.iOS.Extension.Models;
|
|
|
|
|
using UIKit;
|
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
using Plugin.Settings.Abstractions;
|
2016-07-21 03:57:00 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.iOS.Core.Utilities;
|
|
|
|
|
using Bit.App.Resources;
|
2016-07-22 03:59:55 +03:00
|
|
|
|
using System.Diagnostics;
|
2016-07-22 06:41:50 +03:00
|
|
|
|
using Bit.App;
|
2016-08-04 07:06:09 +03:00
|
|
|
|
using Bit.iOS.Core.Controllers;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
|
{
|
2016-08-04 07:06:09 +03:00
|
|
|
|
public partial class LockPinViewController : ExtendedUIViewController
|
2016-07-20 05:38:12 +03:00
|
|
|
|
{
|
|
|
|
|
private ISettings _settings;
|
2016-07-21 03:57:00 +03:00
|
|
|
|
private IAuthService _authService;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
public LockPinViewController(IntPtr handle) : base(handle)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public Context Context { get; set; }
|
2016-07-26 04:32:15 +03:00
|
|
|
|
public LoadingViewController LoadingController { get; set; }
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
public override void ViewWillAppear(bool animated)
|
|
|
|
|
{
|
|
|
|
|
UINavigationBar.Appearance.ShadowImage = new UIImage();
|
|
|
|
|
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
|
|
|
|
|
base.ViewWillAppear(animated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ViewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
_settings = Resolver.Resolve<ISettings>();
|
2016-07-21 03:57:00 +03:00
|
|
|
|
_authService = Resolver.Resolve<IAuthService>();
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
|
|
|
|
|
|
|
|
|
|
var descriptor = UIFontDescriptor.PreferredBody;
|
2016-07-23 22:58:50 +03:00
|
|
|
|
PinLabel.Font = UIFont.FromName("Courier", 35);
|
|
|
|
|
|
|
|
|
|
InstructionLabel.LineBreakMode = UILineBreakMode.WordWrap;
|
|
|
|
|
InstructionLabel.Lines = 0;
|
|
|
|
|
InstructionLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize * 0.8f);
|
|
|
|
|
InstructionLabel.TextColor = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f);
|
2016-07-21 03:57:00 +03:00
|
|
|
|
|
2016-07-21 05:48:53 +03:00
|
|
|
|
PinTextField.EditingChanged += PinTextField_EditingChanged;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
base.ViewDidLoad();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 03:57:00 +03:00
|
|
|
|
public override void ViewDidAppear(bool animated)
|
|
|
|
|
{
|
|
|
|
|
base.ViewDidAppear(animated);
|
|
|
|
|
PinTextField.BecomeFirstResponder();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 05:48:53 +03:00
|
|
|
|
private void PinTextField_EditingChanged(object sender, EventArgs e)
|
2016-07-21 03:57:00 +03:00
|
|
|
|
{
|
2016-07-21 06:51:31 +03:00
|
|
|
|
SetLabelText();
|
2016-07-21 03:57:00 +03:00
|
|
|
|
|
|
|
|
|
if(PinTextField.Text.Length >= 4)
|
|
|
|
|
{
|
|
|
|
|
if(PinTextField.Text == _authService.PIN)
|
|
|
|
|
{
|
2016-07-22 03:59:55 +03:00
|
|
|
|
Debug.WriteLine("BW Log, Start Dismiss PIN controller.");
|
2016-08-06 06:58:31 +03:00
|
|
|
|
_settings.AddOrUpdateValue(Constants.Locked, false);
|
2016-07-21 03:57:00 +03:00
|
|
|
|
PinTextField.ResignFirstResponder();
|
2016-07-26 04:32:15 +03:00
|
|
|
|
LoadingController.DismissLockAndContinue();
|
2016-07-21 03:57:00 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// TODO: keep track of invalid attempts and logout?
|
|
|
|
|
|
2016-07-21 06:51:31 +03:00
|
|
|
|
var alert = Dialogs.CreateAlert(null, "Invalid PIN. Try again.", AppResources.Ok, (a) =>
|
|
|
|
|
{
|
|
|
|
|
PinTextField.Text = string.Empty;
|
|
|
|
|
SetLabelText();
|
|
|
|
|
PinTextField.BecomeFirstResponder();
|
|
|
|
|
});
|
2016-07-21 03:57:00 +03:00
|
|
|
|
PresentViewController(alert, true, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 06:51:31 +03:00
|
|
|
|
private void SetLabelText()
|
|
|
|
|
{
|
|
|
|
|
var newText = string.Empty;
|
|
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
newText += PinTextField.Text.Length <= i ? "- " : "● ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PinLabel.Text = newText.TrimEnd();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 05:38:12 +03:00
|
|
|
|
partial void CancelButton_Activated(UIBarButtonItem sender)
|
|
|
|
|
{
|
2016-07-26 04:32:15 +03:00
|
|
|
|
LoadingController.CompleteRequest(null);
|
2016-07-20 05:38:12 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|