Remove UserDialogs plugin and dependencies for extension. Use custom/native dialogs for extension. Added modern http client to resolve TLS issues in extension. Dismiss and reload table for add site in extension.

This commit is contained in:
Kyle Spearrin 2016-07-09 15:23:54 -04:00
parent d61d3c201a
commit 4cb9488ee7
7 changed files with 75 additions and 46 deletions

View file

@ -0,0 +1,32 @@
using System;
using System.Drawing;
using CoreGraphics;
using UIKit;
namespace Bit.iOS.Core.Utilities
{
public static class Dialogs
{
public static UIAlertController CreateLoadingAlert(string message)
{
var loadingIndicator = new UIActivityIndicatorView(new CGRect(10, 5, 50, 50));
loadingIndicator.HidesWhenStopped = true;
loadingIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
loadingIndicator.StartAnimating();
var alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
alert.View.TintColor = UIColor.Black;
alert.View.Add(loadingIndicator);
return alert;
}
public static UIAlertController CreateAlert(string title, string message, string accept)
{
var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
var oldFrame = alert.View.Frame;
alert.View.Frame = new RectangleF((float)oldFrame.X, (float)oldFrame.Y, (float)oldFrame.Width, (float)oldFrame.Height - 20);
alert.AddAction(UIAlertAction.Create(accept, UIAlertActionStyle.Default, null));
return alert;
}
}
}

View file

@ -67,6 +67,7 @@
<Compile Include="Services\KeyChainStorageService.cs" />
<Compile Include="Services\Settings.cs" />
<Compile Include="Services\SqlService.cs" />
<Compile Include="Utilities\Dialogs.cs" />
<Compile Include="Views\PickerTableViewCell.cs" />
<Compile Include="Views\SwitchTableViewCell.cs" />
<Compile Include="Views\FormEntryTableViewCell.cs" />

View file

@ -16,7 +16,6 @@ using Bit.iOS.Extension.Models;
using MobileCoreServices;
using Plugin.Settings.Abstractions;
using Plugin.Connectivity;
using Acr.UserDialogs;
using Plugin.Fingerprint;
namespace Bit.iOS.Extension
@ -108,7 +107,6 @@ namespace Bit.iOS.Extension
.RegisterType<IAuthApiRepository, AuthApiRepository>(new ContainerControlledLifetimeManager())
// Other
.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
ISettings settings = new Settings("group.com.8bit.bitwarden");

View file

@ -12,17 +12,20 @@ using UIKit;
using XLabs.Ioc;
using Bit.App;
using Plugin.Connectivity.Abstractions;
using Acr.UserDialogs;
using System.Drawing;
using Bit.iOS.Core.Utilities;
namespace Bit.iOS.Extension
{
public partial class SiteAddViewController : UITableViewController
{
private ISiteService _siteService;
private IConnectivity _connectivity;
public SiteAddViewController(IntPtr handle) : base(handle)
{ }
public Context Context { get; set; }
public SiteListViewController Parent { get; set; }
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);
@ -40,6 +43,9 @@ namespace Bit.iOS.Extension
public override void ViewDidLoad()
{
_siteService = Resolver.Resolve<ISiteService>();
_connectivity = Resolver.Resolve<IConnectivity>();
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
NameCell.TextField.Text = Context.Url.Host;
@ -88,18 +94,23 @@ namespace Bit.iOS.Extension
base.ViewDidLoad();
}
async partial void CancelBarButton_Activated(UIBarButtonItem sender)
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
if(!_connectivity.IsConnected)
{
AlertNoConnection();
}
}
partial void CancelBarButton_Activated(UIBarButtonItem sender)
{
DismissViewController(true, null);
}
async partial void SaveBarButton_Activated(UIBarButtonItem sender)
{
var siteService = Resolver.Resolve<ISiteService>();
var connectivity = Resolver.Resolve<IConnectivity>();
var userDialogs = Resolver.Resolve<IUserDialogs>();
if(!connectivity.IsConnected)
if(!_connectivity.IsConnected)
{
AlertNoConnection();
return;
@ -119,29 +130,27 @@ namespace Bit.iOS.Extension
var site = new Site
{
Uri = UriCell.TextField.Text?.Encrypt(),
Name = NameCell.TextField.Text?.Encrypt(),
Username = UsernameCell.TextField.Text?.Encrypt(),
Password = PasswordCell.TextField.Text?.Encrypt(),
Notes = NotesCell.TextView.Text?.Encrypt(),
Uri = string.IsNullOrWhiteSpace(UriCell.TextField.Text) ? null : UriCell.TextField.Text.Encrypt(),
Name = string.IsNullOrWhiteSpace(NameCell.TextField.Text) ? null : NameCell.TextField.Text.Encrypt(),
Username = string.IsNullOrWhiteSpace(UsernameCell.TextField.Text) ? null : UsernameCell.TextField.Text.Encrypt(),
Password = string.IsNullOrWhiteSpace(PasswordCell.TextField.Text) ? null : PasswordCell.TextField.Text.Encrypt(),
Notes = string.IsNullOrWhiteSpace(NotesCell.TextView.Text) ? null : NotesCell.TextView.Text.Encrypt(),
Favorite = FavoriteCell.Switch.On
};
var saveTask = siteService.SaveAsync(site);
userDialogs.ShowLoading("Saving...", MaskType.Black);
var saveTask = _siteService.SaveAsync(site);
var loadingAlert = Dialogs.CreateLoadingAlert("Saving...");
PresentViewController(loadingAlert, true, null);
await saveTask;
userDialogs.HideLoading();
DismissViewController(true, null);
userDialogs.SuccessToast(NameCell.TextField.Text, "New site created.");
DismissViewController(false, () =>
{
Parent.DismissModal();
});
}
public void DisplayAlert(string title, string message, string accept)
{
var alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
var oldFrame = alert.View.Frame;
alert.View.Frame = new RectangleF((float)oldFrame.X, (float)oldFrame.Y, (float)oldFrame.Width, (float)oldFrame.Height - 20);
alert.AddAction(UIAlertAction.Create(accept, UIAlertActionStyle.Default, null));
var alert = Dialogs.CreateAlert(title, message, accept);
PresentViewController(alert, true, null);
}

View file

@ -74,10 +74,17 @@ namespace Bit.iOS.Extension
if(addSiteController != null)
{
addSiteController.Context = Context;
addSiteController.Parent = this;
}
}
}
public void DismissModal()
{
DismissModalViewController(true);
TableView.ReloadData();
}
public class TableSource : UITableViewSource
{
private const string CellIdentifier = "TableCell";

View file

@ -26,8 +26,6 @@
<MtouchLink>None</MtouchLink>
<MtouchDebug>true</MtouchDebug>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchTlsProvider>Legacy</MtouchTlsProvider>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
@ -59,8 +57,6 @@
</CodesignExtraArgs>
<MtouchSdkVersion>9.3</MtouchSdkVersion>
<MtouchLink>None</MtouchLink>
<MtouchTlsProvider>Legacy</MtouchTlsProvider>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
@ -132,16 +128,8 @@
<HintPath>..\..\packages\Acr.Support.2.1.0\lib\Xamarin.iOS10\Acr.Support.iOS.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Acr.UserDialogs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Acr.UserDialogs.5.3.0\lib\Xamarin.iOS10\Acr.UserDialogs.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Acr.UserDialogs.Interface, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Acr.UserDialogs.5.3.0\lib\Xamarin.iOS10\Acr.UserDialogs.Interface.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="BTProgressHUD, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\BTProgressHUD.1.2.0.3\lib\Xamarin.iOS10\BTProgressHUD.dll</HintPath>
<Reference Include="ModernHttpClient, Version=2.4.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\modernhttpclient.2.4.2\lib\Xamarin.iOS10\ModernHttpClient.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@ -172,10 +160,6 @@
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Splat.1.6.2\lib\Xamarin.iOS10\Splat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SQLite-net, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\sqlite-net-pcl.1.1.2\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll</HintPath>
<Private>True</Private>

View file

@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Acr.Support" version="2.1.0" targetFramework="xamarinios10" />
<package id="Acr.UserDialogs" version="5.3.0" targetFramework="xamarinios10" />
<package id="BTProgressHUD" version="1.2.0.3" targetFramework="xamarinios10" />
<package id="CommonServiceLocator" version="1.3" targetFramework="xamarinios10" />
<package id="modernhttpclient" version="2.4.2" targetFramework="xamarinios10" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="xamarinios10" />
<package id="Plugin.Fingerprint" version="1.2.0" targetFramework="xamarinios10" />
<package id="Splat" version="1.6.2" targetFramework="xamarinios10" />
<package id="sqlite-net-pcl" version="1.1.2" targetFramework="xamarinios10" />
<package id="SQLitePCL.bundle_green" version="0.9.2" targetFramework="xamarinios10" />
<package id="SQLitePCL.raw" version="0.9.2" targetFramework="xamarinios10" />