From 98335c6acb9e782e9e8dc0ca0a25b63dfdc581ee Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 20 Jul 2016 23:51:31 -0400 Subject: [PATCH] clear value after invalid pin --- src/iOS.Core/Utilities/Dialogs.cs | 4 ++-- src/iOS.Extension/LockPinViewController.cs | 28 ++++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/iOS.Core/Utilities/Dialogs.cs b/src/iOS.Core/Utilities/Dialogs.cs index a5cffccb0..344c94fb6 100644 --- a/src/iOS.Core/Utilities/Dialogs.cs +++ b/src/iOS.Core/Utilities/Dialogs.cs @@ -27,12 +27,12 @@ namespace Bit.iOS.Core.Utilities return alert; } - public static UIAlertController CreateAlert(string title, string message, string accept) + public static UIAlertController CreateAlert(string title, string message, string accept, Action acceptHandle = null) { var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert); var oldFrame = alert.View.Frame; alert.View.Frame = new RectangleF((float)oldFrame.X, (float)oldFrame.Y, (float)oldFrame.Width, (float)oldFrame.Height - 20); - alert.AddAction(UIAlertAction.Create(accept, UIAlertActionStyle.Default, null)); + alert.AddAction(UIAlertAction.Create(accept, UIAlertActionStyle.Default, acceptHandle)); return alert; } } diff --git a/src/iOS.Extension/LockPinViewController.cs b/src/iOS.Extension/LockPinViewController.cs index 0373bbbd7..7a475116e 100644 --- a/src/iOS.Extension/LockPinViewController.cs +++ b/src/iOS.Extension/LockPinViewController.cs @@ -51,13 +51,7 @@ namespace Bit.iOS.Extension private void PinTextField_EditingChanged(object sender, EventArgs e) { - var newText = string.Empty; - for(int i = 0; i < 4; i++) - { - newText += PinTextField.Text.Length <= i ? "- " : "● "; - } - - PinLabel.Text = newText.TrimEnd(); + SetLabelText(); if(PinTextField.Text.Length >= 4) { @@ -70,14 +64,28 @@ namespace Bit.iOS.Extension { // TODO: keep track of invalid attempts and logout? - var alert = Dialogs.CreateAlert(null, "Invalid PIN. Try again.", AppResources.Ok); + var alert = Dialogs.CreateAlert(null, "Invalid PIN. Try again.", AppResources.Ok, (a) => + { + PinTextField.Text = string.Empty; + SetLabelText(); + PinTextField.BecomeFirstResponder(); + }); PresentViewController(alert, true, null); - PinTextField.Text = string.Empty; - PinTextField.BecomeFirstResponder(); } } } + private void SetLabelText() + { + var newText = string.Empty; + for(int i = 0; i < 4; i++) + { + newText += PinTextField.Text.Length <= i ? "- " : "● "; + } + + PinLabel.Text = newText.TrimEnd(); + } + partial void CancelButton_Activated(UIBarButtonItem sender) { CompleteRequest();