mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 01:48:25 +03:00
sync page details
This commit is contained in:
parent
879b5ef3aa
commit
b68031bd11
3 changed files with 51 additions and 4 deletions
|
@ -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 @@
|
|||
<pages:SyncPageViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
|
||||
<StackLayout Spacing="0" Padding="10, 5">
|
||||
<StackLayout Spacing="10"
|
||||
Padding="10, 5"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="FillAndExpand">
|
||||
<Button Text="{u:I18n SyncVaultNow}"
|
||||
Clicked="Sync_Clicked"></Button>
|
||||
<Label StyleClass="text-muted, text-sm" HorizontalTextAlignment="Center">
|
||||
<Label.FormattedText>
|
||||
<FormattedString>
|
||||
<Span Text="{u:I18n LastSync}" />
|
||||
<Span Text=" " />
|
||||
<Span Text="{Binding LastSync}" />
|
||||
</FormattedString>
|
||||
</Label.FormattedText>
|
||||
</Label>
|
||||
</StackLayout>
|
||||
|
||||
</pages:BaseContentPage>
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace Bit.App.Pages
|
|||
private readonly IPlatformUtilsService _platformUtilsService;
|
||||
private readonly ISyncService _syncService;
|
||||
|
||||
private string _lastSync = "--";
|
||||
|
||||
public SyncPageViewModel()
|
||||
{
|
||||
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue