2016-05-18 06:09:20 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Controls;
|
|
|
|
|
using Bit.App.Models;
|
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Plugin.Connectivity.Abstractions;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using XLabs.Ioc;
|
2016-07-20 01:46:39 +03:00
|
|
|
|
using System.Linq;
|
2016-05-18 06:09:20 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
2016-06-28 02:53:31 +03:00
|
|
|
|
public class SettingsAddFolderPage : ExtendedContentPage
|
2016-05-18 06:09:20 +03:00
|
|
|
|
{
|
|
|
|
|
private readonly IFolderService _folderService;
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
|
|
|
|
private readonly IConnectivity _connectivity;
|
2016-08-05 02:35:56 +03:00
|
|
|
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
2016-05-18 06:09:20 +03:00
|
|
|
|
|
|
|
|
|
public SettingsAddFolderPage()
|
|
|
|
|
{
|
|
|
|
|
_folderService = Resolver.Resolve<IFolderService>();
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
|
|
|
_connectivity = Resolver.Resolve<IConnectivity>();
|
2016-08-05 02:35:56 +03:00
|
|
|
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
2016-05-18 06:09:20 +03:00
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
|
|
|
|
var nameCell = new FormEntryCell(AppResources.Name);
|
|
|
|
|
|
2016-05-24 06:48:34 +03:00
|
|
|
|
var table = new ExtendedTableView
|
2016-05-18 06:09:20 +03:00
|
|
|
|
{
|
|
|
|
|
Intent = TableIntent.Settings,
|
|
|
|
|
EnableScrolling = false,
|
|
|
|
|
HasUnevenRows = true,
|
|
|
|
|
Root = new TableRoot
|
|
|
|
|
{
|
|
|
|
|
new TableSection()
|
|
|
|
|
{
|
|
|
|
|
nameCell
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(Device.OS == TargetPlatform.iOS)
|
|
|
|
|
{
|
2016-05-24 06:48:34 +03:00
|
|
|
|
table.RowHeight = -1;
|
|
|
|
|
table.EstimatedRowHeight = 70;
|
2016-05-18 06:09:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
|
|
|
|
{
|
|
|
|
|
if(!_connectivity.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
AlertNoConnection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(nameCell.Entry.Text))
|
|
|
|
|
{
|
|
|
|
|
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var folder = new Folder
|
|
|
|
|
{
|
|
|
|
|
Name = nameCell.Entry.Text.Encrypt()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var saveTask = _folderService.SaveAsync(folder);
|
|
|
|
|
_userDialogs.ShowLoading("Saving...", MaskType.Black);
|
|
|
|
|
await saveTask;
|
|
|
|
|
|
|
|
|
|
_userDialogs.HideLoading();
|
2016-07-20 01:46:39 +03:00
|
|
|
|
|
|
|
|
|
if(saveTask.Result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PopModalAsync();
|
2016-07-26 07:38:41 +03:00
|
|
|
|
_userDialogs.Toast("New folder created.");
|
2016-08-05 02:35:56 +03:00
|
|
|
|
_googleAnalyticsService.TrackAppEvent("CreatedFolder");
|
2016-07-20 01:46:39 +03:00
|
|
|
|
}
|
|
|
|
|
else if(saveTask.Result.Errors.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred);
|
|
|
|
|
}
|
2016-07-31 01:16:09 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
|
|
|
|
|
}
|
2016-05-18 06:09:20 +03:00
|
|
|
|
}, ToolbarItemOrder.Default, 0);
|
|
|
|
|
|
|
|
|
|
Title = "Add Folder";
|
2016-05-24 06:48:34 +03:00
|
|
|
|
Content = table;
|
2016-05-18 06:09:20 +03:00
|
|
|
|
ToolbarItems.Add(saveToolBarItem);
|
|
|
|
|
if(Device.OS == TargetPlatform.iOS)
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
|
|
|
|
}
|
2016-07-30 23:39:52 +03:00
|
|
|
|
}
|
2016-05-18 06:09:20 +03:00
|
|
|
|
|
2016-07-30 23:39:52 +03:00
|
|
|
|
protected override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2016-05-18 06:09:20 +03:00
|
|
|
|
if(!_connectivity.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
AlertNoConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AlertNoConnection()
|
|
|
|
|
{
|
|
|
|
|
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|