From 31ad96ff3103dd21398fba3c0d6d6dbc22353e48 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 6 Jul 2016 22:59:13 -0400 Subject: [PATCH] lazy decrypt password and username for vault listing. dynamically show copy and url launch options if provided. --- src/App/Models/Page/VaultListPageModel.cs | 8 +++---- src/App/Models/Page/VaultViewSitePageModel.cs | 2 ++ src/App/Pages/Vault/VaultListSitesPage.cs | 22 +++++++++++++++---- src/App/Pages/Vault/VaultViewSitePage.cs | 1 + 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/App/Models/Page/VaultListPageModel.cs b/src/App/Models/Page/VaultListPageModel.cs index 4d3fd73d8..623ebf739 100644 --- a/src/App/Models/Page/VaultListPageModel.cs +++ b/src/App/Models/Page/VaultListPageModel.cs @@ -16,16 +16,16 @@ namespace Bit.App.Models.Page FolderId = folderId; Name = site.Name?.Decrypt(); Username = site.Username?.Decrypt() ?? " "; - Password = site.Password?.Decrypt(); - Uri = site.Uri?.Decrypt(); + Password = new Lazy(() => site.Password?.Decrypt()); + Uri = new Lazy(() => site.Uri?.Decrypt()); } public string Id { get; set; } public string FolderId { get; set; } public string Name { get; set; } public string Username { get; set; } - public string Password { get; set; } - public string Uri { get; set; } + public Lazy Password { get; set; } + public Lazy Uri { get; set; } } public class Folder : List diff --git a/src/App/Models/Page/VaultViewSitePageModel.cs b/src/App/Models/Page/VaultViewSitePageModel.cs index 2bd7acb22..150dfc461 100644 --- a/src/App/Models/Page/VaultViewSitePageModel.cs +++ b/src/App/Models/Page/VaultViewSitePageModel.cs @@ -61,9 +61,11 @@ namespace Bit.App.Models.Page PropertyChanged(this, new PropertyChangedEventArgs(nameof(Uri))); PropertyChanged(this, new PropertyChangedEventArgs(nameof(UriHost))); PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowUri))); + PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowLaunch))); } } public bool ShowUri => !string.IsNullOrWhiteSpace(Uri); + public bool ShowLaunch => Uri.StartsWith("http://") || Uri.StartsWith("https://"); public string UriHost { diff --git a/src/App/Pages/Vault/VaultListSitesPage.cs b/src/App/Pages/Vault/VaultListSitesPage.cs index 60c92b75c..399fc01dc 100644 --- a/src/App/Pages/Vault/VaultListSitesPage.cs +++ b/src/App/Pages/Vault/VaultListSitesPage.cs @@ -13,6 +13,7 @@ using Bit.App.Utilities; using PushNotification.Plugin.Abstractions; using Plugin.Settings.Abstractions; using Plugin.Connectivity.Abstractions; +using System.Collections.Generic; namespace Bit.App.Pages { @@ -121,8 +122,21 @@ namespace Bit.App.Pages private async void MoreClickedAsync(VaultListPageModel.Site site) { - var selection = await DisplayActionSheet(site.Name, AppResources.Cancel, null, - AppResources.View, AppResources.Edit, AppResources.CopyPassword, AppResources.CopyUsername, AppResources.GoToWebsite); + var buttons = new List { AppResources.View, AppResources.Edit }; + if(!string.IsNullOrWhiteSpace(site.Password.Value)) + { + buttons.Add(AppResources.CopyPassword); + } + if(!string.IsNullOrWhiteSpace(site.Username)) + { + buttons.Add(AppResources.CopyUsername); + } + if(!string.IsNullOrWhiteSpace(site.Uri.Value) && (site.Uri.Value.StartsWith("http://") || site.Uri.Value.StartsWith("https://"))) + { + buttons.Add(AppResources.GoToWebsite); + } + + var selection = await DisplayActionSheet(site.Name, AppResources.Cancel, null, buttons.ToArray()); if(selection == AppResources.View) { @@ -136,7 +150,7 @@ namespace Bit.App.Pages } else if(selection == AppResources.CopyPassword) { - Copy(site.Password, AppResources.Password); + Copy(site.Password.Value, AppResources.Password); } else if(selection == AppResources.CopyUsername) { @@ -144,7 +158,7 @@ namespace Bit.App.Pages } else if(selection == AppResources.GoToWebsite) { - Device.OpenUri(new Uri(site.Uri)); + Device.OpenUri(new Uri(site.Uri.Value)); } } diff --git a/src/App/Pages/Vault/VaultViewSitePage.cs b/src/App/Pages/Vault/VaultViewSitePage.cs index 83b477f97..253cb295b 100644 --- a/src/App/Pages/Vault/VaultViewSitePage.cs +++ b/src/App/Pages/Vault/VaultViewSitePage.cs @@ -67,6 +67,7 @@ namespace Bit.App.Pages // URI UriCell = new LabeledValueCell(AppResources.Website, button1Text: AppResources.Launch); UriCell.Value.SetBinding(Label.TextProperty, s => s.UriHost); + UriCell.Button1.SetBinding(IsVisibleProperty, s => s.ShowLaunch); UriCell.Button1.Command = new Command(() => Device.OpenUri(new Uri(Model.Uri))); // Notes