mirror of
https://github.com/bitwarden/android.git
synced 2024-12-20 08:12:26 +03:00
Moved local times to DateTime.Now. Styled sync page with last sync time shown.
This commit is contained in:
parent
ed1cb34cc1
commit
a315f36e09
9 changed files with 55 additions and 18 deletions
|
@ -95,7 +95,7 @@ namespace Bit.App
|
||||||
|
|
||||||
if(Device.OS == TargetPlatform.Android)
|
if(Device.OS == TargetPlatform.Android)
|
||||||
{
|
{
|
||||||
_settings.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.UtcNow);
|
_settings.AddOrUpdateValue(Constants.SettingLastBackgroundedDate, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
public const string SettingLastBackgroundedDate = "lastBackgroundedDate";
|
public const string SettingLastBackgroundedDate = "lastBackgroundedDate";
|
||||||
public const string SettingLocked = "locked";
|
public const string SettingLocked = "locked";
|
||||||
public const string SettingLastLoginEmail = "lastLoginEmail";
|
public const string SettingLastLoginEmail = "lastLoginEmail";
|
||||||
|
public const string SettingLastSync = "lastSync";
|
||||||
|
|
||||||
public const string PasswordGeneratorLength = "pwGenerator:length";
|
public const string PasswordGeneratorLength = "pwGenerator:length";
|
||||||
public const string PasswordGeneratorUppercase = "pwGenerator:uppercase";
|
public const string PasswordGeneratorUppercase = "pwGenerator:uppercase";
|
||||||
|
|
|
@ -7,6 +7,7 @@ using Bit.App.Resources;
|
||||||
using Plugin.Connectivity.Abstractions;
|
using Plugin.Connectivity.Abstractions;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using XLabs.Ioc;
|
using XLabs.Ioc;
|
||||||
|
using Plugin.Settings.Abstractions;
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
|
@ -15,37 +16,64 @@ namespace Bit.App.Pages
|
||||||
private readonly ISyncService _syncService;
|
private readonly ISyncService _syncService;
|
||||||
private readonly IUserDialogs _userDialogs;
|
private readonly IUserDialogs _userDialogs;
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
|
private readonly ISettings _settings;
|
||||||
|
|
||||||
public SettingsSyncPage()
|
public SettingsSyncPage()
|
||||||
{
|
{
|
||||||
_syncService = Resolver.Resolve<ISyncService>();
|
_syncService = Resolver.Resolve<ISyncService>();
|
||||||
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
||||||
_connectivity = Resolver.Resolve<IConnectivity>();
|
_connectivity = Resolver.Resolve<IConnectivity>();
|
||||||
|
_settings = Resolver.Resolve<ISettings>();
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Label LastSyncLabel { get; set; }
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
var syncButton = new Button
|
var syncButton = new Button
|
||||||
{
|
{
|
||||||
Text = "Sync Vault",
|
Text = "Sync Vault Now",
|
||||||
Command = new Command(async () => await SyncAsync())
|
Command = new Command(async () => await SyncAsync()),
|
||||||
|
Style = (Style)Application.Current.Resources["btn-primaryAccent"]
|
||||||
};
|
};
|
||||||
|
|
||||||
var stackLayout = new StackLayout { };
|
LastSyncLabel = new Label
|
||||||
stackLayout.Children.Add(syncButton);
|
{
|
||||||
|
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";
|
Title = "Sync";
|
||||||
Content = stackLayout;
|
Content = stackLayout;
|
||||||
Icon = "fa-refresh";
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
{
|
{
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetLastSync()
|
||||||
|
{
|
||||||
|
var lastSyncDate = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
|
||||||
|
LastSyncLabel.Text = "Last Sync: " + lastSyncDate?.ToString() ?? "Never";
|
||||||
|
}
|
||||||
|
|
||||||
public async Task SyncAsync()
|
public async Task SyncAsync()
|
||||||
{
|
{
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
|
@ -65,6 +93,8 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
_userDialogs.Toast("Syncing failed.");
|
_userDialogs.Toast("Syncing failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetLastSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AlertNoConnection()
|
public void AlertNoConnection()
|
||||||
|
|
|
@ -153,7 +153,11 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
{
|
{
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
|
|
|
@ -188,7 +188,11 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
ToolbarItems.Add(new DismissModalToolBarItem(this, "Cancel"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
if(!_connectivity.IsConnected)
|
if(!_connectivity.IsConnected)
|
||||||
{
|
{
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
|
|
|
@ -158,7 +158,7 @@ namespace Bit.App.Pages
|
||||||
Action registerAction = () =>
|
Action registerAction = () =>
|
||||||
{
|
{
|
||||||
var lastPushRegistration = _settings.GetValueOrDefault<DateTime?>(Constants.PushLastRegistrationDate);
|
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();
|
_pushNotification.Register();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Bit.App.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has it been longer than lockSeconds since the last time the app was backgrounded?
|
// 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));
|
var lastBackground = _settings.GetValueOrDefault(Constants.SettingLastBackgroundedDate, now.AddYears(-1));
|
||||||
if((now - lastBackground).TotalSeconds < lockSeconds)
|
if((now - lastBackground).TotalSeconds < lockSeconds)
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,7 +87,7 @@ namespace Bit.App.Services
|
||||||
if(response.Succeeded)
|
if(response.Succeeded)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Registered device with server.");
|
Debug.WriteLine("Registered device with server.");
|
||||||
_settings.AddOrUpdateValue(Constants.PushLastRegistrationDate, DateTime.UtcNow);
|
_settings.AddOrUpdateValue(Constants.PushLastRegistrationDate, DateTime.Now);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,8 +12,6 @@ namespace Bit.App.Services
|
||||||
{
|
{
|
||||||
public class SyncService : ISyncService
|
public class SyncService : ISyncService
|
||||||
{
|
{
|
||||||
private const string LastSyncKey = "lastSync";
|
|
||||||
|
|
||||||
private readonly ICipherApiRepository _cipherApiRepository;
|
private readonly ICipherApiRepository _cipherApiRepository;
|
||||||
private readonly IFolderApiRepository _folderApiRepository;
|
private readonly IFolderApiRepository _folderApiRepository;
|
||||||
private readonly ISiteApiRepository _siteApiRepository;
|
private readonly ISiteApiRepository _siteApiRepository;
|
||||||
|
@ -137,7 +135,7 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
SyncStarted();
|
SyncStarted();
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.Now;
|
||||||
var ciphers = await _cipherApiRepository.GetAsync();
|
var ciphers = await _cipherApiRepository.GetAsync();
|
||||||
if(!ciphers.Succeeded)
|
if(!ciphers.Succeeded)
|
||||||
{
|
{
|
||||||
|
@ -162,15 +160,15 @@ namespace Bit.App.Services
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_settings.AddOrUpdateValue(LastSyncKey, now);
|
_settings.AddOrUpdateValue(Constants.SettingLastSync, now);
|
||||||
SyncCompleted(true);
|
SyncCompleted(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IncrementalSyncAsync(TimeSpan syncThreshold)
|
public async Task<bool> IncrementalSyncAsync(TimeSpan syncThreshold)
|
||||||
{
|
{
|
||||||
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(LastSyncKey);
|
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
|
||||||
if(lastSync != null && DateTime.UtcNow - lastSync.Value < syncThreshold)
|
if(lastSync != null && DateTime.Now - lastSync.Value < syncThreshold)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -185,8 +183,8 @@ namespace Bit.App.Services
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.Now;
|
||||||
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(LastSyncKey);
|
DateTime? lastSync = _settings.GetValueOrDefault<DateTime?>(Constants.SettingLastSync);
|
||||||
if(lastSync == null)
|
if(lastSync == null)
|
||||||
{
|
{
|
||||||
return await FullSyncAsync();
|
return await FullSyncAsync();
|
||||||
|
@ -219,7 +217,7 @@ namespace Bit.App.Services
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_settings.AddOrUpdateValue(LastSyncKey, now);
|
_settings.AddOrUpdateValue(Constants.SettingLastSync, now);
|
||||||
SyncCompleted(true);
|
SyncCompleted(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue