2016-05-27 05:22:38 +03:00
|
|
|
using System;
|
2016-06-05 01:27:34 +03:00
|
|
|
using System.Collections.Generic;
|
2016-06-10 07:36:15 +03:00
|
|
|
using System.Diagnostics;
|
2016-06-05 01:27:34 +03:00
|
|
|
using System.Linq;
|
2016-06-05 00:04:49 +03:00
|
|
|
using Bit.iOS.Core;
|
|
|
|
using Bit.iOS.Extension.Models;
|
2016-05-07 08:54:44 +03:00
|
|
|
using Foundation;
|
2016-05-27 05:22:38 +03:00
|
|
|
using MobileCoreServices;
|
2016-06-02 07:18:47 +03:00
|
|
|
using Newtonsoft.Json;
|
2016-05-07 08:54:44 +03:00
|
|
|
using UIKit;
|
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
{
|
|
|
|
public partial class ActionViewController : UIViewController
|
|
|
|
{
|
2016-06-03 06:28:17 +03:00
|
|
|
public ActionViewController(IntPtr handle) : base(handle)
|
2016-05-07 08:54:44 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
public Context Context { get; set; }
|
2016-05-07 08:54:44 +03:00
|
|
|
|
2016-06-03 06:28:17 +03:00
|
|
|
public override void ViewDidLoad()
|
2016-06-03 03:35:54 +03:00
|
|
|
{
|
2016-06-03 06:28:17 +03:00
|
|
|
base.ViewDidLoad();
|
2016-06-04 19:10:03 +03:00
|
|
|
View.BackgroundColor = UIColor.FromPatternImage(new UIImage("boxed-bg.png"));
|
2016-06-05 01:27:34 +03:00
|
|
|
NavigationController.NavigationBar.TintColor = UIColor.White;
|
|
|
|
NavigationController.NavigationBar.BarTintColor = new UIColor(0.24f, 0.55f, 0.74f, 1.0f);
|
2016-06-05 04:59:33 +03:00
|
|
|
NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White };
|
2016-06-05 01:27:34 +03:00
|
|
|
|
|
|
|
List<string> sites = new List<string>();
|
|
|
|
for(int i = 1; i <= 100; i++)
|
|
|
|
{
|
|
|
|
sites.Add("Site " + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
tableView.Source = new TableSource(sites, this);
|
2016-05-27 05:22:38 +03:00
|
|
|
}
|
|
|
|
|
2016-06-05 00:04:49 +03:00
|
|
|
partial void CancelClicked(UIBarButtonItem sender)
|
|
|
|
{
|
|
|
|
CompleteRequest(null);
|
|
|
|
}
|
2016-06-04 22:27:50 +03:00
|
|
|
|
2016-06-05 01:27:34 +03:00
|
|
|
private void CompleteRequest(NSDictionary itemData)
|
2016-06-04 19:10:03 +03:00
|
|
|
{
|
2016-06-05 01:27:34 +03:00
|
|
|
var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
|
|
|
|
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
|
|
|
|
var returningItems = new NSExtensionItem[] { resultsItem };
|
|
|
|
|
|
|
|
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)
|
2016-06-02 07:18:47 +03:00
|
|
|
{
|
2016-06-05 01:27:34 +03:00
|
|
|
_tableItems = items;
|
|
|
|
_context = controller.Context;
|
|
|
|
_controller = controller;
|
2016-06-02 07:18:47 +03:00
|
|
|
}
|
2016-06-05 01:27:34 +03:00
|
|
|
|
|
|
|
public override nint RowsInSection(UITableView tableview, nint section)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
2016-06-05 01:27:34 +03:00
|
|
|
return _tableItems.Count();
|
2016-05-31 05:51:53 +03:00
|
|
|
}
|
2016-06-05 01:27:34 +03:00
|
|
|
|
|
|
|
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
|
2016-05-31 05:51:53 +03:00
|
|
|
{
|
2016-06-05 01:27:34 +03:00
|
|
|
var cell = tableView.DequeueReusableCell(CellIdentifier);
|
|
|
|
var item = _tableItems.ElementAt(indexPath.Row);
|
2016-05-30 10:08:12 +03:00
|
|
|
|
2016-06-05 01:27:34 +03:00
|
|
|
// if there are no cells to reuse, create a new one
|
|
|
|
if(cell == null)
|
|
|
|
{
|
|
|
|
cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier);
|
|
|
|
}
|
2016-05-30 10:08:12 +03:00
|
|
|
|
2016-06-05 01:27:34 +03:00
|
|
|
cell.TextLabel.Text = item;
|
|
|
|
return cell;
|
|
|
|
}
|
2016-06-02 07:18:47 +03:00
|
|
|
|
2016-06-05 01:27:34 +03:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2016-06-10 07:36:15 +03:00
|
|
|
Debug.WriteLine("BW LOG, itemData: " + itemData);
|
|
|
|
|
2016-06-05 01:27:34 +03:00
|
|
|
_controller.CompleteRequest(itemData);
|
|
|
|
}
|
2016-06-02 07:18:47 +03:00
|
|
|
}
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
2016-06-05 00:04:49 +03:00
|
|
|
}
|