field logic

This commit is contained in:
Kyle Spearrin 2019-04-29 13:51:05 -04:00
parent 134a4ec5d2
commit 9650e44078
5 changed files with 88 additions and 4 deletions

View file

@ -1,15 +1,18 @@
using Bit.App.Pages; using Bit.App.Pages;
using Bit.Core.Models.View; using Bit.Core.Models.View;
using Xamarin.Forms;
namespace Bit.App.Models namespace Bit.App.Models
{ {
public class ViewFieldViewModel : BaseViewModel public class ViewFieldViewModel : BaseViewModel
{ {
private FieldView _field; private FieldView _field;
private bool _showHiddenValue;
public ViewFieldViewModel(FieldView field) public ViewFieldViewModel(FieldView field)
{ {
Field = field; Field = field;
ToggleHiddenValueCommand = new Command(ToggleHiddenValue);
} }
public FieldView Field public FieldView Field
@ -18,8 +21,37 @@ namespace Bit.App.Models
set => SetProperty(ref _field, value, set => SetProperty(ref _field, value,
additionalPropertyNames: new string[] 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

@ -490,6 +490,7 @@
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label <Label
Text="{Binding Field.Name, Mode=OneWay}" Text="{Binding Field.Name, Mode=OneWay}"
@ -497,17 +498,45 @@
Grid.Row="0" Grid.Row="0"
Grid.Column="0" /> Grid.Column="0" />
<Label <Label
Text="{Binding Field.Value, Mode=OneWay}" Text="{Binding ValueText, Mode=OneWay}"
StyleClass="box-value" StyleClass="box-value"
Grid.Row="1" Grid.Row="1"
Grid.Column="0" /> Grid.Column="0"
IsVisible="{Binding IsTextType}" />
<controls:FaLabel
Text="{Binding ValueText, Mode=OneWay}"
StyleClass="box-value"
Grid.Row="1"
Grid.Column="0"
IsVisible="{Binding IsBooleanType}" />
<StackLayout IsVisible="{Binding IsHiddenType}"
Grid.Row="1"
Grid.Column="0">
<controls:MonoLabel
Text="{Binding ValueText, Mode=OneWay}"
StyleClass="box-value"
IsVisible="{Binding ShowHiddenValue}" />
<controls:MonoLabel
Text="{Binding Field.MaskedValue, Mode=OneWay}"
StyleClass="box-value"
IsVisible="{Binding ShowHiddenValue, Converter={StaticResource inverseBool}}" />
</StackLayout>
<controls:FaButton
StyleClass="box-row-button, box-row-button-platform"
Text="{Binding ShowHiddenValueIcon}"
Command="{Binding ToggleHiddenValueCommand}"
IsVisible="{Binding IsHiddenType}"
Grid.Row="0"
Grid.Column="1"
Grid.RowSpan="2" />
<controls:FaButton <controls:FaButton
StyleClass="box-row-button, box-row-button-platform" StyleClass="box-row-button, box-row-button-platform"
Text="&#xf0ea;" Text="&#xf0ea;"
Command="{Binding BindingContext.CopyFieldCommand, Source={x:Reference _page}}" Command="{Binding BindingContext.CopyFieldCommand, Source={x:Reference _page}}"
CommandParameter="{Binding Field}" CommandParameter="{Binding Field}"
IsVisible="{Binding ShowCopyButton}"
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="2"
Grid.RowSpan="2" /> Grid.RowSpan="2" />
</Grid> </Grid>
<BoxView StyleClass="box-row-separator" /> <BoxView StyleClass="box-row-separator" />

View file

@ -42,6 +42,7 @@ namespace Bit.App.Pages
_auditService = ServiceContainer.Resolve<IAuditService>("auditService"); _auditService = ServiceContainer.Resolve<IAuditService>("auditService");
CopyCommand = new Command<string>((id) => CopyAsync(id, null)); CopyCommand = new Command<string>((id) => CopyAsync(id, null));
CopyUriCommand = new Command<LoginUriView>(CopyUri); CopyUriCommand = new Command<LoginUriView>(CopyUri);
CopyFieldCommand = new Command<FieldView>(CopyField);
LaunchUriCommand = new Command<LoginUriView>(LaunchUri); LaunchUriCommand = new Command<LoginUriView>(LaunchUri);
TogglePasswordCommand = new Command(TogglePassword); TogglePasswordCommand = new Command(TogglePassword);
ToggleCardCodeCommand = new Command(ToggleCardCode); ToggleCardCodeCommand = new Command(ToggleCardCode);
@ -52,6 +53,7 @@ namespace Bit.App.Pages
public Command CopyCommand { get; set; } public Command CopyCommand { get; set; }
public Command CopyUriCommand { get; set; } public Command CopyUriCommand { get; set; }
public Command CopyFieldCommand { get; set; }
public Command LaunchUriCommand { get; set; } public Command LaunchUriCommand { get; set; }
public Command TogglePasswordCommand { get; set; } public Command TogglePasswordCommand { get; set; }
public Command ToggleCardCodeCommand { get; set; } public Command ToggleCardCodeCommand { get; set; }
@ -265,6 +267,10 @@ namespace Bit.App.Pages
{ {
name = AppResources.URI; name = AppResources.URI;
} }
else if(id == "FieldValue")
{
name = AppResources.Value;
}
else if(id == "CardNumber") else if(id == "CardNumber")
{ {
text = Cipher.Card.Number; text = Cipher.Card.Number;
@ -291,6 +297,11 @@ namespace Bit.App.Pages
CopyAsync("LoginUri", uri.Uri); CopyAsync("LoginUri", uri.Uri);
} }
private void CopyField(FieldView field)
{
CopyAsync("FieldValue", field.Value);
}
private void LaunchUri(LoginUriView uri) private void LaunchUri(LoginUriView uri)
{ {
if(uri.CanLaunch) if(uri.CanLaunch)

View file

@ -3363,6 +3363,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Value.
/// </summary>
internal static string Value {
get {
return ResourceManager.GetString("Value", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to {0} has been copied.. /// Looks up a localized string similar to {0} has been copied..
/// </summary> /// </summary>

View file

@ -1384,4 +1384,7 @@
<data name="IdentityName" xml:space="preserve"> <data name="IdentityName" xml:space="preserve">
<value>Identity Name</value> <value>Identity Name</value>
</data> </data>
<data name="Value" xml:space="preserve">
<value>Value</value>
</data>
</root> </root>