bitwarden-android/src/iOS.Extension/ActionViewController.cs

79 lines
3.1 KiB
C#
Raw Normal View History

using System;
using Bit.iOS.Core;
using Bit.iOS.Extension.Models;
using Foundation;
using MobileCoreServices;
using Newtonsoft.Json;
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)
{
}
public Context Context { get; set; }
2016-06-03 06:28:17 +03:00
public override void ViewDidLoad()
{
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"));
}
partial void CancelClicked(UIBarButtonItem sender)
{
CompleteRequest(null);
}
2016-06-04 19:10:03 +03:00
partial void DoneClicked(NSObject sender)
{
NSDictionary itemData = null;
if(Context.ProviderType == UTType.PropertyList)
2016-06-03 01:09:25 +03:00
{
var fillScript = new FillScript(Context.Details);
2016-06-03 01:09:25 +03:00
var scriptJson = JsonConvert.SerializeObject(fillScript, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
var scriptDict = new NSDictionary(Constants.AppExtensionWebViewPageFillScript, scriptJson);
2016-06-03 01:09:25 +03:00
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);
2016-06-02 07:28:41 +03:00
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);
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
var returningItems = new NSExtensionItem[] { resultsItem };
Context.ExtContext.CompleteRequest(returningItems, null);
}
}
}