Assigning context to add site cells

This commit is contained in:
Kyle Spearrin 2016-07-08 00:35:48 -04:00
parent ecb7e9921d
commit 3291a0d78d
5 changed files with 141 additions and 92 deletions

View file

@ -33,14 +33,13 @@ namespace Bit.iOS.Extension
{ {
base.ViewDidLoad(); base.ViewDidLoad();
IEnumerable<SiteViewModel> filteredSiteModels = new List< SiteViewModel>(); IEnumerable<SiteViewModel> filteredSiteModels = new List<SiteViewModel>();
DomainName domain; if(Context.DomainName != null)
if(Context.Url?.Host != null && DomainName.TryParse(Context.Url?.Host, out domain))
{ {
var siteService = Resolver.Resolve<ISiteService>(); var siteService = Resolver.Resolve<ISiteService>();
var sites = await siteService.GetAllAsync(); var sites = await siteService.GetAllAsync();
var siteModels = sites.Select(s => new SiteViewModel(s)); var siteModels = sites.Select(s => new SiteViewModel(s));
filteredSiteModels = siteModels.Where(s => s.Domain != null && s.Domain.BaseDomain == domain.BaseDomain); filteredSiteModels = siteModels.Where(s => s.Domain != null && s.Domain.BaseDomain == Context.DomainName.BaseDomain);
} }
tableView.RowHeight = UITableView.AutomaticDimension; tableView.RowHeight = UITableView.AutomaticDimension;

View file

@ -31,6 +31,11 @@ namespace Bit.iOS.Extension
public override void ViewDidLoad() public override void ViewDidLoad()
{ {
View.BackgroundColor = new UIColor(red: 0.93f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
nameField.Text = Context.Url.Host;
uriField.Text = Context.Url.ToString();
tableView.RowHeight = UITableView.AutomaticDimension; tableView.RowHeight = UITableView.AutomaticDimension;
tableView.EstimatedRowHeight = 44; tableView.EstimatedRowHeight = 44;
tableView.Source = new TableSource (this); tableView.Source = new TableSource (this);
@ -38,6 +43,12 @@ namespace Bit.iOS.Extension
base.ViewDidLoad(); base.ViewDidLoad();
} }
public override void ViewDidAppear(bool animated)
{
usernameCell.BecomeFirstResponder();
base.ViewDidAppear(animated);
}
partial void UIBarButtonItem2289_Activated(UIBarButtonItem sender) partial void UIBarButtonItem2289_Activated(UIBarButtonItem sender)
{ {
DismissViewController(true, null); DismissViewController(true, null);

View file

@ -11,92 +11,107 @@ using UIKit;
namespace Bit.iOS.Extension namespace Bit.iOS.Extension
{ {
[Register ("AddSiteViewController")] [Register ("AddSiteViewController")]
partial class AddSiteViewController partial class AddSiteViewController
{ {
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableViewCell generatePasswordCell { get; set; } UITableViewCell generatePasswordCell { get; set; }
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableViewCell nameCell { get; set; } UITableViewCell nameCell { get; set; }
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITextField nameField { get; set; } UITextField nameField { get; set; }
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UILabel nameLabel { get; set; } UILabel nameLabel { get; set; }
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableViewCell passwordCell { get; set; } UITableViewCell passwordCell { get; set; }
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableView tableView { get; set; } UITextField passwordField { get; set; }
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableViewCell uriCell { get; set; } UITableView tableView { get; set; }
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UITableViewCell usernameCell { get; set; } UITableViewCell uriCell { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField uriField { get; set; }
[Action ("UIBarButtonItem2289_Activated:")] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
partial void UIBarButtonItem2289_Activated (UIBarButtonItem sender); UITableViewCell usernameCell { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField usernameField { get; set; }
[Action ("UIBarButtonItem2290_Activated:")] [Action ("UIBarButtonItem2289_Activated:")]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
partial void UIBarButtonItem2290_Activated (UIBarButtonItem sender); partial void UIBarButtonItem2289_Activated (UIBarButtonItem sender);
void ReleaseDesignerOutlets () [Action ("UIBarButtonItem2290_Activated:")]
{ [GeneratedCode ("iOS Designer", "1.0")]
if (generatePasswordCell != null) { partial void UIBarButtonItem2290_Activated (UIBarButtonItem sender);
generatePasswordCell.Dispose ();
generatePasswordCell = null;
}
if (nameCell != null) { void ReleaseDesignerOutlets ()
nameCell.Dispose (); {
nameCell = null; if (generatePasswordCell != null) {
} generatePasswordCell.Dispose ();
generatePasswordCell = null;
if (nameField != null) { }
nameField.Dispose (); if (nameCell != null) {
nameField = null; nameCell.Dispose ();
} nameCell = null;
}
if (nameLabel != null) { if (nameField != null) {
nameLabel.Dispose (); nameField.Dispose ();
nameLabel = null; nameField = null;
} }
if (nameLabel != null) {
if (passwordCell != null) { nameLabel.Dispose ();
passwordCell.Dispose (); nameLabel = null;
passwordCell = null; }
} if (passwordCell != null) {
passwordCell.Dispose ();
if (tableView != null) { passwordCell = null;
tableView.Dispose (); }
tableView = null; if (passwordField != null) {
} passwordField.Dispose ();
passwordField = null;
if (uriCell != null) { }
uriCell.Dispose (); if (tableView != null) {
uriCell = null; tableView.Dispose ();
} tableView = null;
}
if (usernameCell != null) { if (uriCell != null) {
usernameCell.Dispose (); uriCell.Dispose ();
usernameCell = null; uriCell = null;
} }
} if (uriField != null) {
} uriField.Dispose ();
uriField = null;
}
if (usernameCell != null) {
usernameCell.Dispose ();
usernameCell = null;
}
if (usernameField != null) {
usernameField.Dispose ();
usernameField = null;
}
}
}
} }

View file

@ -137,7 +137,7 @@
<objects> <objects>
<navigationController definesPresentationContext="YES" id="64" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="64" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="67" translucent="NO" hidden="YES"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="67" translucent="NO" hidden="YES">
<rect key="frame" x="0.0" y="20" width="600" height="44"/> <rect key="frame" x="0.0" y="20" width="880" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
</navigationBar> </navigationBar>
<connections> <connections>
@ -154,7 +154,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="oCZ-GQ-aOK" sceneMemberID="viewController"> <navigationController automaticallyAdjustsScrollViewInsets="NO" id="oCZ-GQ-aOK" sceneMemberID="viewController">
<toolbarItems/> <toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="8A5-AR-QHS" translucent="NO"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="8A5-AR-QHS" translucent="NO">
<rect key="frame" x="0.0" y="20" width="600" height="44"/> <rect key="frame" x="0.0" y="20" width="880" height="44"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<textAttributes key="titleTextAttributes"> <textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/> <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
@ -175,7 +175,7 @@
<navigationController definesPresentationContext="YES" id="1845" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="1845" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="1848" translucent="NO"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="1848" translucent="NO">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<rect key="frame" x="0.0" y="20" width="600" height="44"/> <rect key="frame" x="0.0" y="20" width="880" height="44"/>
<textAttributes key="titleTextAttributes"> <textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/> <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
</textAttributes> </textAttributes>
@ -192,7 +192,7 @@
<scene sceneID="2086"> <scene sceneID="2086">
<objects> <objects>
<tableViewController id="2087" sceneMemberID="viewController" customClass="AddSiteViewController"> <tableViewController id="2087" sceneMemberID="viewController" customClass="AddSiteViewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" rowHeight="50" sectionHeaderHeight="22" sectionFooterHeight="22" id="2088" opaque="NO"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" rowHeight="50" sectionHeaderHeight="22" sectionFooterHeight="22" id="2088" opaque="NO" allowsSelection="NO">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@ -210,14 +210,14 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/> <rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Name" lineBreakMode="tailTruncation" minimumFontSize="10" id="2316" translatesAutoresizingMaskIntoConstraints="NO" misplaced="YES"> <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Name" lineBreakMode="tailTruncation" minimumFontSize="10" id="2316" translatesAutoresizingMaskIntoConstraints="NO">
<rect key="frame" x="15" y="10" width="570" height="21"/> <rect key="frame" x="15" y="10" width="570" height="21"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/> <fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/> <color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2317" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing" misplaced="YES"> <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2317" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing">
<rect key="frame" x="15" y="41" width="570" height="30"/> <rect key="frame" x="15" y="41" width="570" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
@ -242,14 +242,14 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/> <rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="URI" lineBreakMode="tailTruncation" minimumFontSize="10" id="2353" translatesAutoresizingMaskIntoConstraints="NO" misplaced="YES"> <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="URI" lineBreakMode="tailTruncation" minimumFontSize="10" id="2353" translatesAutoresizingMaskIntoConstraints="NO">
<rect key="frame" x="15" y="10" width="570" height="21"/> <rect key="frame" x="15" y="10" width="570" height="21"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/> <fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/> <color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2354" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing" misplaced="YES"> <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2354" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing">
<rect key="frame" x="15" y="41" width="570" height="30"/> <rect key="frame" x="15" y="41" width="570" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
@ -274,14 +274,14 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/> <rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Username" lineBreakMode="tailTruncation" minimumFontSize="10" id="2364" translatesAutoresizingMaskIntoConstraints="NO" misplaced="YES"> <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Username" lineBreakMode="tailTruncation" minimumFontSize="10" id="2364" translatesAutoresizingMaskIntoConstraints="NO">
<rect key="frame" x="15" y="10" width="570" height="21"/> <rect key="frame" x="15" y="10" width="570" height="21"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/> <fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/> <color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2365" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing" misplaced="YES"> <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2365" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing">
<rect key="frame" x="15" y="41" width="570" height="30"/> <rect key="frame" x="15" y="41" width="570" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
@ -306,14 +306,14 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/> <rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Password" lineBreakMode="tailTruncation" minimumFontSize="10" id="2375" translatesAutoresizingMaskIntoConstraints="NO" misplaced="YES"> <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Password" lineBreakMode="tailTruncation" minimumFontSize="10" id="2375" translatesAutoresizingMaskIntoConstraints="NO">
<rect key="frame" x="15" y="10" width="570" height="21"/> <rect key="frame" x="15" y="10" width="570" height="21"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/> <fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/> <color key="textColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2376" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing" misplaced="YES"> <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="2376" translatesAutoresizingMaskIntoConstraints="NO" preservesSuperviewLayoutMargins="YES" clearButtonMode="whileEditing">
<rect key="frame" x="15" y="41" width="570" height="30"/> <rect key="frame" x="15" y="41" width="570" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
@ -408,6 +408,9 @@
<outlet property="usernameCell" destination="2362" id="name-outlet-2362"/> <outlet property="usernameCell" destination="2362" id="name-outlet-2362"/>
<outlet property="passwordCell" destination="2373" id="name-outlet-2373"/> <outlet property="passwordCell" destination="2373" id="name-outlet-2373"/>
<outlet property="generatePasswordCell" destination="2305" id="name-outlet-2305"/> <outlet property="generatePasswordCell" destination="2305" id="name-outlet-2305"/>
<outlet property="uriField" destination="2354" id="name-outlet-2354"/>
<outlet property="usernameField" destination="2365" id="name-outlet-2365"/>
<outlet property="passwordField" destination="2376" id="name-outlet-2376"/>
</connections> </connections>
</tableViewController> </tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="2093" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="2093" userLabel="First Responder" sceneMemberID="firstResponder"/>

View file

@ -1,13 +1,34 @@
using System; using System;
using Bit.App.Models;
using Foundation; using Foundation;
namespace Bit.iOS.Extension.Models namespace Bit.iOS.Extension.Models
{ {
public class Context public class Context
{ {
private DomainName _domainName;
public NSExtensionContext ExtContext { get; set; } public NSExtensionContext ExtContext { get; set; }
public string ProviderType { get; set; } public string ProviderType { get; set; }
public Uri Url { get; set; } public Uri Url { get; set; }
public DomainName DomainName
{
get
{
if(_domainName != null)
{
return _domainName;
}
DomainName domain;
if(Url?.Host != null && DomainName.TryParse(Url?.Host, out domain))
{
_domainName = domain;
}
return _domainName;
}
}
public string SiteTitle { get; set; } public string SiteTitle { get; set; }
public string Username { get; set; } public string Username { get; set; }
public string Password { get; set; } public string Password { get; set; }