bitwarden-android/src/App/Pages/SyncPage.cs

84 lines
2.3 KiB
C#
Raw Normal View History

2016-05-03 00:50:16 +03:00
using System;
using System.Threading.Tasks;
using Acr.UserDialogs;
using Bit.App.Abstractions;
using Bit.App.Controls;
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;
using XLabs.Ioc;
2016-05-03 00:50:16 +03:00
namespace Bit.App.Pages
{
public class SyncPage : ContentPage
{
private readonly ISyncService _syncService;
private readonly IUserDialogs _userDialogs;
2016-05-07 01:49:01 +03:00
private readonly IConnectivity _connectivity;
2016-05-03 00:50:16 +03:00
public SyncPage()
{
_syncService = Resolver.Resolve<ISyncService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
2016-05-07 01:49:01 +03:00
_connectivity = Resolver.Resolve<IConnectivity>();
Init();
}
public void Init()
{
var syncButton = new Button
{
Text = "Sync Vault",
Command = new Command( async () => await SyncAsync() )
};
var stackLayout = new StackLayout { };
stackLayout.Children.Add( syncButton );
stackLayout.Children.Add( new ExtendedEntry
{
BottomBorderColor = Color.Black,
HasBorder = true,
HasOnlyBottomBorder = true,
Placeholder = "Some placeholder",
PlaceholderColor = Color.Red
} );
2016-05-03 00:50:16 +03:00
Title = "Sync";
Content = stackLayout;
Icon = "fa-refresh";
2016-05-07 01:49:01 +03:00
if( !_connectivity.IsConnected )
2016-05-07 01:49:01 +03:00
{
AlertNoConnection();
}
}
public async Task SyncAsync()
{
if( !_connectivity.IsConnected )
2016-05-07 01:49:01 +03:00
{
AlertNoConnection();
return;
}
_userDialogs.ShowLoading( "Syncing...", MaskType.Black );
var succeeded = await _syncService.SyncAsync();
_userDialogs.HideLoading();
if( succeeded )
{
_userDialogs.SuccessToast( "Syncing complete." );
}
else
{
_userDialogs.ErrorToast( "Syncing failed." );
}
2016-05-03 00:50:16 +03:00
}
2016-05-07 01:49:01 +03:00
public void AlertNoConnection()
{
DisplayAlert( AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok );
2016-05-07 01:49:01 +03:00
}
2016-05-03 00:50:16 +03:00
}
}