From c206d228fc0c4cbc2f10066b146825fed436aadb Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 21 Jul 2016 23:41:50 -0400 Subject: [PATCH] Fixed locked setting bug. Added no site list message to extension. --- src/App/Pages/Lock/LockFingerprintPage.cs | 1 + src/App/Pages/Lock/LockPasswordPage.cs | 4 +++ src/App/Pages/Lock/LockPinPage.cs | 1 + .../LockFingerprintViewController.cs | 2 ++ .../LockPasswordViewController.cs | 2 ++ src/iOS.Extension/LockPinViewController.cs | 2 ++ src/iOS.Extension/SiteAddViewController.cs | 5 +-- src/iOS.Extension/SiteListViewController.cs | 31 ++++++++++++++++--- 8 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/App/Pages/Lock/LockFingerprintPage.cs b/src/App/Pages/Lock/LockFingerprintPage.cs index f5fecff72..836847c6a 100644 --- a/src/App/Pages/Lock/LockFingerprintPage.cs +++ b/src/App/Pages/Lock/LockFingerprintPage.cs @@ -85,6 +85,7 @@ namespace Bit.App.Pages var result = await _fingerprint.AuthenticateAsync("Use your fingerprint to verify."); if(result.Authenticated) { + _settings.AddOrUpdateValue(Constants.SettingLocked, false); await Navigation.PopModalAsync(); } } diff --git a/src/App/Pages/Lock/LockPasswordPage.cs b/src/App/Pages/Lock/LockPasswordPage.cs index 88809241d..7a9a9488d 100644 --- a/src/App/Pages/Lock/LockPasswordPage.cs +++ b/src/App/Pages/Lock/LockPasswordPage.cs @@ -7,12 +7,14 @@ using Xamarin.Forms; using XLabs.Ioc; using Bit.App.Controls; using System.Linq; +using Plugin.Settings.Abstractions; namespace Bit.App.Pages { public class LockPasswordPage : ExtendedContentPage { private readonly IAuthService _authService; + private readonly ISettings _settings; private readonly IUserDialogs _userDialogs; private readonly ICryptoService _cryptoService; @@ -20,6 +22,7 @@ namespace Bit.App.Pages : base(false) { _authService = Resolver.Resolve(); + _settings = Resolver.Resolve(); _userDialogs = Resolver.Resolve(); _cryptoService = Resolver.Resolve(); @@ -104,6 +107,7 @@ namespace Bit.App.Pages var key = _cryptoService.MakeKeyFromPassword(PasswordCell.Entry.Text, _authService.Email); if(key.SequenceEqual(_cryptoService.Key)) { + _settings.AddOrUpdateValue(Constants.SettingLocked, false); await Navigation.PopModalAsync(); } else diff --git a/src/App/Pages/Lock/LockPinPage.cs b/src/App/Pages/Lock/LockPinPage.cs index 049a2782e..05fd9de1f 100644 --- a/src/App/Pages/Lock/LockPinPage.cs +++ b/src/App/Pages/Lock/LockPinPage.cs @@ -82,6 +82,7 @@ namespace Bit.App.Pages { if(Model.PIN == _authService.PIN) { + _settings.AddOrUpdateValue(Constants.SettingLocked, false); PinControl.Entry.Unfocus(); Navigation.PopModalAsync(); } diff --git a/src/iOS.Extension/LockFingerprintViewController.cs b/src/iOS.Extension/LockFingerprintViewController.cs index f433773b1..f89dcc70b 100644 --- a/src/iOS.Extension/LockFingerprintViewController.cs +++ b/src/iOS.Extension/LockFingerprintViewController.cs @@ -7,6 +7,7 @@ using Foundation; using MobileCoreServices; using Plugin.Fingerprint.Abstractions; using System.Threading.Tasks; +using Bit.App; namespace Bit.iOS.Extension { @@ -74,6 +75,7 @@ namespace Bit.iOS.Extension var result = await _fingerprint.AuthenticateAsync("Use your fingerprint to verify."); if(result.Authenticated) { + _settings.AddOrUpdateValue(Constants.SettingLocked, false); LoadingViewController.DismissLockAndContinue(); } } diff --git a/src/iOS.Extension/LockPasswordViewController.cs b/src/iOS.Extension/LockPasswordViewController.cs index b0ddaf27f..211b8fb07 100644 --- a/src/iOS.Extension/LockPasswordViewController.cs +++ b/src/iOS.Extension/LockPasswordViewController.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Bit.iOS.Core.Utilities; using Bit.App.Abstractions; using System.Linq; +using Bit.App; namespace Bit.iOS.Extension { @@ -85,6 +86,7 @@ namespace Bit.iOS.Extension var key = _cryptoService.MakeKeyFromPassword(MasterPasswordCell.TextField.Text, _authService.Email); if(key.SequenceEqual(_cryptoService.Key)) { + _settings.AddOrUpdateValue(Constants.SettingLocked, false); MasterPasswordCell.TextField.ResignFirstResponder(); LoadingViewController.DismissLockAndContinue(); } diff --git a/src/iOS.Extension/LockPinViewController.cs b/src/iOS.Extension/LockPinViewController.cs index 595555b23..bdc4515a6 100644 --- a/src/iOS.Extension/LockPinViewController.cs +++ b/src/iOS.Extension/LockPinViewController.cs @@ -9,6 +9,7 @@ using Bit.App.Abstractions; using Bit.iOS.Core.Utilities; using Bit.App.Resources; using System.Diagnostics; +using Bit.App; namespace Bit.iOS.Extension { @@ -60,6 +61,7 @@ namespace Bit.iOS.Extension if(PinTextField.Text == _authService.PIN) { Debug.WriteLine("BW Log, Start Dismiss PIN controller."); + _settings.AddOrUpdateValue(Constants.SettingLocked, false); PinTextField.ResignFirstResponder(); LoadingViewController.DismissLockAndContinue(); } diff --git a/src/iOS.Extension/SiteAddViewController.cs b/src/iOS.Extension/SiteAddViewController.cs index 02c347d6f..866552135 100644 --- a/src/iOS.Extension/SiteAddViewController.cs +++ b/src/iOS.Extension/SiteAddViewController.cs @@ -153,10 +153,7 @@ namespace Bit.iOS.Extension var loadingAlert = Dialogs.CreateLoadingAlert("Saving..."); PresentViewController(loadingAlert, true, null); await saveTask; - DismissViewController(false, () => - { - Parent.DismissModal(); - }); + Parent.DismissModal(); } public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) diff --git a/src/iOS.Extension/SiteListViewController.cs b/src/iOS.Extension/SiteListViewController.cs index 5a2b1fc7e..afc0258ab 100644 --- a/src/iOS.Extension/SiteListViewController.cs +++ b/src/iOS.Extension/SiteListViewController.cs @@ -10,6 +10,7 @@ using MobileCoreServices; using Newtonsoft.Json; using UIKit; using XLabs.Ioc; +using Plugin.Settings.Abstractions; namespace Bit.iOS.Extension { @@ -88,8 +89,10 @@ namespace Bit.iOS.Extension public void DismissModal() { - DismissModalViewController(true); - TableView.ReloadData(); + DismissViewController(true, () => + { + TableView.ReloadData(); + }); } public class TableSource : UITableViewSource @@ -109,16 +112,27 @@ namespace Bit.iOS.Extension public override nint RowsInSection(UITableView tableview, nint section) { - return _tableItems.Count(); + return _tableItems.Count() == 0 ? 1 : _tableItems.Count(); } public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { + if(_tableItems.Count() == 0) + { + var noDataCell = new UITableViewCell(UITableViewCellStyle.Default, "NoDataCell"); + noDataCell.TextLabel.Text = "There are no sites in your vault for this website. Tap to add one."; + noDataCell.TextLabel.TextAlignment = UITextAlignment.Center; + noDataCell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap; + noDataCell.TextLabel.Lines = 0; + return noDataCell; + } + var cell = tableView.DequeueReusableCell(CellIdentifier); // if there are no cells to reuse, create a new one if(cell == null) { + Debug.WriteLine("BW Log, Make new cell for list."); cell = new UITableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier); } return cell; @@ -126,7 +140,7 @@ namespace Bit.iOS.Extension public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath) { - if(cell == null) + if(_tableItems.Count() == 0 || cell == null) { return; } @@ -139,10 +153,19 @@ namespace Bit.iOS.Extension public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { + if(_tableItems.Count() == 0) + { + _controller.PerformSegue("siteAddSegue", this); + return; + } + + Resolver.Resolve().AddOrUpdateValue(Bit.App.Constants.SettingLastBackgroundedDate, DateTime.UtcNow); + var item = _tableItems.ElementAt(indexPath.Row); if(item == null) { _controller.CompleteRequest(null); + return; } NSDictionary itemData = null;