This commit is contained in:
Kyle Spearrin 2019-05-08 14:37:12 -04:00
parent 0495c17fc8
commit bb0ee239b4
7 changed files with 152 additions and 47 deletions

View File

@ -33,6 +33,17 @@
<Label Text="{u:I18n ItemInformation}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
<StackLayout StyleClass="box-row, box-row-input"
IsVisible="{Binding EditMode, Converter={StaticResource inverseBool}}">
<Label
Text="{u:I18n Type}"
StyleClass="box-label" />
<Picker
x:Name="_typePicker"
ItemsSource="{Binding TypeOptions, Mode=OneTime}"
SelectedIndex="{Binding TypeSelectedIndex}"
StyleClass="box-value" />
</StackLayout>
<StackLayout StyleClass="box-row, box-row-input">
<Label
Text="{u:I18n Name}"
@ -127,7 +138,8 @@
StyleClass="box-label" />
<Picker
x:Name="_cardBrandPicker"
ItemsSource="{Binding CardBrandOptions}"
ItemsSource="{Binding CardBrandOptions, Mode=OneTime}"
SelectedIndex="{Binding CardBrandSelectedIndex}"
StyleClass="box-value" />
</StackLayout>
<StackLayout StyleClass="box-row, box-row-input">
@ -136,7 +148,8 @@
StyleClass="box-label" />
<Picker
x:Name="_cardExpMonthPicker"
ItemsSource="{Binding CardExpMonthOptions}"
ItemsSource="{Binding CardExpMonthOptions, Mode=OneTime}"
SelectedIndex="{Binding CardExpMonthSelectedIndex}"
StyleClass="box-value" />
</StackLayout>
<StackLayout StyleClass="box-row, box-row-input">
@ -185,7 +198,8 @@
StyleClass="box-label" />
<Picker
x:Name="_identityTitlePicker"
ItemsSource="{Binding IdentityTitleOptions}"
ItemsSource="{Binding IdentityTitleOptions, Mode=OneTime}"
SelectedIndex="{Binding IdentityTitleSelectedIndex}"
StyleClass="box-value" />
</StackLayout>
<StackLayout StyleClass="box-row, box-row-input">

View File

@ -24,6 +24,7 @@ namespace Bit.App.Pages
_vm.Init();
SetActivityIndicator();
_typePicker.ItemDisplayBinding = new Binding("Key");
_cardBrandPicker.ItemDisplayBinding = new Binding("Key");
_cardExpMonthPicker.ItemDisplayBinding = new Binding("Key");
_identityTitlePicker.ItemDisplayBinding = new Binding("Key");

View File

@ -24,6 +24,20 @@ namespace Bit.App.Pages
private List<AddEditPageFieldViewModel> _fields;
private bool _showPassword;
private bool _showCardCode;
private int _typeSelectedIndex;
private int _cardBrandSelectedIndex;
private int _cardExpMonthSelectedIndex;
private int _identityTitleSelectedIndex;
private string[] _additionalCipherProperties = new string[]
{
nameof(IsLogin),
nameof(IsIdentity),
nameof(IsCard),
nameof(IsSecureNote),
nameof(ShowUris),
nameof(ShowAttachments),
nameof(ShowIdentityAddress),
};
public AddEditPageViewModel()
{
@ -38,6 +52,13 @@ namespace Bit.App.Pages
ToggleCardCodeCommand = new Command(ToggleCardCode);
CheckPasswordCommand = new Command(CheckPasswordAsync);
TypeOptions = new List<KeyValuePair<string, CipherType>>
{
new KeyValuePair<string, CipherType>(AppResources.TypeLogin, CipherType.Login),
new KeyValuePair<string, CipherType>(AppResources.TypeCard, CipherType.Card),
new KeyValuePair<string, CipherType>(AppResources.TypeIdentity, CipherType.Identity),
new KeyValuePair<string, CipherType>(AppResources.TypeSecureNote, CipherType.SecureNote),
};
CardBrandOptions = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>($"-- {AppResources.Select} --", null),
@ -86,23 +107,50 @@ namespace Bit.App.Pages
public string FolderId { get; set; }
public CipherType? Type { get; set; }
public List<string> CollectionIds { get; set; }
public List<KeyValuePair<string, CipherType>> TypeOptions { get; set; }
public List<KeyValuePair<string, string>> CardBrandOptions { get; set; }
public List<KeyValuePair<string, string>> CardExpMonthOptions { get; set; }
public List<KeyValuePair<string, string>> IdentityTitleOptions { get; set; }
public int TypeSelectedIndex
{
get => _typeSelectedIndex;
set
{
SetProperty(ref _typeSelectedIndex, value);
TypeChanged();
}
}
public int CardBrandSelectedIndex
{
get => _cardBrandSelectedIndex;
set
{
SetProperty(ref _cardBrandSelectedIndex, value);
CardBrandChanged();
}
}
public int CardExpMonthSelectedIndex
{
get => _cardExpMonthSelectedIndex;
set
{
SetProperty(ref _cardExpMonthSelectedIndex, value);
CardExpMonthChanged();
}
}
public int IdentityTitleSelectedIndex
{
get => _identityTitleSelectedIndex;
set
{
SetProperty(ref _identityTitleSelectedIndex, value);
IdentityTitleChanged();
}
}
public CipherView Cipher
{
get => _cipher;
set => SetProperty(ref _cipher, value,
additionalPropertyNames: new string[]
{
nameof(IsLogin),
nameof(IsIdentity),
nameof(IsCard),
nameof(IsSecureNote),
nameof(ShowUris),
nameof(ShowAttachments),
nameof(ShowIdentityAddress),
});
set => SetProperty(ref _cipher, value, additionalPropertyNames: _additionalCipherProperties);
}
public List<AddEditPageFieldViewModel> Fields
{
@ -155,6 +203,19 @@ namespace Bit.App.Pages
var cipher = await _cipherService.GetAsync(CipherId);
Cipher = await cipher.DecryptAsync();
Fields = Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f)).ToList();
if(Cipher.Card != null)
{
CardBrandSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.Brand) ? 0 :
CardBrandOptions.FindIndex(k => k.Value == Cipher.Card.Brand);
CardExpMonthSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.ExpMonth) ? 0 :
CardExpMonthOptions.FindIndex(k => k.Value == Cipher.Card.ExpMonth);
}
if(Cipher.Identity != null)
{
IdentityTitleSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Identity.Title) ? 0 :
IdentityTitleOptions.FindIndex(k => k.Value == Cipher.Identity.Title);
}
}
else
{
@ -171,6 +232,10 @@ namespace Bit.App.Pages
Cipher.Login.Uris = new List<LoginUriView>();
Cipher.SecureNote.Type = SecureNoteType.Generic;
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
CardBrandSelectedIndex = 0;
CardExpMonthSelectedIndex = 0;
IdentityTitleSelectedIndex = 0;
// TODO: org/collection stuff
}
}
@ -257,6 +322,44 @@ namespace Bit.App.Pages
ShowCardCode = !ShowCardCode;
}
private void TypeChanged()
{
if(Cipher != null && TypeSelectedIndex > -1)
{
Cipher.Type = TypeOptions[TypeSelectedIndex].Value;
TriggerCipherChanged();
}
}
private void CardBrandChanged()
{
if(Cipher?.Card != null && CardBrandSelectedIndex > -1)
{
Cipher.Card.Brand = CardBrandOptions[CardBrandSelectedIndex].Value;
}
}
private void CardExpMonthChanged()
{
if(Cipher?.Card != null && CardExpMonthSelectedIndex > -1)
{
Cipher.Card.ExpMonth = CardExpMonthOptions[CardExpMonthSelectedIndex].Value;
}
}
private void IdentityTitleChanged()
{
if(Cipher?.Identity != null && IdentityTitleSelectedIndex > -1)
{
Cipher.Identity.Title = IdentityTitleOptions[IdentityTitleSelectedIndex].Value;
}
}
private void TriggerCipherChanged()
{
TriggerPropertyChanged(nameof(Cipher), _additionalCipherProperties);
}
private async void CheckPasswordAsync()
{
if(!(Page as BaseContentPage).DoOnce())

View File

@ -124,37 +124,7 @@ namespace Bit.App.Pages
private async void AddButton_Clicked(object sender, System.EventArgs e)
{
var type = await DisplayActionSheet(AppResources.SelectTypeAdd, AppResources.Cancel, null,
AppResources.TypeLogin, AppResources.TypeCard, AppResources.TypeIdentity,
AppResources.TypeSecureNote);
var selectedType = CipherType.SecureNote;
if(type == null || type == AppResources.Cancel)
{
return;
}
else if(type == AppResources.TypeLogin)
{
selectedType = CipherType.Login;
}
else if(type == AppResources.TypeCard)
{
selectedType = CipherType.Card;
}
else if(type == AppResources.TypeIdentity)
{
selectedType = CipherType.Identity;
}
else if(type == AppResources.TypeSecureNote)
{
selectedType = CipherType.SecureNote;
}
else
{
return;
}
var page = new AddEditPage(null, selectedType);
var page = new AddEditPage(null, _vm.Type, _vm.FolderId, _vm.CollectionId);
await Navigation.PushModalAsync(new NavigationPage(page));
}
}

View File

@ -3237,6 +3237,15 @@ namespace Bit.App.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Type.
/// </summary>
public static string Type {
get {
return ResourceManager.GetString("Type", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Card.
/// </summary>

View File

@ -1408,4 +1408,7 @@
<data name="SearchType" xml:space="preserve">
<value>Search type</value>
</data>
<data name="Type" xml:space="preserve">
<value>Type</value>
</data>
</root>

View File

@ -18,6 +18,13 @@ namespace Bit.Core.Utilities
}
backingStore = value;
TriggerPropertyChanged(propertyName, additionalPropertyNames);
onChanged?.Invoke();
return true;
}
protected void TriggerPropertyChanged(string propertyName, string[] additionalPropertyNames = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
if(PropertyChanged != null && additionalPropertyNames != null)
{
@ -26,8 +33,6 @@ namespace Bit.Core.Utilities
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(prop));
}
}
onChanged?.Invoke();
return true;
}
}
}