mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-17 15:27:43 +01:00
pickers
This commit is contained in:
parent
0495c17fc8
commit
bb0ee239b4
@ -33,6 +33,17 @@
|
|||||||
<Label Text="{u:I18n ItemInformation}"
|
<Label Text="{u:I18n ItemInformation}"
|
||||||
StyleClass="box-header, box-header-platform" />
|
StyleClass="box-header, box-header-platform" />
|
||||||
</StackLayout>
|
</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">
|
<StackLayout StyleClass="box-row, box-row-input">
|
||||||
<Label
|
<Label
|
||||||
Text="{u:I18n Name}"
|
Text="{u:I18n Name}"
|
||||||
@ -127,7 +138,8 @@
|
|||||||
StyleClass="box-label" />
|
StyleClass="box-label" />
|
||||||
<Picker
|
<Picker
|
||||||
x:Name="_cardBrandPicker"
|
x:Name="_cardBrandPicker"
|
||||||
ItemsSource="{Binding CardBrandOptions}"
|
ItemsSource="{Binding CardBrandOptions, Mode=OneTime}"
|
||||||
|
SelectedIndex="{Binding CardBrandSelectedIndex}"
|
||||||
StyleClass="box-value" />
|
StyleClass="box-value" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<StackLayout StyleClass="box-row, box-row-input">
|
<StackLayout StyleClass="box-row, box-row-input">
|
||||||
@ -136,7 +148,8 @@
|
|||||||
StyleClass="box-label" />
|
StyleClass="box-label" />
|
||||||
<Picker
|
<Picker
|
||||||
x:Name="_cardExpMonthPicker"
|
x:Name="_cardExpMonthPicker"
|
||||||
ItemsSource="{Binding CardExpMonthOptions}"
|
ItemsSource="{Binding CardExpMonthOptions, Mode=OneTime}"
|
||||||
|
SelectedIndex="{Binding CardExpMonthSelectedIndex}"
|
||||||
StyleClass="box-value" />
|
StyleClass="box-value" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<StackLayout StyleClass="box-row, box-row-input">
|
<StackLayout StyleClass="box-row, box-row-input">
|
||||||
@ -185,7 +198,8 @@
|
|||||||
StyleClass="box-label" />
|
StyleClass="box-label" />
|
||||||
<Picker
|
<Picker
|
||||||
x:Name="_identityTitlePicker"
|
x:Name="_identityTitlePicker"
|
||||||
ItemsSource="{Binding IdentityTitleOptions}"
|
ItemsSource="{Binding IdentityTitleOptions, Mode=OneTime}"
|
||||||
|
SelectedIndex="{Binding IdentityTitleSelectedIndex}"
|
||||||
StyleClass="box-value" />
|
StyleClass="box-value" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<StackLayout StyleClass="box-row, box-row-input">
|
<StackLayout StyleClass="box-row, box-row-input">
|
||||||
|
@ -24,6 +24,7 @@ namespace Bit.App.Pages
|
|||||||
_vm.Init();
|
_vm.Init();
|
||||||
SetActivityIndicator();
|
SetActivityIndicator();
|
||||||
|
|
||||||
|
_typePicker.ItemDisplayBinding = new Binding("Key");
|
||||||
_cardBrandPicker.ItemDisplayBinding = new Binding("Key");
|
_cardBrandPicker.ItemDisplayBinding = new Binding("Key");
|
||||||
_cardExpMonthPicker.ItemDisplayBinding = new Binding("Key");
|
_cardExpMonthPicker.ItemDisplayBinding = new Binding("Key");
|
||||||
_identityTitlePicker.ItemDisplayBinding = new Binding("Key");
|
_identityTitlePicker.ItemDisplayBinding = new Binding("Key");
|
||||||
|
@ -24,6 +24,20 @@ namespace Bit.App.Pages
|
|||||||
private List<AddEditPageFieldViewModel> _fields;
|
private List<AddEditPageFieldViewModel> _fields;
|
||||||
private bool _showPassword;
|
private bool _showPassword;
|
||||||
private bool _showCardCode;
|
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()
|
public AddEditPageViewModel()
|
||||||
{
|
{
|
||||||
@ -38,6 +52,13 @@ namespace Bit.App.Pages
|
|||||||
ToggleCardCodeCommand = new Command(ToggleCardCode);
|
ToggleCardCodeCommand = new Command(ToggleCardCode);
|
||||||
CheckPasswordCommand = new Command(CheckPasswordAsync);
|
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>>
|
CardBrandOptions = new List<KeyValuePair<string, string>>
|
||||||
{
|
{
|
||||||
new KeyValuePair<string, string>($"-- {AppResources.Select} --", null),
|
new KeyValuePair<string, string>($"-- {AppResources.Select} --", null),
|
||||||
@ -86,23 +107,50 @@ namespace Bit.App.Pages
|
|||||||
public string FolderId { get; set; }
|
public string FolderId { get; set; }
|
||||||
public CipherType? Type { get; set; }
|
public CipherType? Type { get; set; }
|
||||||
public List<string> CollectionIds { 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>> CardBrandOptions { get; set; }
|
||||||
public List<KeyValuePair<string, string>> CardExpMonthOptions { get; set; }
|
public List<KeyValuePair<string, string>> CardExpMonthOptions { get; set; }
|
||||||
public List<KeyValuePair<string, string>> IdentityTitleOptions { 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
|
public CipherView Cipher
|
||||||
{
|
{
|
||||||
get => _cipher;
|
get => _cipher;
|
||||||
set => SetProperty(ref _cipher, value,
|
set => SetProperty(ref _cipher, value, additionalPropertyNames: _additionalCipherProperties);
|
||||||
additionalPropertyNames: new string[]
|
|
||||||
{
|
|
||||||
nameof(IsLogin),
|
|
||||||
nameof(IsIdentity),
|
|
||||||
nameof(IsCard),
|
|
||||||
nameof(IsSecureNote),
|
|
||||||
nameof(ShowUris),
|
|
||||||
nameof(ShowAttachments),
|
|
||||||
nameof(ShowIdentityAddress),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
public List<AddEditPageFieldViewModel> Fields
|
public List<AddEditPageFieldViewModel> Fields
|
||||||
{
|
{
|
||||||
@ -155,6 +203,19 @@ namespace Bit.App.Pages
|
|||||||
var cipher = await _cipherService.GetAsync(CipherId);
|
var cipher = await _cipherService.GetAsync(CipherId);
|
||||||
Cipher = await cipher.DecryptAsync();
|
Cipher = await cipher.DecryptAsync();
|
||||||
Fields = Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f)).ToList();
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -171,6 +232,10 @@ namespace Bit.App.Pages
|
|||||||
Cipher.Login.Uris = new List<LoginUriView>();
|
Cipher.Login.Uris = new List<LoginUriView>();
|
||||||
Cipher.SecureNote.Type = SecureNoteType.Generic;
|
Cipher.SecureNote.Type = SecureNoteType.Generic;
|
||||||
|
|
||||||
|
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
|
||||||
|
CardBrandSelectedIndex = 0;
|
||||||
|
CardExpMonthSelectedIndex = 0;
|
||||||
|
IdentityTitleSelectedIndex = 0;
|
||||||
// TODO: org/collection stuff
|
// TODO: org/collection stuff
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,6 +322,44 @@ namespace Bit.App.Pages
|
|||||||
ShowCardCode = !ShowCardCode;
|
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()
|
private async void CheckPasswordAsync()
|
||||||
{
|
{
|
||||||
if(!(Page as BaseContentPage).DoOnce())
|
if(!(Page as BaseContentPage).DoOnce())
|
||||||
|
@ -124,37 +124,7 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
private async void AddButton_Clicked(object sender, System.EventArgs e)
|
private async void AddButton_Clicked(object sender, System.EventArgs e)
|
||||||
{
|
{
|
||||||
var type = await DisplayActionSheet(AppResources.SelectTypeAdd, AppResources.Cancel, null,
|
var page = new AddEditPage(null, _vm.Type, _vm.FolderId, _vm.CollectionId);
|
||||||
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);
|
|
||||||
await Navigation.PushModalAsync(new NavigationPage(page));
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
src/App/Resources/AppResources.Designer.cs
generated
9
src/App/Resources/AppResources.Designer.cs
generated
@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Card.
|
/// Looks up a localized string similar to Card.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1408,4 +1408,7 @@
|
|||||||
<data name="SearchType" xml:space="preserve">
|
<data name="SearchType" xml:space="preserve">
|
||||||
<value>Search type</value>
|
<value>Search type</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Type" xml:space="preserve">
|
||||||
|
<value>Type</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -18,6 +18,13 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
backingStore = value;
|
backingStore = value;
|
||||||
|
TriggerPropertyChanged(propertyName, additionalPropertyNames);
|
||||||
|
onChanged?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void TriggerPropertyChanged(string propertyName, string[] additionalPropertyNames = null)
|
||||||
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
if(PropertyChanged != null && additionalPropertyNames != null)
|
if(PropertyChanged != null && additionalPropertyNames != null)
|
||||||
{
|
{
|
||||||
@ -26,8 +33,6 @@ namespace Bit.Core.Utilities
|
|||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(prop));
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(prop));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onChanged?.Invoke();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user