diff --git a/src/App/App.cs b/src/App/App.cs index 86e232256..9e326c0d9 100644 --- a/src/App/App.cs +++ b/src/App/App.cs @@ -77,10 +77,10 @@ namespace Bit.App CheckLockAsync(false); } - var lockPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage; - if(lockPage != null) + var lockPinPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage; + if(lockPinPage != null) { - lockPage.PinControl.Entry.Focus(); + lockPinPage.PinControl.Entry.Focus(); } } diff --git a/src/App/Controls/PinControl.cs b/src/App/Controls/PinControl.cs index 68060bae5..78b0708e5 100644 --- a/src/App/Controls/PinControl.cs +++ b/src/App/Controls/PinControl.cs @@ -1,5 +1,4 @@ using System; -using Bit.App.Models.Page; using Xamarin.Forms; namespace Bit.App.Controls @@ -7,10 +6,12 @@ namespace Bit.App.Controls public class PinControl { private Action _pinEnteredAction; + private Action _confirmPinEnteredAction; - public PinControl(Action pinEnteredAction) + public PinControl(Action pinEnteredAction, Action confirmPinEnteredAction = null) { _pinEnteredAction = pinEnteredAction; + _confirmPinEnteredAction = confirmPinEnteredAction; Label = new Label { @@ -19,7 +20,6 @@ namespace Bit.App.Controls TextColor = Color.FromHex("333333"), FontFamily = "Courier" }; - Label.SetBinding(Label.TextProperty, s => s.LabelText); Entry = new ExtendedEntry { @@ -27,19 +27,35 @@ namespace Bit.App.Controls MaxLength = 4, Margin = new Thickness(0, int.MaxValue, 0, 0) }; - Entry.SetBinding(Xamarin.Forms.Entry.TextProperty, s => s.PIN); - Entry.TextChanged += PinEntry_TextChanged; + Entry.TextChanged += Entry_TextChanged; + + ConfirmEntry = new ExtendedEntry + { + Keyboard = Keyboard.Numeric, + MaxLength = 4, + Margin = new Thickness(0, int.MaxValue, 0, 0) + }; + Entry.TextChanged += ConfirmEntry_TextChanged; } - private void PinEntry_TextChanged(object sender, TextChangedEventArgs e) + private void Entry_TextChanged(object sender, TextChangedEventArgs e) { - if(e.NewTextValue.Length >= 4) + if(e.NewTextValue.Length >= 4 && _pinEnteredAction != null) { _pinEnteredAction(); } } + private void ConfirmEntry_TextChanged(object sender, TextChangedEventArgs e) + { + if(e.NewTextValue.Length >= 4 && _confirmPinEnteredAction != null) + { + _confirmPinEnteredAction(); + } + } + public Label Label { get; set; } public ExtendedEntry Entry { get; set; } + public ExtendedEntry ConfirmEntry { get; set; } } } diff --git a/src/App/Models/Page/PinPageModel.cs b/src/App/Models/Page/PinPageModel.cs index e04e59755..933167d0f 100644 --- a/src/App/Models/Page/PinPageModel.cs +++ b/src/App/Models/Page/PinPageModel.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; +using System.ComponentModel; namespace Bit.App.Models.Page { diff --git a/src/App/Pages/LockPinPage.cs b/src/App/Pages/LockPinPage.cs index 706887716..5b4cdcf51 100644 --- a/src/App/Pages/LockPinPage.cs +++ b/src/App/Pages/LockPinPage.cs @@ -6,10 +6,8 @@ using Bit.App.Resources; using Xamarin.Forms; using XLabs.Ioc; using Plugin.Settings.Abstractions; -using System.Collections.Generic; using Bit.App.Models.Page; using Bit.App.Controls; -using System.Diagnostics; namespace Bit.App.Pages { @@ -34,6 +32,8 @@ namespace Bit.App.Pages public void Init() { PinControl = new PinControl(PinEntered); + PinControl.Label.SetBinding(Label.TextProperty, s => s.LabelText); + PinControl.Entry.SetBinding(Entry.TextProperty, s => s.PIN); var logoutButton = new Button { @@ -49,11 +49,19 @@ namespace Bit.App.Pages Children = { PinControl.Label, logoutButton, PinControl.Entry } }; + var tgr = new TapGestureRecognizer(); + tgr.Tapped += Tgr_Tapped; + Title = "Verify PIN"; Content = stackLayout; + Content.GestureRecognizers.Add(tgr); BindingContext = Model; } + private void Tgr_Tapped(object sender, EventArgs e) + { + PinControl.Entry.Focus(); + } protected override bool OnBackButtonPressed() { @@ -75,6 +83,8 @@ namespace Bit.App.Pages } else { + // TODO: keep track of invalid attempts and logout? + _userDialogs.Alert("Invalid PIN. Try again."); Model.PIN = string.Empty; PinControl.Entry.Focus();