1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-11 05:43:30 +00:00

Feature sync on refresh (#937)

* Added new option: Sync on refresh

* Removed unused field

* Fixed refreshing on disappearing & unnecessary codes removed

* Requested changes

* Calling storage service instead of a dedicated service function (mobile-specific)
This commit is contained in:
aaxdev
2020-08-05 19:19:27 +02:00
committed by GitHub
parent c5a71c4304
commit 3b4ef4d238
9 changed files with 4338 additions and 2786 deletions

View File

@@ -1,5 +1,6 @@
using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;
@@ -11,25 +12,56 @@ namespace Bit.App.Pages
{
private readonly IDeviceActionService _deviceActionService;
private readonly IPlatformUtilsService _platformUtilsService;
private readonly IStorageService _storageService;
private readonly ISyncService _syncService;
private string _lastSync = "--";
private bool _inited;
private bool _syncOnRefresh;
public SyncPageViewModel()
{
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
PageTitle = AppResources.Sync;
}
public bool EnableSyncOnRefresh
{
get => _syncOnRefresh;
set
{
if (SetProperty(ref _syncOnRefresh, value))
{
var task = UpdateSyncOnRefreshAsync();
}
}
}
public string LastSync
{
get => _lastSync;
set => SetProperty(ref _lastSync, value);
}
public async Task InitAsync()
{
await SetLastSyncAsync();
EnableSyncOnRefresh = await _storageService.GetAsync<bool>(Constants.SyncOnRefreshKey);
_inited = true;
}
public async Task UpdateSyncOnRefreshAsync()
{
if (_inited)
{
await _storageService.SaveAsync(Constants.SyncOnRefreshKey, _syncOnRefresh);
}
}
public async Task SetLastSyncAsync()
{
var last = await _syncService.GetLastSyncAsync();