From 4af91b5ab66f9a5bc9e2e3d2ec012734b17c39d5 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 9 Feb 2017 00:12:09 -0500 Subject: [PATCH] Update ios extension to use new login service lookup by uristring --- src/iOS.Extension/LoadingViewController.cs | 12 ++-- src/iOS.Extension/LoginAddViewController.cs | 4 +- src/iOS.Extension/LoginListViewController.cs | 18 +++--- src/iOS.Extension/Models/Context.cs | 17 ++---- src/iOS.Extension/Models/LoginViewModel.cs | 64 +------------------- 5 files changed, 23 insertions(+), 92 deletions(-) diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index 82a3baf1d..45883f6c7 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -328,7 +328,7 @@ namespace Bit.iOS.Extension _googleAnalyticsService.TrackExtensionEvent("ProcessItemProvider", type); 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, Username: " + _context.Username); Debug.WriteLine("BW LOG, Password: " + _context.Password); @@ -359,7 +359,7 @@ namespace Bit.iOS.Extension 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; _context.Details = DeserializeString(jsonStr); }); @@ -374,7 +374,7 @@ namespace Bit.iOS.Extension 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; if(url != null) { - _context.Url = new Uri(url); + _context.UrlString = url; } _context.Details = DeserializeDictionary(dict[Constants.AppExtensionWebViewPageDetails] as NSDictionary); @@ -409,7 +409,7 @@ namespace Bit.iOS.Extension if(url != null) { - _context.Url = new Uri(url); + _context.UrlString = url; } _context.LoginTitle = title; @@ -436,7 +436,7 @@ namespace Bit.iOS.Extension if(url != null) { - _context.Url = new Uri(url); + _context.UrlString = url; } _context.LoginTitle = title; diff --git a/src/iOS.Extension/LoginAddViewController.cs b/src/iOS.Extension/LoginAddViewController.cs index 98e7b4f56..c459ee641 100644 --- a/src/iOS.Extension/LoginAddViewController.cs +++ b/src/iOS.Extension/LoginAddViewController.cs @@ -59,7 +59,7 @@ namespace Bit.iOS.Extension SaveBarButton.Title = AppResources.Save; 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.ShouldReturn += (UITextField tf) => { @@ -67,7 +67,7 @@ namespace Bit.iOS.Extension return true; }; - UriCell.TextField.Text = Context?.Url?.ToString() ?? string.Empty; + UriCell.TextField.Text = Context?.UrlString ?? string.Empty; UriCell.TextField.KeyboardType = UIKeyboardType.Url; UriCell.TextField.ReturnKeyType = UIReturnKeyType.Next; UriCell.TextField.ShouldReturn += (UITextField tf) => diff --git a/src/iOS.Extension/LoginListViewController.cs b/src/iOS.Extension/LoginListViewController.cs index f6861f0ca..009f91cf0 100644 --- a/src/iOS.Extension/LoginListViewController.cs +++ b/src/iOS.Extension/LoginListViewController.cs @@ -113,17 +113,13 @@ namespace Bit.iOS.Extension public async Task LoadItemsAsync() { - _tableItems = new List(); - if(_context.DomainName != null) - { - var loginService = Resolver.Resolve(); - var logins = await loginService.GetAllAsync(); - var loginModels = logins.Select(s => new LoginViewModel(s)); - _tableItems = loginModels - .Where(s => s.Domain != null && s.Domain.BaseDomain == _context.DomainName.BaseDomain) - .OrderBy(s => s.Name).ThenBy(s => s.Username) - .ToList(); - } + var loginService = Resolver.Resolve(); + var logins = await loginService.GetAllAsync(_context.UrlString); + var loginModels = logins; + _tableItems = logins.Select(s => new LoginViewModel(s)) + .OrderBy(s => s.Name) + .ThenBy(s => s.Username) + .ToList(); } public IEnumerable TableItems { get; set; } diff --git a/src/iOS.Extension/Models/Context.cs b/src/iOS.Extension/Models/Context.cs index 0c3724d67..447965c06 100644 --- a/src/iOS.Extension/Models/Context.cs +++ b/src/iOS.Extension/Models/Context.cs @@ -10,25 +10,20 @@ namespace Bit.iOS.Extension.Models public NSExtensionContext ExtContext { get; set; } public string ProviderType { get; set; } - public Uri Url { get; set; } - public DomainName DomainName + public Uri Uri { get { - if(_domainName != null) + Uri uri; + if(string.IsNullOrWhiteSpace(UrlString) || !Uri.TryCreate(UrlString, UriKind.Absolute, out uri)) { - return _domainName; + return null; } - DomainName domain; - if(Url?.Host != null && DomainName.TryParse(Url?.Host, out domain)) - { - _domainName = domain; - } - - return _domainName; + return uri; } } + public string UrlString { get; set; } public string LoginTitle { get; set; } public string Username { get; set; } public string Password { get; set; } diff --git a/src/iOS.Extension/Models/LoginViewModel.cs b/src/iOS.Extension/Models/LoginViewModel.cs index 107adcdaf..8121faa26 100644 --- a/src/iOS.Extension/Models/LoginViewModel.cs +++ b/src/iOS.Extension/Models/LoginViewModel.cs @@ -1,16 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Bit.App.Models; +using Bit.App.Models; namespace Bit.iOS.Extension.Models { public class LoginViewModel { - private string _uri; - private DomainName _domain = null; - private bool _domainParsed = false; - public LoginViewModel(Login login) { Id = login.Id; @@ -24,59 +17,6 @@ namespace Bit.iOS.Extension.Models public string Name { get; set; } public string Username { get; set; } public string Password { get; set; } - public string Uri - { - 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; - } - } + public string Uri { get; set; } } }