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;
|
|
|
|
|
using Foundation;
|
|
|
|
|
using MobileCoreServices;
|
2016-07-21 03:57:00 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.iOS.Core.Utilities;
|
|
|
|
|
using Bit.App.Resources;
|
2016-07-20 05:38:12 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
|
{
|
|
|
|
|
public partial class LockPinViewController : UIViewController
|
|
|
|
|
{
|
|
|
|
|
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-22 02:02:04 +03:00
|
|
|
|
public LoadingViewController LoadingViewController { 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-21 03:57:00 +03:00
|
|
|
|
PinLabel.Font = UIFont.FromName("Courier", descriptor.PointSize * 1.3f);
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
PinTextField.ResignFirstResponder();
|
2016-07-22 02:02:04 +03:00
|
|
|
|
LoadingViewController.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)
|
|
|
|
|
{
|
|
|
|
|
CompleteRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CompleteRequest()
|
|
|
|
|
{
|
|
|
|
|
var resultsProvider = new NSItemProvider(null, UTType.PropertyList);
|
|
|
|
|
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
|
|
|
|
|
var returningItems = new NSExtensionItem[] { resultsItem };
|
|
|
|
|
|
|
|
|
|
Context.ExtContext.CompleteRequest(returningItems, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|