1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-17 15:27:43 +01:00

move field view model

This commit is contained in:
Kyle Spearrin 2019-04-29 13:56:36 -04:00
parent 9468bb322d
commit 2a6fe3f351
3 changed files with 55 additions and 62 deletions

View File

@ -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;
}
}
}

View File

@ -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 @@
</StackLayout>
<controls:RepeaterView ItemsSource="{Binding Fields}">
<controls:RepeaterView.ItemTemplate>
<DataTemplate x:DataType="models:ViewFieldViewModel">
<DataTemplate x:DataType="pages:ViewPageFieldViewModel">
<StackLayout Spacing="0" Padding="0">
<Grid StyleClass="box-row">
<Grid.RowDefinitions>

View File

@ -22,7 +22,7 @@ namespace Bit.App.Pages
private readonly IPlatformUtilsService _platformUtilsService;
private readonly IAuditService _auditService;
private CipherView _cipher;
private List<ViewFieldViewModel> _fields;
private List<ViewPageFieldViewModel> _fields;
private bool _canAccessPremium;
private bool _showPassword;
private bool _showCardCode;
@ -76,7 +76,7 @@ namespace Bit.App.Pages
nameof(ShowIdentityAddress),
});
}
public List<ViewFieldViewModel> Fields
public List<ViewPageFieldViewModel> 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;
}
}
}