Table source and row selection.

This commit is contained in:
Kyle Spearrin 2016-06-04 18:27:34 -04:00
parent 9755d4c79b
commit 1c4de107b9
3 changed files with 112 additions and 52 deletions

View file

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using Bit.iOS.Core; using Bit.iOS.Core;
using Bit.iOS.Extension.Models; using Bit.iOS.Extension.Models;
using Foundation; using Foundation;
@ -20,6 +22,16 @@ namespace Bit.iOS.Extension
{ {
base.ViewDidLoad(); base.ViewDidLoad();
View.BackgroundColor = UIColor.FromPatternImage(new UIImage("boxed-bg.png")); 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<string> sites = new List<string>();
for(int i = 1; i <= 100; i++)
{
sites.Add("Site " + i);
}
tableView.Source = new TableSource(sites, this);
} }
partial void CancelClicked(UIBarButtonItem sender) partial void CancelClicked(UIBarButtonItem sender)
@ -27,45 +39,6 @@ namespace Bit.iOS.Extension
CompleteRequest(null); 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) private void CompleteRequest(NSDictionary itemData)
{ {
var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList); var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
@ -74,5 +47,80 @@ namespace Bit.iOS.Extension
Context.ExtContext.CompleteRequest(returningItems, null); Context.ExtContext.CompleteRequest(returningItems, null);
} }
public class TableSource : UITableViewSource
{
private const string CellIdentifier = "TableCell";
private IEnumerable<string> _tableItems;
private Context _context;
private ActionViewController _controller;
public TableSource(IEnumerable<string> 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);
}
}
} }
} }

View file

@ -14,6 +14,14 @@ namespace Bit.iOS.Extension
[Register ("ActionViewController")] [Register ("ActionViewController")]
partial class 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:")] [Action ("DoneClicked:")]
partial void DoneClicked (Foundation.NSObject sender); partial void DoneClicked (Foundation.NSObject sender);
@ -23,6 +31,14 @@ namespace Bit.iOS.Extension
void ReleaseDesignerOutlets () void ReleaseDesignerOutlets ()
{ {
if (NavItem != null) {
NavItem.Dispose ();
NavItem = null;
}
if (tableView != null) {
tableView.Dispose ();
tableView = null;
}
} }
} }
} }

View file

@ -18,7 +18,7 @@
<color key="backgroundColor" colorSpace="calibratedWhite" white="1" alpha="1"/> <color key="backgroundColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
<subviews> <subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="1717" translatesAutoresizingMaskIntoConstraints="NO"> <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="1717" translatesAutoresizingMaskIntoConstraints="NO">
<rect key="frame" x="0.0" y="72" width="600" height="506"/> <rect key="frame" x="0.0" y="64" width="600" height="536"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes> <prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="1722" rowHeight="44"> <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="1722" rowHeight="44">
@ -31,29 +31,25 @@
</view> </view>
</tableViewCell> </tableViewCell>
</prototypes> </prototypes>
<constraints>
<constraint id="1745" firstAttribute="width" constant="600"/>
<constraint id="1746" firstAttribute="height" constant="506"/>
</constraints>
</tableView> </tableView>
</subviews> </subviews>
<constraints> <constraints>
<constraint id="1743" firstItem="zMn-AG-sqS" firstAttribute="trailing" secondItem="1717" secondAttribute="trailing"/> <constraint id="1753" firstItem="1717" firstAttribute="top" secondItem="qkL-Od-lgU" secondAttribute="bottom"/>
<constraint id="1744" firstItem="zMn-AG-sqS" firstAttribute="bottom" secondItem="1717" secondAttribute="bottom" constant="22"/> <constraint id="1754" firstItem="1717" firstAttribute="leading" secondItem="zMn-AG-sqS" secondAttribute="leading"/>
<constraint id="1755" firstItem="1717" firstAttribute="trailing" secondItem="zMn-AG-sqS" secondAttribute="trailing"/>
<constraint id="1756" firstItem="1717" firstAttribute="bottom" secondItem="n38-gi-rB5" secondAttribute="top"/>
</constraints> </constraints>
</view> </view>
<navigationItem key="navigationItem" id="yHH-Ee-etX" title="Sites"> <navigationItem key="navigationItem" id="yHH-Ee-etX" title="Sites">
<barButtonItem key="leftBarButtonItem" title="Done" style="done" id="WYi-yp-eM6"> <barButtonItem title="Cancel" id="1714" translatesAutoresizingMaskIntoConstraints="NO" key="leftBarButtonItem">
<connections>
<action selector="DoneClicked:" destination="ObA-dk-sSI" id="eDL-XE-zg5"/>
</connections>
</barButtonItem>
<barButtonItem title="Cancel" id="1714" translatesAutoresizingMaskIntoConstraints="NO" key="rightBarButtonItem">
<connections> <connections>
<action selector="CancelClicked:" destination="ObA-dk-sSI" id="1729"/> <action selector="CancelClicked:" destination="ObA-dk-sSI" id="1729"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
</navigationItem> </navigationItem>
<connections>
<outlet property="tableView" destination="1717" id="name-outlet-1717"/>
</connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="X47-rx-isc" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="X47-rx-isc" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>