diff --git a/src/App/App.cs b/src/App/App.cs index 6e05a5bc3..6d47caba1 100644 --- a/src/App/App.cs +++ b/src/App/App.cs @@ -95,7 +95,7 @@ namespace Bit.App if(Device.OS == TargetPlatform.Android) { - _settings.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.UtcNow); + _settings.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.Now); } } diff --git a/src/App/Constants.cs b/src/App/Constants.cs index 8a90bcdc7..8f6654318 100644 --- a/src/App/Constants.cs +++ b/src/App/Constants.cs @@ -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"; diff --git a/src/App/Pages/Settings/SettingsSyncPage.cs b/src/App/Pages/Settings/SettingsSyncPage.cs index 0343a620a..1be421ba7 100644 --- a/src/App/Pages/Settings/SettingsSyncPage.cs +++ b/src/App/Pages/Settings/SettingsSyncPage.cs @@ -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(); _userDialogs = Resolver.Resolve(); _connectivity = Resolver.Resolve(); + _settings = Resolver.Resolve(); 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(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() diff --git a/src/App/Pages/Vault/VaultAddSitePage.cs b/src/App/Pages/Vault/VaultAddSitePage.cs index 81a9fa029..9c7d94c11 100644 --- a/src/App/Pages/Vault/VaultAddSitePage.cs +++ b/src/App/Pages/Vault/VaultAddSitePage.cs @@ -153,7 +153,11 @@ namespace Bit.App.Pages { ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel")); } + } + protected override void OnAppearing() + { + base.OnAppearing(); if(!_connectivity.IsConnected) { AlertNoConnection(); diff --git a/src/App/Pages/Vault/VaultEditSitePage.cs b/src/App/Pages/Vault/VaultEditSitePage.cs index 3841fc0a1..b3fabbc69 100644 --- a/src/App/Pages/Vault/VaultEditSitePage.cs +++ b/src/App/Pages/Vault/VaultEditSitePage.cs @@ -188,7 +188,11 @@ namespace Bit.App.Pages { ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel")); } + } + protected override void OnAppearing() + { + base.OnAppearing(); if(!_connectivity.IsConnected) { AlertNoConnection(); diff --git a/src/App/Pages/Vault/VaultListSitesPage.cs b/src/App/Pages/Vault/VaultListSitesPage.cs index 4db32ddc9..04df13254 100644 --- a/src/App/Pages/Vault/VaultListSitesPage.cs +++ b/src/App/Pages/Vault/VaultListSitesPage.cs @@ -158,7 +158,7 @@ namespace Bit.App.Pages Action registerAction = () => { var lastPushRegistration = _settings.GetValueOrDefault(Constants.PushLastRegistrationDate); - if(!pushPromptShow || !lastPushRegistration.HasValue || (DateTime.UtcNow - lastPushRegistration) > TimeSpan.FromDays(1)) + if(!pushPromptShow || !lastPushRegistration.HasValue || (DateTime.Now - lastPushRegistration) > TimeSpan.FromDays(1)) { _pushNotification.Register(); } diff --git a/src/App/Services/LockService.cs b/src/App/Services/LockService.cs index 6d2012e9e..26e57a075 100644 --- a/src/App/Services/LockService.cs +++ b/src/App/Services/LockService.cs @@ -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) { diff --git a/src/App/Services/PushNotificationListener.cs b/src/App/Services/PushNotificationListener.cs index c792be46b..5d681058d 100644 --- a/src/App/Services/PushNotificationListener.cs +++ b/src/App/Services/PushNotificationListener.cs @@ -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 { diff --git a/src/App/Services/SyncService.cs b/src/App/Services/SyncService.cs index 604b670fe..30b7ff922 100644 --- a/src/App/Services/SyncService.cs +++ b/src/App/Services/SyncService.cs @@ -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 IncrementalSyncAsync(TimeSpan syncThreshold) { - DateTime? lastSync = _settings.GetValueOrDefault(LastSyncKey); - if(lastSync != null && DateTime.UtcNow - lastSync.Value < syncThreshold) + DateTime? lastSync = _settings.GetValueOrDefault(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(LastSyncKey); + var now = DateTime.Now; + DateTime? lastSync = _settings.GetValueOrDefault(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; }