From 1c4de107b9e1796bace38d73fd72d4f7513132cc Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 4 Jun 2016 18:27:34 -0400 Subject: [PATCH] Table source and row selection. --- src/iOS.Extension/ActionViewController.cs | 126 ++++++++++++------ .../ActionViewController.designer.cs | 16 +++ src/iOS.Extension/MainInterface.storyboard | 22 ++- 3 files changed, 112 insertions(+), 52 deletions(-) diff --git a/src/iOS.Extension/ActionViewController.cs b/src/iOS.Extension/ActionViewController.cs index 4f0a46727..cbe5fe59b 100644 --- a/src/iOS.Extension/ActionViewController.cs +++ b/src/iOS.Extension/ActionViewController.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using Bit.iOS.Core; using Bit.iOS.Extension.Models; using Foundation; @@ -20,6 +22,16 @@ namespace Bit.iOS.Extension { base.ViewDidLoad(); View.BackgroundColor = UIColor.FromPatternImage(new UIImage("boxed-bg.png")); + NavigationController.NavigationBar.TintColor = UIColor.White; + NavigationController.NavigationBar.BarTintColor = new UIColor(0.24f, 0.55f, 0.74f, 1.0f); + + List sites = new List(); + for(int i = 1; i <= 100; i++) + { + sites.Add("Site " + i); + } + + tableView.Source = new TableSource(sites, this); } partial void CancelClicked(UIBarButtonItem sender) @@ -27,45 +39,6 @@ namespace Bit.iOS.Extension CompleteRequest(null); } - partial void DoneClicked(NSObject sender) - { - NSDictionary itemData = null; - if(Context.ProviderType == UTType.PropertyList) - { - var fillScript = new FillScript(Context.Details); - var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); - var scriptDict = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson); - itemData = new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, scriptDict); - } - if(Context.ProviderType == Constants.UTTypeAppExtensionFindLoginAction) - { - itemData = new NSDictionary( - Constants.AppExtensionUsernameKey, "me@example.com", - Constants.AppExtensionPasswordKey, "mypassword"); - } - else if(Context.ProviderType == Constants.UTTypeAppExtensionFillBrowserAction - || Context.ProviderType == Constants.UTTypeAppExtensionFillWebViewAction) - { - var fillScript = new FillScript(Context.Details); - var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); - itemData = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson); - } - else if(Context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction) - { - itemData = new NSDictionary( - Constants.AppExtensionUsernameKey, "me@example.com", - Constants.AppExtensionPasswordKey, "mypassword"); - } - else if(Context.ProviderType == Constants.UTTypeAppExtensionChangePasswordAction) - { - itemData = new NSDictionary( - Constants.AppExtensionPasswordKey, "mynewpassword", - Constants.AppExtensionOldPasswordKey, "myoldpassword"); - } - - CompleteRequest(itemData); - } - private void CompleteRequest(NSDictionary itemData) { var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList); @@ -74,5 +47,80 @@ namespace Bit.iOS.Extension Context.ExtContext.CompleteRequest(returningItems, null); } + + public class TableSource : UITableViewSource + { + private const string CellIdentifier = "TableCell"; + + private IEnumerable _tableItems; + private Context _context; + private ActionViewController _controller; + + public TableSource(IEnumerable items, ActionViewController controller) + { + _tableItems = items; + _context = controller.Context; + _controller = controller; + } + + public override nint RowsInSection(UITableView tableview, nint section) + { + return _tableItems.Count(); + } + + public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) + { + var cell = tableView.DequeueReusableCell(CellIdentifier); + var item = _tableItems.ElementAt(indexPath.Row); + + // if there are no cells to reuse, create a new one + if(cell == null) + { + cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier); + } + + cell.TextLabel.Text = item; + return cell; + } + + public override void RowSelected(UITableView tableView, NSIndexPath indexPath) + { + NSDictionary itemData = null; + if(_context.ProviderType == UTType.PropertyList) + { + var fillScript = new FillScript(_context.Details); + var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + var scriptDict = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson); + itemData = new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, scriptDict); + } + else if(_context.ProviderType == Constants.UTTypeAppExtensionFindLoginAction) + { + itemData = new NSDictionary( + Constants.AppExtensionUsernameKey, "me@example.com", + Constants.AppExtensionPasswordKey, "mypassword"); + } + else if(_context.ProviderType == Constants.UTTypeAppExtensionFillBrowserAction + || _context.ProviderType == Constants.UTTypeAppExtensionFillWebViewAction) + { + var fillScript = new FillScript(_context.Details); + var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + itemData = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson); + } + else if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction) + { + itemData = new NSDictionary( + Constants.AppExtensionUsernameKey, "me@example.com", + Constants.AppExtensionPasswordKey, "mypassword"); + } + else if(_context.ProviderType == Constants.UTTypeAppExtensionChangePasswordAction) + { + itemData = new NSDictionary( + Constants.AppExtensionPasswordKey, "mynewpassword", + Constants.AppExtensionOldPasswordKey, "myoldpassword"); + } + + _controller.CompleteRequest(itemData); + } + } } } diff --git a/src/iOS.Extension/ActionViewController.designer.cs b/src/iOS.Extension/ActionViewController.designer.cs index 7fc2e6450..85385a2e2 100644 --- a/src/iOS.Extension/ActionViewController.designer.cs +++ b/src/iOS.Extension/ActionViewController.designer.cs @@ -14,6 +14,14 @@ namespace Bit.iOS.Extension [Register ("ActionViewController")] partial class ActionViewController { + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UINavigationItem NavItem { get; set; } + + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UITableView tableView { get; set; } + [Action ("DoneClicked:")] partial void DoneClicked (Foundation.NSObject sender); @@ -23,6 +31,14 @@ namespace Bit.iOS.Extension void ReleaseDesignerOutlets () { + if (NavItem != null) { + NavItem.Dispose (); + NavItem = null; + } + if (tableView != null) { + tableView.Dispose (); + tableView = null; + } } } } diff --git a/src/iOS.Extension/MainInterface.storyboard b/src/iOS.Extension/MainInterface.storyboard index a67b63df7..04206fe30 100644 --- a/src/iOS.Extension/MainInterface.storyboard +++ b/src/iOS.Extension/MainInterface.storyboard @@ -18,7 +18,7 @@ - + @@ -31,29 +31,25 @@ - - - - - - + + + + - - - - - - + + + +