mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 01:48:25 +03:00
folder add/edit page
This commit is contained in:
parent
f9473ea61d
commit
291c201b00
7 changed files with 220 additions and 4 deletions
|
@ -41,6 +41,9 @@
|
|||
<Compile Update="Pages\Generator\GeneratorHistoryPage.xaml.cs">
|
||||
<DependentUpon>GeneratorHistoryPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Pages\Settings\FolderAddEditPage.xaml.cs">
|
||||
<DependentUpon>FolderAddEditPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Pages\Settings\FoldersPage.xaml.cs">
|
||||
<DependentUpon>FoldersPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
40
src/App/Pages/Settings/FolderAddEditPage.xaml
Normal file
40
src/App/Pages/Settings/FolderAddEditPage.xaml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<pages:BaseContentPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Bit.App.Pages.FolderAddEditPage"
|
||||
xmlns:pages="clr-namespace:Bit.App.Pages"
|
||||
xmlns:u="clr-namespace:Bit.App.Utilities"
|
||||
x:DataType="pages:FolderAddEditPageViewModel"
|
||||
x:Name="_page"
|
||||
Title="{Binding PageTitle}">
|
||||
<ContentPage.BindingContext>
|
||||
<pages:FolderAddEditPageViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Text="{u:I18n Save}" Clicked="Save_Clicked" Order="Primary" />
|
||||
<ToolbarItem Text="{u:I18n Delete}"
|
||||
Clicked="Delete_Clicked"
|
||||
Order="Secondary"
|
||||
IsDestructive="True"
|
||||
x:Name="_deleteItem" />
|
||||
</ContentPage.ToolbarItems>
|
||||
|
||||
<ScrollView x:Name="_scrollView">
|
||||
<StackLayout Spacing="20">
|
||||
<StackLayout StyleClass="box">
|
||||
<StackLayout StyleClass="box-row, box-row-input">
|
||||
<Label
|
||||
Text="{u:I18n Name}"
|
||||
StyleClass="box-label" />
|
||||
<Entry
|
||||
Text="{Binding Folder.Name}"
|
||||
StyleClass="box-value"
|
||||
x:Name="_nameEntry" />
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
</pages:BaseContentPage>
|
51
src/App/Pages/Settings/FolderAddEditPage.xaml.cs
Normal file
51
src/App/Pages/Settings/FolderAddEditPage.xaml.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
namespace Bit.App.Pages
|
||||
{
|
||||
public partial class FolderAddEditPage : BaseContentPage
|
||||
{
|
||||
private FolderAddEditPageViewModel _vm;
|
||||
|
||||
public FolderAddEditPage(
|
||||
string folderId = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
_vm = BindingContext as FolderAddEditPageViewModel;
|
||||
_vm.Page = this;
|
||||
_vm.FolderId = folderId;
|
||||
_vm.Init();
|
||||
SetActivityIndicator();
|
||||
if(!_vm.EditMode)
|
||||
{
|
||||
ToolbarItems.Remove(_deleteItem);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
await LoadOnAppearedAsync(_scrollView, true, async () =>
|
||||
{
|
||||
await _vm.LoadAsync();
|
||||
if(!_vm.EditMode)
|
||||
{
|
||||
RequestFocus(_nameEntry);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async void Save_Clicked(object sender, System.EventArgs e)
|
||||
{
|
||||
if(DoOnce())
|
||||
{
|
||||
await _vm.SubmitAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async void Delete_Clicked(object sender, System.EventArgs e)
|
||||
{
|
||||
if(DoOnce())
|
||||
{
|
||||
await _vm.DeleteAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
109
src/App/Pages/Settings/FolderAddEditPageViewModel.cs
Normal file
109
src/App/Pages/Settings/FolderAddEditPageViewModel.cs
Normal file
|
@ -0,0 +1,109 @@
|
|||
using Bit.App.Abstractions;
|
||||
using Bit.App.Resources;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Utilities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
public class FolderAddEditPageViewModel : BaseViewModel
|
||||
{
|
||||
private readonly IDeviceActionService _deviceActionService;
|
||||
private readonly IFolderService _folderService;
|
||||
private readonly IPlatformUtilsService _platformUtilsService;
|
||||
private FolderView _folder;
|
||||
|
||||
public FolderAddEditPageViewModel()
|
||||
{
|
||||
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||
_folderService = ServiceContainer.Resolve<IFolderService>("folderService");
|
||||
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
|
||||
}
|
||||
|
||||
public string FolderId { get; set; }
|
||||
public FolderView Folder
|
||||
{
|
||||
get => _folder;
|
||||
set => SetProperty(ref _folder, value);
|
||||
}
|
||||
public bool EditMode => !string.IsNullOrWhiteSpace(FolderId);
|
||||
|
||||
public void Init()
|
||||
{
|
||||
PageTitle = EditMode ? AppResources.EditFolder : AppResources.AddFolder;
|
||||
}
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
if(Folder == null)
|
||||
{
|
||||
if(EditMode)
|
||||
{
|
||||
var folder = await _folderService.GetAsync(FolderId);
|
||||
Folder = await folder.DecryptAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Folder = new FolderView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> SubmitAsync()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Folder.Name))
|
||||
{
|
||||
await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
|
||||
string.Format(AppResources.ValidationFieldRequired, AppResources.Name),
|
||||
AppResources.Ok);
|
||||
return false;
|
||||
}
|
||||
|
||||
var folder = await _folderService.EncryptAsync(Folder);
|
||||
try
|
||||
{
|
||||
await _deviceActionService.ShowLoadingAsync(AppResources.Saving);
|
||||
await _folderService.SaveWithServerAsync(folder);
|
||||
Folder.Id = folder.Id;
|
||||
await _deviceActionService.HideLoadingAsync();
|
||||
_platformUtilsService.ShowToast("success", null,
|
||||
EditMode ? AppResources.FolderUpdated : AppResources.FolderCreated);
|
||||
await Page.Navigation.PopModalAsync();
|
||||
return true;
|
||||
}
|
||||
catch(ApiException e)
|
||||
{
|
||||
await _deviceActionService.HideLoadingAsync();
|
||||
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync()
|
||||
{
|
||||
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete,
|
||||
null, AppResources.Yes, AppResources.No);
|
||||
if(!confirmed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
await _deviceActionService.ShowLoadingAsync(AppResources.Deleting);
|
||||
await _folderService.DeleteWithServerAsync(Folder.Id);
|
||||
await _deviceActionService.HideLoadingAsync();
|
||||
_platformUtilsService.ShowToast("success", null, AppResources.FolderDeleted);
|
||||
await Page.Navigation.PopModalAsync();
|
||||
return true;
|
||||
}
|
||||
catch(ApiException e)
|
||||
{
|
||||
await _deviceActionService.HideLoadingAsync();
|
||||
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@
|
|||
ItemsSource="{Binding Folders}"
|
||||
VerticalOptions="FillAndExpand"
|
||||
CachingStrategy="RecycleElement"
|
||||
SelectedItem="Row_Selected"
|
||||
ItemSelected="RowSelected"
|
||||
StyleClass="list, list-platform">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="views:FolderView">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Bit.Core.Models.View;
|
||||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
|
@ -35,12 +36,23 @@ namespace Bit.App.Pages
|
|||
|
||||
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
|
||||
((ListView)sender).SelectedItem = null;
|
||||
if(!DoOnce())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!(e.SelectedItem is FolderView folder))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var page = new FolderAddEditPage(folder.Id);
|
||||
await Navigation.PushModalAsync(new NavigationPage(page));
|
||||
}
|
||||
|
||||
private async void AddButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var page = new FolderAddEditPage();
|
||||
await Navigation.PushModalAsync(new NavigationPage(page));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -408,6 +408,7 @@ namespace Bit.App.Pages
|
|||
await _deviceActionService.HideLoadingAsync();
|
||||
_platformUtilsService.ShowToast("success", null, AppResources.ItemDeleted);
|
||||
_messagingService.Send("deletedCipher");
|
||||
await Page.Navigation.PopModalAsync();
|
||||
return true;
|
||||
}
|
||||
catch(ApiException e)
|
||||
|
|
Loading…
Reference in a new issue