1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-28 10:54:59 +02:00

misc section with folders

This commit is contained in:
Kyle Spearrin 2019-05-09 12:18:23 -04:00
parent b07afa7f11
commit fb5c36071d
5 changed files with 103 additions and 44 deletions

View File

@ -348,7 +348,7 @@
<controls:RepeaterView ItemsSource="{Binding Uris}"> <controls:RepeaterView ItemsSource="{Binding Uris}">
<controls:RepeaterView.ItemTemplate> <controls:RepeaterView.ItemTemplate>
<DataTemplate x:DataType="views:LoginUriView"> <DataTemplate x:DataType="views:LoginUriView">
<Grid StyleClass="box-row"> <Grid StyleClass="box-row, box-row-input">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -383,12 +383,28 @@
<Button Text="{u:I18n NewUri}" StyleClass="box-button-row" <Button Text="{u:I18n NewUri}" StyleClass="box-button-row"
Clicked="NewUri_Clicked"></Button> Clicked="NewUri_Clicked"></Button>
</StackLayout> </StackLayout>
<StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Miscellaneous}"
StyleClass="box-header, box-header-platform" />
</StackLayout>
<StackLayout StyleClass="box-row, box-row-input">
<Label
Text="{u:I18n Folder}"
StyleClass="box-label" />
<Picker
x:Name="_folderPicker"
ItemsSource="{Binding FolderOptions, Mode=OneTime}"
SelectedIndex="{Binding FolderSelectedIndex}"
StyleClass="box-value" />
</StackLayout>
</StackLayout>
<StackLayout StyleClass="box"> <StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header"> <StackLayout StyleClass="box-row-header">
<Label Text="{u:I18n Notes}" <Label Text="{u:I18n Notes}"
StyleClass="box-header, box-header-platform" /> StyleClass="box-header, box-header-platform" />
</StackLayout> </StackLayout>
<StackLayout StyleClass="box-row"> <StackLayout StyleClass="box-row, box-row-input">
<Editor <Editor
Text="{Binding Cipher.Notes}" Text="{Binding Cipher.Notes}"
StyleClass="box-value" StyleClass="box-value"
@ -404,7 +420,7 @@
<controls:RepeaterView.ItemTemplate> <controls:RepeaterView.ItemTemplate>
<DataTemplate x:DataType="pages:AddEditPageFieldViewModel"> <DataTemplate x:DataType="pages:AddEditPageFieldViewModel">
<StackLayout Spacing="0" Padding="0"> <StackLayout Spacing="0" Padding="0">
<Grid StyleClass="box-row"> <Grid StyleClass="box-row, box-row-input">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />

View File

@ -28,6 +28,7 @@ namespace Bit.App.Pages
_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");
_folderPicker.ItemDisplayBinding = new Binding("Key");
} }
protected override async void OnAppearing() protected override async void OnAppearing()

View File

@ -16,6 +16,7 @@ namespace Bit.App.Pages
{ {
private readonly IDeviceActionService _deviceActionService; private readonly IDeviceActionService _deviceActionService;
private readonly ICipherService _cipherService; private readonly ICipherService _cipherService;
private readonly IFolderService _folderService;
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly IPlatformUtilsService _platformUtilsService; private readonly IPlatformUtilsService _platformUtilsService;
private readonly IAuditService _auditService; private readonly IAuditService _auditService;
@ -27,6 +28,7 @@ namespace Bit.App.Pages
private int _cardBrandSelectedIndex; private int _cardBrandSelectedIndex;
private int _cardExpMonthSelectedIndex; private int _cardExpMonthSelectedIndex;
private int _identityTitleSelectedIndex; private int _identityTitleSelectedIndex;
private int _folderSelectedIndex;
private string[] _additionalCipherProperties = new string[] private string[] _additionalCipherProperties = new string[]
{ {
nameof(IsLogin), nameof(IsLogin),
@ -60,6 +62,7 @@ namespace Bit.App.Pages
{ {
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"); _deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_cipherService = ServiceContainer.Resolve<ICipherService>("cipherService"); _cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
_folderService = ServiceContainer.Resolve<IFolderService>("folderService");
_userService = ServiceContainer.Resolve<IUserService>("userService"); _userService = ServiceContainer.Resolve<IUserService>("userService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService"); _platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_auditService = ServiceContainer.Resolve<IAuditService>("auditService"); _auditService = ServiceContainer.Resolve<IAuditService>("auditService");
@ -117,6 +120,7 @@ namespace Bit.App.Pages
new KeyValuePair<string, string>(AppResources.Ms, AppResources.Ms), new KeyValuePair<string, string>(AppResources.Ms, AppResources.Ms),
new KeyValuePair<string, string>(AppResources.Dr, AppResources.Dr), new KeyValuePair<string, string>(AppResources.Dr, AppResources.Dr),
}; };
FolderOptions = new List<KeyValuePair<string, string>>();
} }
public Command GeneratePasswordCommand { get; set; } public Command GeneratePasswordCommand { get; set; }
@ -134,6 +138,7 @@ namespace Bit.App.Pages
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 List<KeyValuePair<string, string>> FolderOptions { get; set; }
public ExtendedObservableCollection<LoginUriView> Uris { get; set; } public ExtendedObservableCollection<LoginUriView> Uris { get; set; }
public ExtendedObservableCollection<AddEditPageFieldViewModel> Fields { get; set; } public ExtendedObservableCollection<AddEditPageFieldViewModel> Fields { get; set; }
public int TypeSelectedIndex public int TypeSelectedIndex
@ -172,6 +177,15 @@ namespace Bit.App.Pages
IdentityTitleChanged(); IdentityTitleChanged();
} }
} }
public int FolderSelectedIndex
{
get => _folderSelectedIndex;
set
{
SetProperty(ref _folderSelectedIndex, value);
FolderChanged();
}
}
public CipherView Cipher public CipherView Cipher
{ {
get => _cipher; get => _cipher;
@ -217,54 +231,62 @@ namespace Bit.App.Pages
public async Task LoadAsync() public async Task LoadAsync()
{ {
// TODO: load collections // TODO: load collections
var folders = await _folderService.GetAllDecryptedAsync();
FolderOptions = folders.Select(f => new KeyValuePair<string, string>(f.Name, f.Id)).ToList();
if(EditMode) if(Cipher == null)
{ {
var cipher = await _cipherService.GetAsync(CipherId); if(EditMode)
Cipher = await cipher.DecryptAsync();
if(Cipher.Card != null)
{ {
CardBrandSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.Brand) ? 0 : var cipher = await _cipherService.GetAsync(CipherId);
CardBrandOptions.FindIndex(k => k.Value == Cipher.Card.Brand); Cipher = await cipher.DecryptAsync();
CardExpMonthSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Card.ExpMonth) ? 0 :
CardExpMonthOptions.FindIndex(k => k.Value == Cipher.Card.ExpMonth); FolderSelectedIndex = string.IsNullOrWhiteSpace(Cipher.FolderId) ? FolderOptions.Count - 1 :
FolderOptions.FindIndex(k => k.Value == Cipher.FolderId); ;
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);
}
} }
if(Cipher.Identity != null) else
{ {
IdentityTitleSelectedIndex = string.IsNullOrWhiteSpace(Cipher.Identity.Title) ? 0 : Cipher = new CipherView
IdentityTitleOptions.FindIndex(k => k.Value == Cipher.Identity.Title); {
OrganizationId = OrganizationId,
FolderId = FolderId,
Type = Type.GetValueOrDefault(CipherType.Login),
Login = new LoginView(),
Card = new CardView(),
Identity = new IdentityView(),
SecureNote = new SecureNoteView()
};
Cipher.Login.Uris = new List<LoginUriView> { new LoginUriView() };
Cipher.SecureNote.Type = SecureNoteType.Generic;
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
CardBrandSelectedIndex = 0;
CardExpMonthSelectedIndex = 0;
IdentityTitleSelectedIndex = 0;
FolderSelectedIndex = FolderOptions.Count - 1;
// TODO: org/collection stuff
} }
}
else if(Cipher.Login.Uris != null)
{
Cipher = new CipherView
{ {
OrganizationId = OrganizationId, Uris.ResetWithRange(Cipher.Login.Uris);
FolderId = FolderId, }
Type = Type.GetValueOrDefault(CipherType.Login), if(Cipher.Fields != null)
Login = new LoginView(), {
Card = new CardView(), Fields.ResetWithRange(Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f)));
Identity = new IdentityView(), }
SecureNote = new SecureNoteView()
};
Cipher.Login.Uris = new List<LoginUriView> { new LoginUriView() };
Cipher.SecureNote.Type = SecureNoteType.Generic;
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
CardBrandSelectedIndex = 0;
CardExpMonthSelectedIndex = 0;
IdentityTitleSelectedIndex = 0;
// TODO: org/collection stuff
}
if(Cipher.Login.Uris != null)
{
Uris.ResetWithRange(Cipher.Login.Uris);
}
if(Cipher.Fields != null)
{
Fields.ResetWithRange(Cipher.Fields?.Select(f => new AddEditPageFieldViewModel(f)));
} }
} }
@ -484,6 +506,14 @@ namespace Bit.App.Pages
} }
} }
private void FolderChanged()
{
if(Cipher != null && FolderSelectedIndex > -1)
{
Cipher.FolderId = FolderOptions[FolderSelectedIndex].Value;
}
}
private void TriggerCipherChanged() private void TriggerCipherChanged()
{ {
TriggerPropertyChanged(nameof(Cipher), _additionalCipherProperties); TriggerPropertyChanged(nameof(Cipher), _additionalCipherProperties);

View File

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

View File

@ -1417,4 +1417,7 @@
<data name="MoveUp" xml:space="preserve"> <data name="MoveUp" xml:space="preserve">
<value>Move Up</value> <value>Move Up</value>
</data> </data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root> </root>