2016-07-08 03:53:01 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
using Bit.App.Models;
|
2016-07-09 08:07:02 +03:00
|
|
|
using Bit.App.Resources;
|
|
|
|
using Bit.iOS.Core.Views;
|
2016-07-08 03:53:01 +03:00
|
|
|
using Bit.iOS.Extension.Models;
|
|
|
|
using Foundation;
|
|
|
|
using UIKit;
|
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
{
|
2016-07-09 09:01:23 +03:00
|
|
|
public partial class SiteAddViewController : UITableViewController
|
2016-07-08 03:53:01 +03:00
|
|
|
{
|
2016-07-09 09:01:23 +03:00
|
|
|
public SiteAddViewController(IntPtr handle) : base(handle)
|
2016-07-08 03:53:01 +03:00
|
|
|
{ }
|
|
|
|
|
|
|
|
public Context Context { get; set; }
|
2016-07-09 08:07:02 +03:00
|
|
|
public FormEntryTableViewCell NameCell { get; set; } = new FormEntryTableViewCell(AppResources.Name);
|
|
|
|
public FormEntryTableViewCell UriCell { get; set; } = new FormEntryTableViewCell(AppResources.URI);
|
|
|
|
public FormEntryTableViewCell UsernameCell { get; set; } = new FormEntryTableViewCell(AppResources.Username);
|
|
|
|
public FormEntryTableViewCell PasswordCell { get; set; } = new FormEntryTableViewCell(AppResources.Password);
|
|
|
|
public UITableViewCell GeneratePasswordCell { get; set; } = new UITableViewCell(UITableViewCellStyle.Subtitle, "GeneratePasswordCell");
|
|
|
|
public SwitchTableViewCell FavoriteCell { get; set; } = new SwitchTableViewCell("Favorite");
|
|
|
|
public FormEntryTableViewCell NotesCell { get; set; } = new FormEntryTableViewCell(useTextView: true, height: 90);
|
2016-07-08 03:53:01 +03:00
|
|
|
|
|
|
|
public override void ViewWillAppear(bool animated)
|
|
|
|
{
|
|
|
|
UINavigationBar.Appearance.ShadowImage = new UIImage();
|
|
|
|
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
|
|
|
|
base.ViewWillAppear(animated);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void ViewDidLoad()
|
|
|
|
{
|
2016-07-09 08:07:02 +03:00
|
|
|
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
|
|
|
|
|
|
|
|
NameCell.TextField.Text = Context.Url.Host;
|
|
|
|
NameCell.TextField.ReturnKeyType = UIReturnKeyType.Next;
|
|
|
|
NameCell.TextField.ShouldReturn += (UITextField tf) =>
|
|
|
|
{
|
|
|
|
UriCell.TextField.BecomeFirstResponder();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
UriCell.TextField.Text = Context.Url.ToString();
|
|
|
|
UriCell.TextField.KeyboardType = UIKeyboardType.Url;
|
|
|
|
UriCell.TextField.ReturnKeyType = UIReturnKeyType.Next;
|
|
|
|
UriCell.TextField.ShouldReturn += (UITextField tf) =>
|
|
|
|
{
|
|
|
|
UsernameCell.TextField.BecomeFirstResponder();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
UsernameCell.TextField.BecomeFirstResponder();
|
|
|
|
UsernameCell.TextField.AutocapitalizationType = UITextAutocapitalizationType.None;
|
|
|
|
UsernameCell.TextField.AutocorrectionType = UITextAutocorrectionType.No;
|
|
|
|
UsernameCell.TextField.SpellCheckingType = UITextSpellCheckingType.No;
|
|
|
|
UsernameCell.TextField.ReturnKeyType = UIReturnKeyType.Next;
|
|
|
|
UsernameCell.TextField.ShouldReturn += (UITextField tf) =>
|
|
|
|
{
|
|
|
|
PasswordCell.TextField.BecomeFirstResponder();
|
|
|
|
return true;
|
|
|
|
};
|
2016-07-08 07:35:48 +03:00
|
|
|
|
2016-07-09 08:07:02 +03:00
|
|
|
PasswordCell.TextField.SecureTextEntry = true;
|
|
|
|
PasswordCell.TextField.ReturnKeyType = UIReturnKeyType.Next;
|
|
|
|
PasswordCell.TextField.ShouldReturn += (UITextField tf) =>
|
|
|
|
{
|
|
|
|
NotesCell.TextView.BecomeFirstResponder();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
GeneratePasswordCell.TextLabel.Text = "Generate Password";
|
|
|
|
GeneratePasswordCell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
|
2016-07-08 07:35:48 +03:00
|
|
|
|
2016-07-09 09:01:23 +03:00
|
|
|
TableView.RowHeight = UITableView.AutomaticDimension;
|
|
|
|
TableView.EstimatedRowHeight = 70;
|
|
|
|
TableView.Source = new TableSource(this);
|
2016-07-08 03:53:01 +03:00
|
|
|
|
|
|
|
base.ViewDidLoad();
|
|
|
|
}
|
|
|
|
|
2016-07-09 09:01:23 +03:00
|
|
|
partial void CancelBarButton_Activated(UIBarButtonItem sender)
|
2016-07-08 03:53:01 +03:00
|
|
|
{
|
|
|
|
DismissViewController(true, null);
|
|
|
|
}
|
|
|
|
|
2016-07-09 09:01:23 +03:00
|
|
|
partial void SaveBarButton_Activated(UIBarButtonItem sender)
|
2016-07-08 03:53:01 +03:00
|
|
|
{
|
|
|
|
DismissViewController(true, null);
|
|
|
|
}
|
2016-07-08 07:06:10 +03:00
|
|
|
|
|
|
|
public class TableSource : UITableViewSource
|
|
|
|
{
|
2016-07-09 09:01:23 +03:00
|
|
|
private SiteAddViewController _controller;
|
2016-07-08 07:06:10 +03:00
|
|
|
|
2016-07-09 09:01:23 +03:00
|
|
|
public TableSource(SiteAddViewController controller)
|
2016-07-08 07:06:10 +03:00
|
|
|
{
|
|
|
|
_controller = controller;
|
|
|
|
}
|
|
|
|
|
2016-07-09 08:07:02 +03:00
|
|
|
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
|
2016-07-08 07:06:10 +03:00
|
|
|
{
|
2016-07-09 08:07:02 +03:00
|
|
|
if(indexPath.Section == 0)
|
|
|
|
{
|
|
|
|
if(indexPath.Row == 0)
|
|
|
|
{
|
|
|
|
return _controller.NameCell;
|
|
|
|
}
|
|
|
|
else if(indexPath.Row == 1)
|
|
|
|
{
|
|
|
|
return _controller.UriCell;
|
|
|
|
}
|
|
|
|
else if(indexPath.Row == 2)
|
|
|
|
{
|
|
|
|
return _controller.UsernameCell;
|
|
|
|
}
|
|
|
|
else if(indexPath.Row == 3)
|
|
|
|
{
|
|
|
|
return _controller.PasswordCell;
|
|
|
|
}
|
|
|
|
else if(indexPath.Row == 4)
|
|
|
|
{
|
|
|
|
return _controller.GeneratePasswordCell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(indexPath.Section == 1)
|
|
|
|
{
|
|
|
|
if(indexPath.Row == 1)
|
|
|
|
{
|
|
|
|
return _controller.FavoriteCell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(indexPath.Section == 2)
|
|
|
|
{
|
|
|
|
return _controller.NotesCell;
|
2016-07-08 07:06:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return new UITableViewCell();
|
|
|
|
}
|
|
|
|
|
2016-07-09 08:07:02 +03:00
|
|
|
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
|
2016-07-08 07:06:10 +03:00
|
|
|
{
|
|
|
|
return UITableView.AutomaticDimension;
|
|
|
|
}
|
|
|
|
|
2016-07-09 08:07:02 +03:00
|
|
|
public override nint NumberOfSections(UITableView tableView)
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override nint RowsInSection(UITableView tableview, nint section)
|
2016-07-08 07:06:10 +03:00
|
|
|
{
|
2016-07-09 08:07:02 +03:00
|
|
|
if(section == 0)
|
|
|
|
{
|
2016-07-08 07:06:10 +03:00
|
|
|
return 5;
|
2016-07-09 08:07:02 +03:00
|
|
|
}
|
|
|
|
else if(section == 1)
|
|
|
|
{
|
2016-07-08 07:06:10 +03:00
|
|
|
return 2;
|
2016-07-09 08:07:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-08 07:06:10 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 08:07:02 +03:00
|
|
|
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
|
2016-07-08 07:06:10 +03:00
|
|
|
{
|
|
|
|
return UITableView.AutomaticDimension;
|
2016-07-09 08:07:02 +03:00
|
|
|
}
|
2016-07-08 07:06:10 +03:00
|
|
|
|
2016-07-09 08:07:02 +03:00
|
|
|
public override string TitleForHeader(UITableView tableView, nint section)
|
2016-07-08 07:06:10 +03:00
|
|
|
{
|
2016-07-09 08:07:02 +03:00
|
|
|
if(section == 0)
|
|
|
|
{
|
2016-07-08 07:06:10 +03:00
|
|
|
return "Site Information";
|
2016-07-09 08:07:02 +03:00
|
|
|
}
|
|
|
|
else if(section == 2)
|
|
|
|
{
|
2016-07-08 07:06:10 +03:00
|
|
|
return "Notes";
|
|
|
|
}
|
|
|
|
|
2016-07-09 08:07:02 +03:00
|
|
|
return null;
|
2016-07-08 07:06:10 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-08 03:53:01 +03:00
|
|
|
}
|
|
|
|
}
|