From 669385df0f03b51aba095f935bf76986faef8ef7 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 26 Jul 2016 22:28:02 -0400 Subject: [PATCH] Added setup view controller to app extension. --- src/iOS.Core/Constants.cs | 1 + src/iOS.Extension/LoadingViewController.cs | 30 ++++-- .../LoadingViewController.designer.cs | 8 -- src/iOS.Extension/MainInterface.storyboard | 98 ++++++++++++++++--- src/iOS.Extension/SetupViewController.cs | 38 +++++++ .../SetupViewController.designer.cs | 60 ++++++++++++ src/iOS.Extension/iOS.Extension.csproj | 4 + src/iOS/AppDelegate.cs | 2 +- 8 files changed, 213 insertions(+), 28 deletions(-) create mode 100644 src/iOS.Extension/SetupViewController.cs create mode 100644 src/iOS.Extension/SetupViewController.designer.cs diff --git a/src/iOS.Core/Constants.cs b/src/iOS.Core/Constants.cs index d44f85062..50941c0bb 100644 --- a/src/iOS.Core/Constants.cs +++ b/src/iOS.Core/Constants.cs @@ -27,5 +27,6 @@ public const string UTTypeAppExtensionChangePasswordAction = "org.appextension.change-password-action"; public const string UTTypeAppExtensionFillWebViewAction = "org.appextension.fill-webview-action"; public const string UTTypeAppExtensionFillBrowserAction = "org.appextension.fill-browser-action"; + public const string UTTypeAppExtensionSetup = "com.8bit.bitwarden.extension-setup"; } } diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index d869a4616..1f94b3fec 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -26,7 +26,7 @@ namespace Bit.iOS.Extension { private Context _context = new Context(); private bool _setupHockeyApp = false; - private readonly JsonSerializerSettings _jsonSettings = + private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; public LoadingViewController(IntPtr handle) : base(handle) @@ -39,10 +39,6 @@ namespace Bit.iOS.Extension View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); _context.ExtContext = ExtensionContext; - var descriptor = UIFontDescriptor.PreferredBody; - DecryptingLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize); - DecryptingLabel.TextColor = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f); - if(!Resolver.IsSet) { SetIoc(); @@ -69,7 +65,8 @@ namespace Bit.iOS.Extension || ProcessFindLoginBrowserProvider(itemProvider, Constants.UTTypeAppExtensionFillBrowserAction) || ProcessFindLoginBrowserProvider(itemProvider, Constants.UTTypeAppExtensionFillWebViewAction) || ProcessSaveLoginProvider(itemProvider) - || ProcessChangePasswordProvider(itemProvider)) + || ProcessChangePasswordProvider(itemProvider) + || ProcessExtensionSetupProvider(itemProvider)) { processed = true; break; @@ -116,6 +113,10 @@ namespace Bit.iOS.Extension { PerformSegue("newSiteSegue", this); } + else if(_context.ProviderType == Constants.UTTypeAppExtensionSetup) + { + PerformSegue("setupSegue", this); + } else { PerformSegue("siteListSegue", this); @@ -134,6 +135,7 @@ namespace Bit.iOS.Extension var fingerprintViewController = navController.TopViewController as LockFingerprintViewController; var pinViewController = navController.TopViewController as LockPinViewController; var passwordViewController = navController.TopViewController as LockPasswordViewController; + var setupViewController = navController.TopViewController as SetupViewController; if(listSiteController != null) { @@ -160,6 +162,11 @@ namespace Bit.iOS.Extension passwordViewController.Context = _context; passwordViewController.LoadingController = this; } + else if(setupViewController != null) + { + setupViewController.Context = _context; + setupViewController.LoadingController = this; + } } } @@ -403,6 +410,17 @@ namespace Bit.iOS.Extension }); } + private bool ProcessExtensionSetupProvider(NSItemProvider itemProvider) + { + if(itemProvider.HasItemConformingTo(Constants.UTTypeAppExtensionSetup)) + { + _context.ProviderType = Constants.UTTypeAppExtensionSetup; + return true; + } + + return false; + } + private T DeserializeDictionary(NSDictionary dict) { if(dict != null) diff --git a/src/iOS.Extension/LoadingViewController.designer.cs b/src/iOS.Extension/LoadingViewController.designer.cs index 062778b3e..0cd9c2cd2 100644 --- a/src/iOS.Extension/LoadingViewController.designer.cs +++ b/src/iOS.Extension/LoadingViewController.designer.cs @@ -14,16 +14,8 @@ namespace Bit.iOS.Extension [Register ("LoadingViewController")] partial class LoadingViewController { - [Outlet] - [GeneratedCode ("iOS Designer", "1.0")] - UIKit.UILabel DecryptingLabel { get; set; } - void ReleaseDesignerOutlets () { - if (DecryptingLabel != null) { - DecryptingLabel.Dispose (); - DecryptingLabel = null; - } } } } \ No newline at end of file diff --git a/src/iOS.Extension/MainInterface.storyboard b/src/iOS.Extension/MainInterface.storyboard index 3e55f2dda..9fe90ac45 100644 --- a/src/iOS.Extension/MainInterface.storyboard +++ b/src/iOS.Extension/MainInterface.storyboard @@ -18,23 +18,13 @@ - + - - + - - - @@ -43,7 +33,7 @@ - + @@ -78,6 +68,7 @@ + @@ -512,6 +503,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/iOS.Extension/SetupViewController.cs b/src/iOS.Extension/SetupViewController.cs new file mode 100644 index 000000000..5309ad0ca --- /dev/null +++ b/src/iOS.Extension/SetupViewController.cs @@ -0,0 +1,38 @@ +using System; +using Bit.iOS.Extension.Models; +using UIKit; +using Plugin.Settings.Abstractions; + +namespace Bit.iOS.Extension +{ + public partial class SetupViewController : UIViewController + { + public SetupViewController(IntPtr handle) : base(handle) + { } + + public Context Context { get; set; } + public LoadingViewController LoadingController { get; set; } + + 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() + { + View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); + var descriptor = UIFontDescriptor.PreferredBody; + DescriptionLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize); + DescriptionLabel.TextColor = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f); + ActivatedLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize * 1.3f); + base.ViewDidLoad(); + } + + partial void BackButton_Activated(UIBarButtonItem sender) + { + LoadingController.CompleteRequest(null); + } + } +} diff --git a/src/iOS.Extension/SetupViewController.designer.cs b/src/iOS.Extension/SetupViewController.designer.cs new file mode 100644 index 000000000..c42fc7681 --- /dev/null +++ b/src/iOS.Extension/SetupViewController.designer.cs @@ -0,0 +1,60 @@ +// WARNING +// +// This file has been generated automatically by Xamarin Studio from the outlets and +// actions declared in your storyboard file. +// Manual changes to this file will not be maintained. +// +using Foundation; +using System; +using System.CodeDom.Compiler; +using UIKit; + +namespace Bit.iOS.Extension +{ + [Register ("SetupViewController")] + partial class SetupViewController + { + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UIKit.UILabel ActivatedLabel { get; set; } + + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UIKit.UIBarButtonItem BackButton { get; set; } + + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UIKit.UILabel DescriptionLabel { get; set; } + + [Outlet] + [GeneratedCode ("iOS Designer", "1.0")] + UIKit.UIImageView IconImage { get; set; } + + [Action ("BackButton_Activated:")] + [GeneratedCode ("iOS Designer", "1.0")] + partial void BackButton_Activated (UIKit.UIBarButtonItem sender); + + void ReleaseDesignerOutlets () + { + if (ActivatedLabel != null) { + ActivatedLabel.Dispose (); + ActivatedLabel = null; + } + + if (BackButton != null) { + BackButton.Dispose (); + BackButton = null; + } + + if (DescriptionLabel != null) { + DescriptionLabel.Dispose (); + DescriptionLabel = null; + } + + if (IconImage != null) { + IconImage.Dispose (); + IconImage = null; + } + } + } +} \ No newline at end of file diff --git a/src/iOS.Extension/iOS.Extension.csproj b/src/iOS.Extension/iOS.Extension.csproj index 1fb4b9382..c15accf12 100644 --- a/src/iOS.Extension/iOS.Extension.csproj +++ b/src/iOS.Extension/iOS.Extension.csproj @@ -99,6 +99,10 @@ LockPasswordViewController.cs + + + SetupViewController.cs + LockPinViewController.cs diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 7478cbcdd..736deb16e 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -75,7 +75,7 @@ namespace Bit.iOS MessagingCenter.Subscribe(Xamarin.Forms.Application.Current, "ShowAppExtension", (sender, page) => { - var itemProvider = new NSItemProvider(new NSDictionary(), "com.8bit.bitwarden.extension-setup"); + var itemProvider = new NSItemProvider(new NSDictionary(), iOS.Core.Constants.UTTypeAppExtensionSetup); var extensionItem = new NSExtensionItem(); extensionItem.Attachments = new NSItemProvider[] { itemProvider }; var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null);