2016-05-03 00:50:16 +03:00
|
|
|
|
using System;
|
2016-05-06 07:17:38 +03:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Abstractions;
|
2016-05-11 05:53:34 +03:00
|
|
|
|
using Bit.App.Controls;
|
2016-05-07 20:42:09 +03:00
|
|
|
|
using Bit.App.Resources;
|
2016-05-07 01:49:01 +03:00
|
|
|
|
using Plugin.Connectivity.Abstractions;
|
2016-05-03 00:50:16 +03:00
|
|
|
|
using Xamarin.Forms;
|
2016-05-06 07:17:38 +03:00
|
|
|
|
using XLabs.Ioc;
|
2016-05-03 00:50:16 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
2016-06-28 02:53:31 +03:00
|
|
|
|
public class SyncPage : ExtendedContentPage
|
2016-05-03 00:50:16 +03:00
|
|
|
|
{
|
2016-05-06 07:17:38 +03:00
|
|
|
|
private readonly ISyncService _syncService;
|
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
2016-05-07 01:49:01 +03:00
|
|
|
|
private readonly IConnectivity _connectivity;
|
2016-05-06 07:17:38 +03:00
|
|
|
|
|
2016-05-03 00:50:16 +03:00
|
|
|
|
public SyncPage()
|
|
|
|
|
{
|
2016-05-06 07:17:38 +03:00
|
|
|
|
_syncService = Resolver.Resolve<ISyncService>();
|
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
2016-05-07 01:49:01 +03:00
|
|
|
|
_connectivity = Resolver.Resolve<IConnectivity>();
|
2016-05-06 07:17:38 +03:00
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
|
|
|
|
var syncButton = new Button
|
|
|
|
|
{
|
|
|
|
|
Text = "Sync Vault",
|
2016-05-12 00:30:09 +03:00
|
|
|
|
Command = new Command(async () => await SyncAsync())
|
2016-05-06 07:17:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var stackLayout = new StackLayout { };
|
2016-05-12 00:30:09 +03:00
|
|
|
|
stackLayout.Children.Add(syncButton);
|
2016-05-06 07:17:38 +03:00
|
|
|
|
|
2016-05-03 00:50:16 +03:00
|
|
|
|
Title = "Sync";
|
2016-05-06 07:17:38 +03:00
|
|
|
|
Content = stackLayout;
|
|
|
|
|
Icon = "fa-refresh";
|
2016-05-07 01:49:01 +03:00
|
|
|
|
|
2016-05-12 00:30:09 +03:00
|
|
|
|
if(!_connectivity.IsConnected)
|
2016-05-07 01:49:01 +03:00
|
|
|
|
{
|
|
|
|
|
AlertNoConnection();
|
|
|
|
|
}
|
2016-05-06 07:17:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SyncAsync()
|
|
|
|
|
{
|
2016-05-12 00:30:09 +03:00
|
|
|
|
if(!_connectivity.IsConnected)
|
2016-05-07 01:49:01 +03:00
|
|
|
|
{
|
|
|
|
|
AlertNoConnection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 00:30:09 +03:00
|
|
|
|
_userDialogs.ShowLoading("Syncing...", MaskType.Black);
|
2016-05-06 07:17:38 +03:00
|
|
|
|
var succeeded = await _syncService.SyncAsync();
|
|
|
|
|
_userDialogs.HideLoading();
|
2016-05-12 00:30:09 +03:00
|
|
|
|
if(succeeded)
|
2016-05-06 07:17:38 +03:00
|
|
|
|
{
|
2016-05-12 00:30:09 +03:00
|
|
|
|
_userDialogs.SuccessToast("Syncing complete.");
|
2016-05-06 07:17:38 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-05-12 00:30:09 +03:00
|
|
|
|
_userDialogs.ErrorToast("Syncing failed.");
|
2016-05-06 07:17:38 +03:00
|
|
|
|
}
|
2016-05-03 00:50:16 +03:00
|
|
|
|
}
|
2016-05-07 01:49:01 +03:00
|
|
|
|
|
|
|
|
|
public void AlertNoConnection()
|
|
|
|
|
{
|
2016-05-12 00:30:09 +03:00
|
|
|
|
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
|
2016-05-07 01:49:01 +03:00
|
|
|
|
}
|
2016-05-03 00:50:16 +03:00
|
|
|
|
}
|
|
|
|
|
}
|