From ae79eb6a9645adab7302f0b9bd95d3c36622d282 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 12 Jul 2016 23:55:52 -0400 Subject: [PATCH] select focus inputs in table cells. load folders into picker cell. --- src/iOS.Core/Views/FormEntryTableViewCell.cs | 14 +++++++- src/iOS.Core/Views/ISelectable.cs | 7 ++++ src/iOS.Core/Views/PickerTableViewCell.cs | 15 +++----- src/iOS.Core/iOS.Core.csproj | 1 + src/iOS.Extension/SiteAddViewController.cs | 36 ++++++++++++++++++-- 5 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 src/iOS.Core/Views/ISelectable.cs diff --git a/src/iOS.Core/Views/FormEntryTableViewCell.cs b/src/iOS.Core/Views/FormEntryTableViewCell.cs index 5eea6a6c7..44c3e6105 100644 --- a/src/iOS.Core/Views/FormEntryTableViewCell.cs +++ b/src/iOS.Core/Views/FormEntryTableViewCell.cs @@ -3,7 +3,7 @@ using UIKit; namespace Bit.iOS.Core.Views { - public class FormEntryTableViewCell : UITableViewCell + public class FormEntryTableViewCell : UITableViewCell, ISelectable { public FormEntryTableViewCell( string labelName = null, @@ -107,5 +107,17 @@ namespace Bit.iOS.Core.Views public UILabel Label { get; set; } public UITextField TextField { get; set; } public UITextView TextView { get; set; } + + public void Select() + { + if(TextView != null) + { + TextView.BecomeFirstResponder(); + } + else if(TextField != null) + { + TextField.BecomeFirstResponder(); + } + } } } diff --git a/src/iOS.Core/Views/ISelectable.cs b/src/iOS.Core/Views/ISelectable.cs new file mode 100644 index 000000000..463d783fd --- /dev/null +++ b/src/iOS.Core/Views/ISelectable.cs @@ -0,0 +1,7 @@ +namespace Bit.iOS.Core.Views +{ + public interface ISelectable + { + void Select(); + } +} diff --git a/src/iOS.Core/Views/PickerTableViewCell.cs b/src/iOS.Core/Views/PickerTableViewCell.cs index c4f72fd3e..84094b752 100644 --- a/src/iOS.Core/Views/PickerTableViewCell.cs +++ b/src/iOS.Core/Views/PickerTableViewCell.cs @@ -6,10 +6,10 @@ using UIKit; namespace Bit.iOS.Core.Views { - public class PickerTableViewCell : UITableViewCell + public class PickerTableViewCell : UITableViewCell, ISelectable { private List _items = new List(); - private int _selectedIndex = -1; + private int _selectedIndex = 0; public PickerTableViewCell( string labelName, @@ -35,8 +35,6 @@ namespace Bit.iOS.Core.Views TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.FromDescriptor(descriptor, pointSize) }; - TextField.Started += Entry_Started; - TextField.Ended += Entry_Ended; var width = (float)UIScreen.MainScreen.Bounds.Width; var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44)) @@ -134,14 +132,9 @@ namespace Bit.iOS.Core.Views Picker.Select(Math.Max(formsIndex, 0), 0, true); } - private void Entry_Ended(object sender, EventArgs e) + public void Select() { - //throw new NotImplementedException(); - } - - private void Entry_Started(object sender, EventArgs e) - { - //throw new NotImplementedException(); + TextField?.BecomeFirstResponder(); } private class NoCaretField : UITextField diff --git a/src/iOS.Core/iOS.Core.csproj b/src/iOS.Core/iOS.Core.csproj index cbb3f77a8..9a237ba2c 100644 --- a/src/iOS.Core/iOS.Core.csproj +++ b/src/iOS.Core/iOS.Core.csproj @@ -68,6 +68,7 @@ + diff --git a/src/iOS.Extension/SiteAddViewController.cs b/src/iOS.Extension/SiteAddViewController.cs index c0bc19d8c..ee7f371e6 100644 --- a/src/iOS.Extension/SiteAddViewController.cs +++ b/src/iOS.Extension/SiteAddViewController.cs @@ -19,7 +19,9 @@ namespace Bit.iOS.Extension public partial class SiteAddViewController : UITableViewController { private ISiteService _siteService; + private IFolderService _folderService; private IConnectivity _connectivity; + private IEnumerable _folders; public SiteAddViewController(IntPtr handle) : base(handle) { } @@ -46,6 +48,7 @@ namespace Bit.iOS.Extension { _siteService = Resolver.Resolve(); _connectivity = Resolver.Resolve(); + _folderService = Resolver.Resolve(); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); @@ -88,12 +91,15 @@ namespace Bit.iOS.Extension GeneratePasswordCell.TextLabel.Text = "Generate Password"; GeneratePasswordCell.Accessory = UITableViewCellAccessory.DisclosureIndicator; - FolderCell.Items = new List { "Folder 1", "Folder 2" }; - FolderCell.SelectedIndex = 1; + _folders = _folderService.GetAllAsync().GetAwaiter().GetResult(); + var folderNames = _folders.Select(s => s.Name.Decrypt()).OrderBy(s => s).ToList(); + folderNames.Insert(0, AppResources.FolderNone); + FolderCell.Items = folderNames; TableView.RowHeight = UITableView.AutomaticDimension; TableView.EstimatedRowHeight = 70; TableView.Source = new TableSource(this); + TableView.AllowsSelection = true; base.ViewDidLoad(); } @@ -139,7 +145,8 @@ namespace Bit.iOS.Extension Username = string.IsNullOrWhiteSpace(UsernameCell.TextField.Text) ? null : UsernameCell.TextField.Text.Encrypt(), Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ? null : PasswordCell.TextField.Text.Encrypt(), Notes = string.IsNullOrWhiteSpace(NotesCell.TextView.Text) ? null : NotesCell.TextView.Text.Encrypt(), - Favorite = FavoriteCell.Switch.On + Favorite = FavoriteCell.Switch.On, + FolderId = FolderCell.SelectedIndex == 0 ? null : _folders.ElementAtOrDefault(FolderCell.SelectedIndex - 1)?.Id }; var saveTask = _siteService.SaveAsync(site); @@ -260,6 +267,29 @@ namespace Bit.iOS.Extension return null; } + + public override void RowSelected(UITableView tableView, NSIndexPath indexPath) + { + tableView.DeselectRow(indexPath, true); + tableView.EndEditing(true); + + if(indexPath.Section == 0 && indexPath.Row == 4) + { + // Generate password selected + } + + var cell = tableView.CellAt(indexPath); + if(cell == null) + { + return; + } + + var selectableCell = cell as ISelectable; + if(selectableCell != null) + { + selectableCell.Select(); + } + } } } }