1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-22 16:18:21 +01:00

Moved local times to DateTime.Now. Styled sync page with last sync time shown.

This commit is contained in:
Kyle Spearrin 2016-07-30 17:29:04 -04:00
parent ed1cb34cc1
commit a315f36e09
9 changed files with 55 additions and 18 deletions

View File

@ -95,7 +95,7 @@ namespace Bit.App
if(Device.OS == TargetPlatform.Android)
{
_settings.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.UtcNow);
_settings.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.Now);
}
}

View File

@ -8,6 +8,7 @@
public const string SettingLastBackgroundedDate = "lastBackgroundedDate";
public const string SettingLocked = "locked";
public const string SettingLastLoginEmail = "lastLoginEmail";
public const string SettingLastSync = "lastSync";
public const string PasswordGeneratorLength = "pwGenerator:length";
public const string PasswordGeneratorUppercase = "pwGenerator:uppercase";

View File

@ -7,6 +7,7 @@ using Bit.App.Resources;
using Plugin.Connectivity.Abstractions;
using Xamarin.Forms;
using XLabs.Ioc;
using Plugin.Settings.Abstractions;
namespace Bit.App.Pages
{
@ -15,37 +16,64 @@ namespace Bit.App.Pages
private readonly ISyncService _syncService;
private readonly IUserDialogs _userDialogs;
private readonly IConnectivity _connectivity;
private readonly ISettings _settings;
public SettingsSyncPage()
{
_syncService = Resolver.Resolve<ISyncService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_connectivity = Resolver.Resolve<IConnectivity>();
_settings = Resolver.Resolve<ISettings>();
Init();
}
public Label LastSyncLabel { get; set; }
public void Init()
{
var syncButton = new Button
{
Text = "Sync Vault",
Command = new Command(async () => await SyncAsync())
Text = "Sync Vault Now",
Command = new Command(async () => await SyncAsync()),
Style = (Style)Application.Current.Resources["btn-primaryAccent"]
};
var stackLayout = new StackLayout { };
stackLayout.Children.Add(syncButton);
LastSyncLabel = new Label
{
Style = (Style)Application.Current.Resources["text-muted"],
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
HorizontalTextAlignment = TextAlignment.Center
};
SetLastSync();
var stackLayout = new StackLayout
{
VerticalOptions = LayoutOptions.CenterAndExpand,
Children = { syncButton, LastSyncLabel },
Padding = new Thickness(15, 0)
};
Title = "Sync";
Content = stackLayout;
Icon = "fa-refresh";
}
protected override void OnAppearing()
{
base.OnAppearing();
if(!_connectivity.IsConnected)
{
AlertNoConnection();
}
}
private void SetLastSync()
{
var lastSyncDate = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
LastSyncLabel.Text = "Last Sync: " + lastSyncDate?.ToString() ?? "Never";
}
public async Task SyncAsync()
{
if(!_connectivity.IsConnected)
@ -65,6 +93,8 @@ namespace Bit.App.Pages
{
_userDialogs.Toast("Syncing failed.");
}
SetLastSync();
}
public void AlertNoConnection()

View File

@ -153,7 +153,11 @@ namespace Bit.App.Pages
{
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
}
}
protected override void OnAppearing()
{
base.OnAppearing();
if(!_connectivity.IsConnected)
{
AlertNoConnection();

View File

@ -188,7 +188,11 @@ namespace Bit.App.Pages
{
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
}
}
protected override void OnAppearing()
{
base.OnAppearing();
if(!_connectivity.IsConnected)
{
AlertNoConnection();

View File

@ -158,7 +158,7 @@ namespace Bit.App.Pages
Action registerAction = () =>
{
var lastPushRegistration = _settings.GetValueOrDefault<DateTime?>(Constants.PushLastRegistrationDate);
if(!pushPromptShow || !lastPushRegistration.HasValue || (DateTime.UtcNow - lastPushRegistration) > TimeSpan.FromDays(1))
if(!pushPromptShow || !lastPushRegistration.HasValue || (DateTime.Now - lastPushRegistration) > TimeSpan.FromDays(1))
{
_pushNotification.Register();
}

View File

@ -41,7 +41,7 @@ namespace Bit.App.Services
}
// Has it been longer than lockSeconds since the last time the app was backgrounded?
var now = DateTime.UtcNow;
var now = DateTime.Now;
var lastBackground = _settings.GetValueOrDefault(Constants.SettingLastBackgroundedDate, now.AddYears(-1));
if((now - lastBackground).TotalSeconds < lockSeconds)
{

View File

@ -87,7 +87,7 @@ namespace Bit.App.Services
if(response.Succeeded)
{
Debug.WriteLine("Registered device with server.");
_settings.AddOrUpdateValue(Constants.PushLastRegistrationDate, DateTime.UtcNow);
_settings.AddOrUpdateValue(Constants.PushLastRegistrationDate, DateTime.Now);
}
else
{

View File

@ -12,8 +12,6 @@ namespace Bit.App.Services
{
public class SyncService : ISyncService
{
private const string LastSyncKey = "lastSync";
private readonly ICipherApiRepository _cipherApiRepository;
private readonly IFolderApiRepository _folderApiRepository;
private readonly ISiteApiRepository _siteApiRepository;
@ -137,7 +135,7 @@ namespace Bit.App.Services
SyncStarted();
var now = DateTime.UtcNow;
var now = DateTime.Now;
var ciphers = await _cipherApiRepository.GetAsync();
if(!ciphers.Succeeded)
{
@ -162,15 +160,15 @@ namespace Bit.App.Services
return false;
}
_settings.AddOrUpdateValue(LastSyncKey, now);
_settings.AddOrUpdateValue(Constants.SettingLastSync, now);
SyncCompleted(true);
return true;
}
public async Task<bool> IncrementalSyncAsync(TimeSpan syncThreshold)
{
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(LastSyncKey);
if(lastSync != null && DateTime.UtcNow - lastSync.Value < syncThreshold)
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
if(lastSync != null && DateTime.Now - lastSync.Value < syncThreshold)
{
return false;
}
@ -185,8 +183,8 @@ namespace Bit.App.Services
return false;
}
var now = DateTime.UtcNow;
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(LastSyncKey);
var now = DateTime.Now;
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
if(lastSync == null)
{
return await FullSyncAsync();
@ -219,7 +217,7 @@ namespace Bit.App.Services
return false;
}
_settings.AddOrUpdateValue(LastSyncKey, now);
_settings.AddOrUpdateValue(Constants.SettingLastSync, now);
SyncCompleted(true);
return true;
}