Update ios extension to use new login service lookup by uristring

This commit is contained in:
Kyle Spearrin 2017-02-09 00:12:09 -05:00
parent 539121070a
commit 4af91b5ab6
5 changed files with 23 additions and 92 deletions

View file

@ -328,7 +328,7 @@ namespace Bit.iOS.Extension
_googleAnalyticsService.TrackExtensionEvent("ProcessItemProvider", type); _googleAnalyticsService.TrackExtensionEvent("ProcessItemProvider", type);
Debug.WriteLine("BW LOG, ProviderType: " + _context.ProviderType); Debug.WriteLine("BW LOG, ProviderType: " + _context.ProviderType);
Debug.WriteLine("BW LOG, Url: " + _context.Url); Debug.WriteLine("BW LOG, Url: " + _context.UrlString);
Debug.WriteLine("BW LOG, Title: " + _context.LoginTitle); Debug.WriteLine("BW LOG, Title: " + _context.LoginTitle);
Debug.WriteLine("BW LOG, Username: " + _context.Username); Debug.WriteLine("BW LOG, Username: " + _context.Username);
Debug.WriteLine("BW LOG, Password: " + _context.Password); Debug.WriteLine("BW LOG, Password: " + _context.Password);
@ -359,7 +359,7 @@ namespace Bit.iOS.Extension
return; return;
} }
_context.Url = new Uri(result.ValueForKey(new NSString(Constants.AppExtensionUrlStringKey)) as NSString); _context.UrlString = result.ValueForKey(new NSString(Constants.AppExtensionUrlStringKey)) as NSString;
var jsonStr = result.ValueForKey(new NSString(Constants.AppExtensionWebViewPageDetails)) as NSString; var jsonStr = result.ValueForKey(new NSString(Constants.AppExtensionWebViewPageDetails)) as NSString;
_context.Details = DeserializeString<PageDetails>(jsonStr); _context.Details = DeserializeString<PageDetails>(jsonStr);
}); });
@ -374,7 +374,7 @@ namespace Bit.iOS.Extension
if(url != null) if(url != null)
{ {
_context.Url = new Uri(url); _context.UrlString = url;
} }
}); });
} }
@ -387,7 +387,7 @@ namespace Bit.iOS.Extension
var url = dict[Constants.AppExtensionUrlStringKey] as NSString; var url = dict[Constants.AppExtensionUrlStringKey] as NSString;
if(url != null) if(url != null)
{ {
_context.Url = new Uri(url); _context.UrlString = url;
} }
_context.Details = DeserializeDictionary<PageDetails>(dict[Constants.AppExtensionWebViewPageDetails] as NSDictionary); _context.Details = DeserializeDictionary<PageDetails>(dict[Constants.AppExtensionWebViewPageDetails] as NSDictionary);
@ -409,7 +409,7 @@ namespace Bit.iOS.Extension
if(url != null) if(url != null)
{ {
_context.Url = new Uri(url); _context.UrlString = url;
} }
_context.LoginTitle = title; _context.LoginTitle = title;
@ -436,7 +436,7 @@ namespace Bit.iOS.Extension
if(url != null) if(url != null)
{ {
_context.Url = new Uri(url); _context.UrlString = url;
} }
_context.LoginTitle = title; _context.LoginTitle = title;

View file

@ -59,7 +59,7 @@ namespace Bit.iOS.Extension
SaveBarButton.Title = AppResources.Save; SaveBarButton.Title = AppResources.Save;
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
NameCell.TextField.Text = Context?.Url?.Host ?? string.Empty; NameCell.TextField.Text = Context?.Uri?.Host ?? string.Empty;
NameCell.TextField.ReturnKeyType = UIReturnKeyType.Next; NameCell.TextField.ReturnKeyType = UIReturnKeyType.Next;
NameCell.TextField.ShouldReturn += (UITextField tf) => NameCell.TextField.ShouldReturn += (UITextField tf) =>
{ {
@ -67,7 +67,7 @@ namespace Bit.iOS.Extension
return true; return true;
}; };
UriCell.TextField.Text = Context?.Url?.ToString() ?? string.Empty; UriCell.TextField.Text = Context?.UrlString ?? string.Empty;
UriCell.TextField.KeyboardType = UIKeyboardType.Url; UriCell.TextField.KeyboardType = UIKeyboardType.Url;
UriCell.TextField.ReturnKeyType = UIReturnKeyType.Next; UriCell.TextField.ReturnKeyType = UIReturnKeyType.Next;
UriCell.TextField.ShouldReturn += (UITextField tf) => UriCell.TextField.ShouldReturn += (UITextField tf) =>

View file

@ -113,17 +113,13 @@ namespace Bit.iOS.Extension
public async Task LoadItemsAsync() public async Task LoadItemsAsync()
{ {
_tableItems = new List<LoginViewModel>(); var loginService = Resolver.Resolve<ILoginService>();
if(_context.DomainName != null) var logins = await loginService.GetAllAsync(_context.UrlString);
{ var loginModels = logins;
var loginService = Resolver.Resolve<ILoginService>(); _tableItems = logins.Select(s => new LoginViewModel(s))
var logins = await loginService.GetAllAsync(); .OrderBy(s => s.Name)
var loginModels = logins.Select(s => new LoginViewModel(s)); .ThenBy(s => s.Username)
_tableItems = loginModels .ToList();
.Where(s => s.Domain != null && s.Domain.BaseDomain == _context.DomainName.BaseDomain)
.OrderBy(s => s.Name).ThenBy(s => s.Username)
.ToList();
}
} }
public IEnumerable<LoginViewModel> TableItems { get; set; } public IEnumerable<LoginViewModel> TableItems { get; set; }

View file

@ -10,25 +10,20 @@ namespace Bit.iOS.Extension.Models
public NSExtensionContext ExtContext { get; set; } public NSExtensionContext ExtContext { get; set; }
public string ProviderType { get; set; } public string ProviderType { get; set; }
public Uri Url { get; set; } public Uri Uri
public DomainName DomainName
{ {
get get
{ {
if(_domainName != null) Uri uri;
if(string.IsNullOrWhiteSpace(UrlString) || !Uri.TryCreate(UrlString, UriKind.Absolute, out uri))
{ {
return _domainName; return null;
} }
DomainName domain; return uri;
if(Url?.Host != null && DomainName.TryParse(Url?.Host, out domain))
{
_domainName = domain;
}
return _domainName;
} }
} }
public string UrlString { get; set; }
public string LoginTitle { get; set; } public string LoginTitle { get; set; }
public string Username { get; set; } public string Username { get; set; }
public string Password { get; set; } public string Password { get; set; }

View file

@ -1,16 +1,9 @@
using System; using Bit.App.Models;
using System.Collections.Generic;
using System.Text;
using Bit.App.Models;
namespace Bit.iOS.Extension.Models namespace Bit.iOS.Extension.Models
{ {
public class LoginViewModel public class LoginViewModel
{ {
private string _uri;
private DomainName _domain = null;
private bool _domainParsed = false;
public LoginViewModel(Login login) public LoginViewModel(Login login)
{ {
Id = login.Id; Id = login.Id;
@ -24,59 +17,6 @@ namespace Bit.iOS.Extension.Models
public string Name { get; set; } public string Name { get; set; }
public string Username { get; set; } public string Username { get; set; }
public string Password { get; set; } public string Password { get; set; }
public string Uri public string Uri { get; set; }
{
get { return _uri; }
set
{
_domainParsed = false;
_uri = value;
}
}
public string HostName
{
get
{
if(string.IsNullOrWhiteSpace(Uri))
{
return null;
}
try
{
return new Uri(Uri)?.Host;
}
catch
{
return null;
};
}
}
public DomainName Domain
{
get
{
if(string.IsNullOrWhiteSpace(Uri))
{
return null;
}
if(_domainParsed)
{
return _domain;
}
_domainParsed = true;
DomainName domain;
if(DomainName.TryParse(HostName, out domain))
{
_domain = domain;
}
return _domain;
}
}
} }
} }