diff --git a/src/iOS.Extension/LockPinViewController.cs b/src/iOS.Extension/LockPinViewController.cs index 56e3327c2..5df5ec18e 100644 --- a/src/iOS.Extension/LockPinViewController.cs +++ b/src/iOS.Extension/LockPinViewController.cs @@ -1,16 +1,20 @@ -using System; +using System; using Bit.iOS.Extension.Models; using UIKit; using XLabs.Ioc; using Plugin.Settings.Abstractions; using Foundation; using MobileCoreServices; +using Bit.App.Abstractions; +using Bit.iOS.Core.Utilities; +using Bit.App.Resources; namespace Bit.iOS.Extension { public partial class LockPinViewController : UIViewController { private ISettings _settings; + private IAuthService _authService; public LockPinViewController(IntPtr handle) : base(handle) { } @@ -27,14 +31,53 @@ namespace Bit.iOS.Extension public override void ViewDidLoad() { _settings = Resolver.Resolve(); + _authService = Resolver.Resolve(); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); var descriptor = UIFontDescriptor.PreferredBody; + PinLabel.Font = UIFont.FromName("Courier", descriptor.PointSize * 1.3f); + + PinTextField.ValueChanged += PinTextField_ValueChanged; base.ViewDidLoad(); } + public override void ViewDidAppear(bool animated) + { + base.ViewDidAppear(animated); + PinTextField.BecomeFirstResponder(); + } + + private void PinTextField_ValueChanged(object sender, EventArgs e) + { + var newText = string.Empty; + for(int i = 0; i < 4; i++) + { + newText += PinTextField.Text.Length <= i ? "- " : "● "; + } + + PinLabel.Text = newText.TrimEnd(); + + if(PinTextField.Text.Length >= 4) + { + if(PinTextField.Text == _authService.PIN) + { + PinTextField.ResignFirstResponder(); + DismissModalViewController(true); + } + else + { + // TODO: keep track of invalid attempts and logout? + + var alert = Dialogs.CreateAlert(null, "Invalid PIN. Try again.", AppResources.Ok); + PresentViewController(alert, true, null); + PinTextField.Text = string.Empty; + PinTextField.BecomeFirstResponder(); + } + } + } + partial void CancelButton_Activated(UIBarButtonItem sender) { CompleteRequest(); diff --git a/src/iOS.Extension/LockPinViewController.designer.cs b/src/iOS.Extension/LockPinViewController.designer.cs index 7bc573761..b3d5f3628 100644 --- a/src/iOS.Extension/LockPinViewController.designer.cs +++ b/src/iOS.Extension/LockPinViewController.designer.cs @@ -11,23 +11,39 @@ using UIKit; namespace Bit.iOS.Extension { - [Register ("LockPinViewController")] - partial class LockPinViewController - { - [Outlet] - [GeneratedCode ("iOS Designer", "1.0")] - UIKit.UIBarButtonItem CancelButton { get; set; } + [Register ("LockPinViewController")] + partial class LockPinViewController + { + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UIBarButtonItem CancelButton { get; set; } - [Action("CancelButton_Activated:")] - [GeneratedCode("iOS Designer", "1.0")] - partial void CancelButton_Activated(UIKit.UIBarButtonItem sender); + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UILabel PinLabel { get; set; } - void ReleaseDesignerOutlets () - { - if (CancelButton != null) { - CancelButton.Dispose (); - CancelButton = null; - } - } - } -} \ No newline at end of file + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UITextField PinTextField { get; set; } + + [Action ("CancelButton_Activated:")] + [GeneratedCode ("iOS Designer", "1.0")] + partial void CancelButton_Activated (UIBarButtonItem sender); + + void ReleaseDesignerOutlets () + { + if (CancelButton != null) { + CancelButton.Dispose (); + CancelButton = null; + } + if (PinLabel != null) { + PinLabel.Dispose (); + PinLabel = null; + } + if (PinTextField != null) { + PinTextField.Dispose (); + PinTextField = null; + } + } + } +} diff --git a/src/iOS.Extension/MainInterface.storyboard b/src/iOS.Extension/MainInterface.storyboard index e404599e4..8f8d3d4cb 100644 --- a/src/iOS.Extension/MainInterface.storyboard +++ b/src/iOS.Extension/MainInterface.storyboard @@ -40,7 +40,7 @@ @@ -57,7 +57,7 @@ - + @@ -78,7 +78,7 @@ - + @@ -203,7 +203,7 @@ - + @@ -301,7 +301,7 @@ - + @@ -365,7 +365,31 @@ - + + + + + + + + + + + + + + + + + + + @@ -376,6 +400,8 @@ + + @@ -387,7 +413,7 @@ - + @@ -430,7 +456,7 @@ - + diff --git a/src/iOS/Controls/CustomLabelRenderer.cs b/src/iOS/Controls/CustomLabelRenderer.cs index 7781b454e..b29b4fa84 100644 --- a/src/iOS/Controls/CustomLabelRenderer.cs +++ b/src/iOS/Controls/CustomLabelRenderer.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using Bit.iOS.Controls; using UIKit; using Xamarin.Forms; @@ -16,25 +17,51 @@ namespace Bit.iOS.Controls var view = e.NewElement as Label; if(Control != null && view != null) { - var descriptor = UIFontDescriptor.PreferredBody; - var pointSize = descriptor.PointSize; - - var size = view.FontSize; - if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label))) - { - pointSize *= 1.3f; - } - else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label))) - { - pointSize *= .8f; - } - else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Label))) - { - pointSize *= .6f; - } - - Control.Font = UIFont.FromDescriptor(descriptor, pointSize); + UpdateFont(); } } + + protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) + { + base.OnElementPropertyChanged(sender, e); + + if(e.PropertyName == Label.TextColorProperty.PropertyName) + { + UpdateFont(); + } + else if(e.PropertyName == Label.FontProperty.PropertyName) + { + UpdateFont(); + } + else if(e.PropertyName == Label.TextProperty.PropertyName) + { + UpdateFont(); + } + else if(e.PropertyName == Label.FormattedTextProperty.PropertyName) + { + UpdateFont(); + } + } + + private void UpdateFont() + { + var pointSize = UIFontDescriptor.PreferredBody.PointSize; + + var size = Element.FontSize; + if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label))) + { + pointSize *= 1.3f; + } + else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label))) + { + pointSize *= .8f; + } + else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Label))) + { + pointSize *= .6f; + } + + Control.Font = UIFont.FromDescriptor(Element.Font.ToUIFont().FontDescriptor, pointSize); + } } }