mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 01:48:25 +03:00
view page updates
This commit is contained in:
parent
d7312e2977
commit
9b2ce98b46
4 changed files with 85 additions and 7 deletions
25
src/App/Models/ViewFieldViewModel.cs
Normal file
25
src/App/Models/ViewFieldViewModel.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Bit.App.Pages;
|
||||
using Bit.Core.Models.View;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public class ViewFieldViewModel : BaseViewModel
|
||||
{
|
||||
private FieldView _field;
|
||||
|
||||
public ViewFieldViewModel(FieldView field)
|
||||
{
|
||||
Field = field;
|
||||
}
|
||||
|
||||
public FieldView Field
|
||||
{
|
||||
get => _field;
|
||||
set => SetProperty(ref _field, value,
|
||||
additionalPropertyNames: new string[]
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
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}">
|
||||
|
@ -18,6 +19,12 @@
|
|||
<ToolbarItem Icon="cogs.png"
|
||||
Text="{u:I18n Edit}" />
|
||||
</ContentPage.ToolbarItems>
|
||||
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<u:InverseBoolConverter x:Key="inverseBool" />
|
||||
</ResourceDictionary>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<ScrollView>
|
||||
<StackLayout Spacing="20">
|
||||
|
@ -167,7 +174,14 @@
|
|||
Text="{u:I18n URI}"
|
||||
StyleClass="box-label"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0" />
|
||||
Grid.Column="0"
|
||||
IsVisible="{Binding IsWebsite, Mode=OneWay, Converter={StaticResource inverseBool}}" />
|
||||
<Label
|
||||
Text="{u:I18n Website}"
|
||||
StyleClass="box-label"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
IsVisible="{Binding IsWebsite, Mode=OneWay}" />
|
||||
<Label
|
||||
Text="{Binding HostnameOrUri, Mode=OneWay}"
|
||||
StyleClass="box-value"
|
||||
|
@ -181,7 +195,8 @@
|
|||
CommandParameter="{Binding .}"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Grid.RowSpan="2" />
|
||||
Grid.RowSpan="2"
|
||||
IsVisible="{Binding CanLaunch, Mode=OneWay}" />
|
||||
<controls:FaButton
|
||||
StyleClass="box-row-button, box-row-button-platform"
|
||||
Text=""
|
||||
|
@ -215,9 +230,9 @@
|
|||
<Label Text="{u:I18n CustomFields}"
|
||||
StyleClass="box-header, box-header-platform" />
|
||||
</StackLayout>
|
||||
<controls:RepeaterView ItemsSource="{Binding Cipher.Fields}">
|
||||
<controls:RepeaterView ItemsSource="{Binding Fields}">
|
||||
<controls:RepeaterView.ItemTemplate>
|
||||
<DataTemplate x:DataType="views:FieldView">
|
||||
<DataTemplate x:DataType="models:ViewFieldViewModel">
|
||||
<StackLayout Spacing="0" Padding="0">
|
||||
<Grid StyleClass="box-row">
|
||||
<Grid.RowDefinitions>
|
||||
|
@ -229,12 +244,12 @@
|
|||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label
|
||||
Text="{Binding Name, Mode=OneWay}"
|
||||
Text="{Binding Field.Name, Mode=OneWay}"
|
||||
StyleClass="box-label"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0" />
|
||||
<Label
|
||||
Text="{Binding Value, Mode=OneWay}"
|
||||
Text="{Binding Field.Value, Mode=OneWay}"
|
||||
StyleClass="box-value"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0" />
|
||||
|
@ -242,7 +257,7 @@
|
|||
StyleClass="box-row-button, box-row-button-platform"
|
||||
Text=""
|
||||
Command="{Binding BindingContext.CopyFieldCommand, Source={x:Reference _page}}"
|
||||
CommandParameter="{Binding .}"
|
||||
CommandParameter="{Binding Field}"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Grid.RowSpan="2" />
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models;
|
||||
using Bit.App.Resources;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
|
@ -17,6 +20,7 @@ namespace Bit.App.Pages
|
|||
private readonly ITotpService _totpService;
|
||||
private readonly IPlatformUtilsService _platformUtilsService;
|
||||
private CipherView _cipher;
|
||||
private List<ViewFieldViewModel> _fields;
|
||||
private bool _canAccessPremium;
|
||||
private string _totpCode;
|
||||
private string _totpCodeFormatted;
|
||||
|
@ -58,6 +62,11 @@ namespace Bit.App.Pages
|
|||
nameof(ShowTotp)
|
||||
});
|
||||
}
|
||||
public List<ViewFieldViewModel> Fields
|
||||
{
|
||||
get => _fields;
|
||||
set => SetProperty(ref _fields, value);
|
||||
}
|
||||
public bool CanAccessPremium
|
||||
{
|
||||
get => _canAccessPremium;
|
||||
|
@ -102,6 +111,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();
|
||||
|
||||
if(Cipher.Type == Core.Enums.CipherType.Login && !string.IsNullOrWhiteSpace(Cipher.Login.Totp) &&
|
||||
(Cipher.OrganizationUseTotp || CanAccessPremium))
|
||||
|
|
28
src/App/Utilities/InverseBoolConverter.cs
Normal file
28
src/App/Utilities/InverseBoolConverter.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
{
|
||||
public class InverseBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter,
|
||||
System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if(targetType == typeof(bool))
|
||||
{
|
||||
return !(bool)value;
|
||||
}
|
||||
if(targetType == typeof(bool?))
|
||||
{
|
||||
return !((bool?)value).GetValueOrDefault();
|
||||
}
|
||||
throw new InvalidOperationException("The target must be a boolean.");
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter,
|
||||
System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue