From b68031bd11500df08f323d31d7ec9dbbd921cf5f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 14 May 2019 16:36:54 -0400 Subject: [PATCH] sync page details --- src/App/Pages/Settings/SyncPage.xaml | 15 +++++++-- src/App/Pages/Settings/SyncPage.xaml.cs | 6 ++++ src/App/Pages/Settings/SyncPageViewModel.cs | 34 +++++++++++++++++++-- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/App/Pages/Settings/SyncPage.xaml b/src/App/Pages/Settings/SyncPage.xaml index 7faf7bb8f..e5a7242a3 100644 --- a/src/App/Pages/Settings/SyncPage.xaml +++ b/src/App/Pages/Settings/SyncPage.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Bit.App.Pages.SyncPage" xmlns:pages="clr-namespace:Bit.App.Pages" - xmlns:controls="clr-namespace:Bit.App.Controls" xmlns:u="clr-namespace:Bit.App.Utilities" x:DataType="pages:SyncPageViewModel" Title="{Binding PageTitle}"> @@ -12,9 +11,21 @@ - + + diff --git a/src/App/Pages/Settings/SyncPage.xaml.cs b/src/App/Pages/Settings/SyncPage.xaml.cs index a03d44a69..f9d1ce01a 100644 --- a/src/App/Pages/Settings/SyncPage.xaml.cs +++ b/src/App/Pages/Settings/SyncPage.xaml.cs @@ -13,6 +13,12 @@ namespace Bit.App.Pages _vm.Page = this; } + protected async override void OnAppearing() + { + base.OnAppearing(); + await _vm.SetLastSyncAsync(); + } + private async void Sync_Clicked(object sender, EventArgs e) { if(DoOnce()) diff --git a/src/App/Pages/Settings/SyncPageViewModel.cs b/src/App/Pages/Settings/SyncPageViewModel.cs index a360acb94..87ae4bae9 100644 --- a/src/App/Pages/Settings/SyncPageViewModel.cs +++ b/src/App/Pages/Settings/SyncPageViewModel.cs @@ -13,6 +13,8 @@ namespace Bit.App.Pages private readonly IPlatformUtilsService _platformUtilsService; private readonly ISyncService _syncService; + private string _lastSync = "--"; + public SyncPageViewModel() { _deviceActionService = ServiceContainer.Resolve("deviceActionService"); @@ -22,14 +24,42 @@ namespace Bit.App.Pages PageTitle = AppResources.Sync; } + public string LastSync + { + get => _lastSync; + set => SetProperty(ref _lastSync, value); + } + + public async Task SetLastSyncAsync() + { + var last = await _syncService.GetLastSyncAsync(); + if(last != null) + { + var localDate = last.Value.ToLocalTime(); + LastSync = string.Format("{0} {1}", localDate.ToShortDateString(), localDate.ToShortTimeString()); + } + else + { + LastSync = AppResources.Never; + } + } + public async Task SyncAsync() { try { await _deviceActionService.ShowLoadingAsync(AppResources.Syncing); - await _syncService.FullSyncAsync(true); + var success = await _syncService.FullSyncAsync(true); await _deviceActionService.HideLoadingAsync(); - _platformUtilsService.ShowToast("success", null, AppResources.SyncingComplete); + if(success) + { + await SetLastSyncAsync(); + _platformUtilsService.ShowToast("success", null, AppResources.SyncingComplete); + } + else + { + await Page.DisplayAlert(null, AppResources.SyncingFailed, AppResources.Ok); + } } catch(ApiException e) {