From 2a6fe3f3512e5c20426c1912470731566c8b0ba1 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 29 Apr 2019 13:56:36 -0400 Subject: [PATCH] move field view model --- src/App/Models/ViewFieldViewModel.cs | 57 ------------------------ src/App/Pages/Vault/ViewPage.xaml | 3 +- src/App/Pages/Vault/ViewPageViewModel.cs | 57 ++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 62 deletions(-) delete mode 100644 src/App/Models/ViewFieldViewModel.cs diff --git a/src/App/Models/ViewFieldViewModel.cs b/src/App/Models/ViewFieldViewModel.cs deleted file mode 100644 index 8bba95145..000000000 --- a/src/App/Models/ViewFieldViewModel.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Bit.App.Pages; -using Bit.Core.Models.View; -using Xamarin.Forms; - -namespace Bit.App.Models -{ - public class ViewFieldViewModel : BaseViewModel - { - private FieldView _field; - private bool _showHiddenValue; - - public ViewFieldViewModel(FieldView field) - { - Field = field; - ToggleHiddenValueCommand = new Command(ToggleHiddenValue); - } - - public FieldView Field - { - get => _field; - set => SetProperty(ref _field, value, - additionalPropertyNames: new string[] - { - nameof(ValueText), - nameof(IsBooleanType), - nameof(IsHiddenType), - nameof(IsTextType), - nameof(ShowCopyButton), - }); - } - - public bool ShowHiddenValue - { - get => _showHiddenValue; - set => SetProperty(ref _showHiddenValue, value, - additionalPropertyNames: new string[] - { - nameof(ShowHiddenValueIcon) - }); - } - - public Command ToggleHiddenValueCommand { get; set; } - - public string ValueText => IsBooleanType ? (_field.Value == "true" ? "" : "") : _field.Value; - public string ShowHiddenValueIcon => _showHiddenValue ? "" : ""; - public bool IsTextType => _field.Type == Core.Enums.FieldType.Text; - public bool IsBooleanType => _field.Type == Core.Enums.FieldType.Boolean; - public bool IsHiddenType => _field.Type == Core.Enums.FieldType.Hidden; - public bool ShowCopyButton => _field.Type != Core.Enums.FieldType.Boolean && - !string.IsNullOrWhiteSpace(_field.Value); - - public void ToggleHiddenValue() - { - ShowHiddenValue = !ShowHiddenValue; - } - } -} diff --git a/src/App/Pages/Vault/ViewPage.xaml b/src/App/Pages/Vault/ViewPage.xaml index 2f955b61b..e4a852a50 100644 --- a/src/App/Pages/Vault/ViewPage.xaml +++ b/src/App/Pages/Vault/ViewPage.xaml @@ -7,7 +7,6 @@ xmlns:u="clr-namespace:Bit.App.Utilities" xmlns:controls="clr-namespace:Bit.App.Controls" xmlns:views="clr-namespace:Bit.Core.Models.View;assembly=BitwardenCore" - xmlns:models="clr-namespace:Bit.App.Models" x:DataType="pages:ViewPageViewModel" x:Name="_page" Title="{Binding PageTitle}"> @@ -480,7 +479,7 @@ - + diff --git a/src/App/Pages/Vault/ViewPageViewModel.cs b/src/App/Pages/Vault/ViewPageViewModel.cs index fef59dfc7..fe8a513b6 100644 --- a/src/App/Pages/Vault/ViewPageViewModel.cs +++ b/src/App/Pages/Vault/ViewPageViewModel.cs @@ -22,7 +22,7 @@ namespace Bit.App.Pages private readonly IPlatformUtilsService _platformUtilsService; private readonly IAuditService _auditService; private CipherView _cipher; - private List _fields; + private List _fields; private bool _canAccessPremium; private bool _showPassword; private bool _showCardCode; @@ -76,7 +76,7 @@ namespace Bit.App.Pages nameof(ShowIdentityAddress), }); } - public List Fields + public List Fields { get => _fields; set => SetProperty(ref _fields, value); @@ -149,7 +149,7 @@ namespace Bit.App.Pages var cipher = await _cipherService.GetAsync(CipherId); Cipher = await cipher.DecryptAsync(); CanAccessPremium = await _userService.CanAccessPremiumAsync(); - Fields = Cipher.Fields?.Select(f => new ViewFieldViewModel(f)).ToList(); + Fields = Cipher.Fields?.Select(f => new ViewPageFieldViewModel(f)).ToList(); if(Cipher.Type == Core.Enums.CipherType.Login && !string.IsNullOrWhiteSpace(Cipher.Login.Totp) && (Cipher.OrganizationUseTotp || CanAccessPremium)) @@ -310,4 +310,55 @@ namespace Bit.App.Pages } } } + + public class ViewPageFieldViewModel : BaseViewModel + { + private FieldView _field; + private bool _showHiddenValue; + + public ViewPageFieldViewModel(FieldView field) + { + Field = field; + ToggleHiddenValueCommand = new Command(ToggleHiddenValue); + } + + public FieldView Field + { + get => _field; + set => SetProperty(ref _field, value, + additionalPropertyNames: new string[] + { + nameof(ValueText), + nameof(IsBooleanType), + nameof(IsHiddenType), + nameof(IsTextType), + nameof(ShowCopyButton), + }); + } + + public bool ShowHiddenValue + { + get => _showHiddenValue; + set => SetProperty(ref _showHiddenValue, value, + additionalPropertyNames: new string[] + { + nameof(ShowHiddenValueIcon) + }); + } + + public Command ToggleHiddenValueCommand { get; set; } + + public string ValueText => IsBooleanType ? (_field.Value == "true" ? "" : "") : _field.Value; + public string ShowHiddenValueIcon => _showHiddenValue ? "" : ""; + public bool IsTextType => _field.Type == Core.Enums.FieldType.Text; + public bool IsBooleanType => _field.Type == Core.Enums.FieldType.Boolean; + public bool IsHiddenType => _field.Type == Core.Enums.FieldType.Hidden; + public bool ShowCopyButton => _field.Type != Core.Enums.FieldType.Boolean && + !string.IsNullOrWhiteSpace(_field.Value); + + public void ToggleHiddenValue() + { + ShowHiddenValue = !ShowHiddenValue; + } + } }