1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-18 01:03:24 +00:00

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.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<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)
@@ -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<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);
}
}
}
}