From 4a0e3227fc1375a10ad20890c3d5b35cc115c169 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sun, 30 Oct 2016 00:02:07 -0400 Subject: [PATCH] adjust font sizse for username/password if they are over certain lengths on vault view page. --- src/App/Models/Page/VaultViewSitePageModel.cs | 45 +++++++++++++++++++ src/App/Pages/Vault/VaultViewSitePage.cs | 2 + 2 files changed, 47 insertions(+) diff --git a/src/App/Models/Page/VaultViewSitePageModel.cs b/src/App/Models/Page/VaultViewSitePageModel.cs index 150dfc461..32e2ac42c 100644 --- a/src/App/Models/Page/VaultViewSitePageModel.cs +++ b/src/App/Models/Page/VaultViewSitePageModel.cs @@ -36,9 +36,31 @@ namespace Bit.App.Models.Page _username = value; PropertyChanged(this, new PropertyChangedEventArgs(nameof(Username))); PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowUsername))); + PropertyChanged(this, new PropertyChangedEventArgs(nameof(UsernameFontSize))); } } public bool ShowUsername => !string.IsNullOrWhiteSpace(Username); + public double UsernameFontSize + { + get + { + if(Device.OS == TargetPlatform.Android) + { + var length = Username?.Length ?? 0; + + if(length > 35) + { + return Device.GetNamedSize(NamedSize.Micro, typeof(Label)); + } + else if(length > 25) + { + return Device.GetNamedSize(NamedSize.Small, typeof(Label)); + } + } + + return Device.GetNamedSize(NamedSize.Medium, typeof(Label)); + } + } public string Password { @@ -48,9 +70,32 @@ namespace Bit.App.Models.Page _password = value; PropertyChanged(this, new PropertyChangedEventArgs(nameof(Password))); PropertyChanged(this, new PropertyChangedEventArgs(nameof(MaskedPassword))); + PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowPassword))); + PropertyChanged(this, new PropertyChangedEventArgs(nameof(PasswordFontSize))); } } public bool ShowPassword => !string.IsNullOrWhiteSpace(Password); + public double PasswordFontSize + { + get + { + if(Device.OS == TargetPlatform.Android) + { + var length = Password?.Length ?? 0; + + if(length > 25) + { + return Device.GetNamedSize(NamedSize.Micro, typeof(Label)); + } + else if(length > 15) + { + return Device.GetNamedSize(NamedSize.Small, typeof(Label)); + } + } + + return Device.GetNamedSize(NamedSize.Medium, typeof(Label)); + } + } public string Uri { diff --git a/src/App/Pages/Vault/VaultViewSitePage.cs b/src/App/Pages/Vault/VaultViewSitePage.cs index 027aeddc9..18ebe75a1 100644 --- a/src/App/Pages/Vault/VaultViewSitePage.cs +++ b/src/App/Pages/Vault/VaultViewSitePage.cs @@ -49,12 +49,14 @@ namespace Bit.App.Pages // Username UsernameCell = new LabeledValueCell(AppResources.Username, button1Text: AppResources.Copy); UsernameCell.Value.SetBinding(Label.TextProperty, s => s.Username); + UsernameCell.Value.SetBinding(Label.FontSizeProperty, s => s.UsernameFontSize); UsernameCell.Button1.Command = new Command(() => Copy(Model.Username, AppResources.Username)); // Password PasswordCell = new LabeledValueCell(AppResources.Password, button1Text: string.Empty, button2Text: AppResources.Copy); PasswordCell.Value.SetBinding(Label.TextProperty, s => s.MaskedPassword); + PasswordCell.Value.SetBinding(Label.FontSizeProperty, s => s.PasswordFontSize); PasswordCell.Button1.SetBinding(Button.ImageProperty, s => s.ShowHideImage); if(Device.OS == TargetPlatform.iOS) {