From 7f5d371bf339e5827c139d6026d610bc97f2bacb Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 21 Jul 2016 19:02:04 -0400 Subject: [PATCH] Moved lock logic to loading view controller. --- src/iOS.Extension/LoadingViewController.cs | 57 +++++++++++++++++-- .../LockFingerprintViewController.cs | 3 +- .../LockPasswordViewController.cs | 3 +- src/iOS.Extension/LockPinViewController.cs | 3 +- src/iOS.Extension/MainInterface.storyboard | 29 +++++----- src/iOS.Extension/SiteListViewController.cs | 34 ----------- 6 files changed, 74 insertions(+), 55 deletions(-) diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index 818914f66..e3c1070c8 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -66,7 +66,24 @@ namespace Bit.iOS.Extension public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); - PerformSegue("siteListSegue", this); + + var lockService = Resolver.Resolve(); + var lockType = lockService.GetLockType(false); + switch(lockType) + { + case App.Enums.LockType.Fingerprint: + PerformSegue("lockFingerprintSegue", this); + break; + case App.Enums.LockType.PIN: + PerformSegue("lockPinSegue", this); + break; + case App.Enums.LockType.Password: + PerformSegue("lockPasswordSegue", this); + break; + default: + PerformSegue("siteListSegue", this); + break; + } } public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) @@ -74,14 +91,46 @@ namespace Bit.iOS.Extension var navController = segue.DestinationViewController as UINavigationController; if(navController != null) { - var actionController = navController.TopViewController as SiteListViewController; - if(actionController != null) + var listSiteController = navController.TopViewController as SiteListViewController; + var addSiteController = navController.TopViewController as SiteAddViewController; + var fingerprintViewController = navController.TopViewController as LockFingerprintViewController; + var pinViewController = navController.TopViewController as LockPinViewController; + var passwordViewController = navController.TopViewController as LockPasswordViewController; + + if(listSiteController != null) { - actionController.Context = _context; + listSiteController.Context = _context; + } + else if(addSiteController != null) + { + addSiteController.Context = _context; + } + else if(fingerprintViewController != null) + { + fingerprintViewController.Context = _context; + fingerprintViewController.LoadingViewController = this; + } + else if(pinViewController != null) + { + pinViewController.Context = _context; + pinViewController.LoadingViewController = this; + } + else if(passwordViewController != null) + { + passwordViewController.Context = _context; + passwordViewController.LoadingViewController = this; } } } + public void DismissLockAndContinue() + { + DismissViewController(true, () => + { + PerformSegue("siteListSegue", this); + }); + } + private void SetIoc() { var container = new UnityContainer(); diff --git a/src/iOS.Extension/LockFingerprintViewController.cs b/src/iOS.Extension/LockFingerprintViewController.cs index 81435a83b..f433773b1 100644 --- a/src/iOS.Extension/LockFingerprintViewController.cs +++ b/src/iOS.Extension/LockFingerprintViewController.cs @@ -19,6 +19,7 @@ namespace Bit.iOS.Extension { } public Context Context { get; set; } + public LoadingViewController LoadingViewController { get; set; } public override void ViewWillAppear(bool animated) { @@ -73,7 +74,7 @@ namespace Bit.iOS.Extension var result = await _fingerprint.AuthenticateAsync("Use your fingerprint to verify."); if(result.Authenticated) { - DismissModalViewController(true); + LoadingViewController.DismissLockAndContinue(); } } } diff --git a/src/iOS.Extension/LockPasswordViewController.cs b/src/iOS.Extension/LockPasswordViewController.cs index 1369738ee..b0ddaf27f 100644 --- a/src/iOS.Extension/LockPasswordViewController.cs +++ b/src/iOS.Extension/LockPasswordViewController.cs @@ -24,6 +24,7 @@ namespace Bit.iOS.Extension { } public Context Context { get; set; } + public LoadingViewController LoadingViewController { get; set; } public FormEntryTableViewCell MasterPasswordCell { get; set; } = new FormEntryTableViewCell( AppResources.MasterPassword, useLabelAsPlaceholder: true); @@ -85,7 +86,7 @@ namespace Bit.iOS.Extension if(key.SequenceEqual(_cryptoService.Key)) { MasterPasswordCell.TextField.ResignFirstResponder(); - DismissModalViewController(true); + LoadingViewController.DismissLockAndContinue(); } else { diff --git a/src/iOS.Extension/LockPinViewController.cs b/src/iOS.Extension/LockPinViewController.cs index 7a475116e..49e3dce78 100644 --- a/src/iOS.Extension/LockPinViewController.cs +++ b/src/iOS.Extension/LockPinViewController.cs @@ -20,6 +20,7 @@ namespace Bit.iOS.Extension { } public Context Context { get; set; } + public LoadingViewController LoadingViewController { get; set; } public override void ViewWillAppear(bool animated) { @@ -58,7 +59,7 @@ namespace Bit.iOS.Extension if(PinTextField.Text == _authService.PIN) { PinTextField.ResignFirstResponder(); - DismissModalViewController(true); + LoadingViewController.DismissLockAndContinue(); } else { diff --git a/src/iOS.Extension/MainInterface.storyboard b/src/iOS.Extension/MainInterface.storyboard index 198591e0f..ee6a8738c 100644 --- a/src/iOS.Extension/MainInterface.storyboard +++ b/src/iOS.Extension/MainInterface.storyboard @@ -29,6 +29,10 @@ + + + + @@ -90,7 +94,7 @@ - + @@ -128,7 +132,7 @@ - + @@ -173,9 +177,6 @@ - - - @@ -215,7 +216,7 @@ - + @@ -276,7 +277,7 @@ - + @@ -294,7 +295,7 @@ - + @@ -309,7 +310,7 @@ - + @@ -352,7 +353,7 @@ - + @@ -407,7 +408,7 @@ - + @@ -422,7 +423,7 @@ - + @@ -437,7 +438,7 @@ - + @@ -471,7 +472,7 @@ - + diff --git a/src/iOS.Extension/SiteListViewController.cs b/src/iOS.Extension/SiteListViewController.cs index 562b4b8be..48405f3c9 100644 --- a/src/iOS.Extension/SiteListViewController.cs +++ b/src/iOS.Extension/SiteListViewController.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Bit.App.Abstractions; -using Bit.App.Models; using Bit.iOS.Core; using Bit.iOS.Extension.Models; using Foundation; @@ -32,23 +31,6 @@ namespace Bit.iOS.Extension { base.ViewDidLoad(); - var lockService = Resolver.Resolve(); - var lockType = lockService.GetLockType(false); - switch(lockType) - { - case App.Enums.LockType.Fingerprint: - PerformSegue("lockFingerprintSegue", this); - break; - case App.Enums.LockType.PIN: - PerformSegue("lockPinSegue", this); - break; - case App.Enums.LockType.Password: - PerformSegue("lockPasswordSegue", this); - break; - default: - break; - } - IEnumerable filteredSiteModels = new List(); if(Context.DomainName != null) { @@ -88,27 +70,11 @@ namespace Bit.iOS.Extension if(navController != null) { var addSiteController = navController.TopViewController as SiteAddViewController; - var fingerprintViewController = navController.TopViewController as LockFingerprintViewController; - var pinViewController = navController.TopViewController as LockPinViewController; - var passwordViewController = navController.TopViewController as LockPasswordViewController; - if(addSiteController != null) { addSiteController.Context = Context; addSiteController.Parent = this; } - else if(fingerprintViewController != null) - { - fingerprintViewController.Context = Context; - } - else if(pinViewController != null) - { - pinViewController.Context = Context; - } - else if(passwordViewController != null) - { - passwordViewController.Context = Context; - } } }