stub sync page

This commit is contained in:
Kyle Spearrin 2019-05-14 12:05:30 -04:00
parent ff1f895476
commit 879b5ef3aa
5 changed files with 95 additions and 3 deletions

View File

@ -41,6 +41,9 @@
<Compile Update="Pages\Generator\GeneratorHistoryPage.xaml.cs">
<DependentUpon>GeneratorHistoryPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Settings\SyncPage.xaml.cs">
<DependentUpon>SyncPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\Vault\AttachmentsPage.xaml.cs">
<DependentUpon>AttachmentsPage.xaml</DependentUpon>
</Compile>

View File

@ -1,4 +1,5 @@
using System;
using Bit.App.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -19,7 +20,7 @@ namespace Bit.App.Pages
_vm.Page = this;
}
private void RowSelected(object sender, SelectedItemChangedEventArgs e)
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
{
((ListView)sender).SelectedItem = null;
if(!DoOnce())
@ -31,7 +32,10 @@ namespace Bit.App.Pages
return;
}
// TODO
if(item.Name == AppResources.Sync)
{
await Navigation.PushModalAsync(new NavigationPage(new SyncPage()));
}
}
}
}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<pages:BaseContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
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}">
<ContentPage.BindingContext>
<pages:SyncPageViewModel />
</ContentPage.BindingContext>
<StackLayout Spacing="0" Padding="10, 5">
<Button Text="{u:I18n SyncVaultNow}"
Clicked="Sync_Clicked"></Button>
</StackLayout>
</pages:BaseContentPage>

View File

@ -0,0 +1,24 @@
using System;
namespace Bit.App.Pages
{
public partial class SyncPage : BaseContentPage
{
private readonly SyncPageViewModel _vm;
public SyncPage()
{
InitializeComponent();
_vm = BindingContext as SyncPageViewModel;
_vm.Page = this;
}
private async void Sync_Clicked(object sender, EventArgs e)
{
if(DoOnce())
{
await _vm.SyncAsync();
}
}
}
}

View File

@ -0,0 +1,41 @@
using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;
using System.Threading.Tasks;
namespace Bit.App.Pages
{
public class SyncPageViewModel : BaseViewModel
{
private readonly IDeviceActionService _deviceActionService;
private readonly IPlatformUtilsService _platformUtilsService;
private readonly ISyncService _syncService;
public SyncPageViewModel()
{
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
PageTitle = AppResources.Sync;
}
public async Task SyncAsync()
{
try
{
await _deviceActionService.ShowLoadingAsync(AppResources.Syncing);
await _syncService.FullSyncAsync(true);
await _deviceActionService.HideLoadingAsync();
_platformUtilsService.ShowToast("success", null, AppResources.SyncingComplete);
}
catch(ApiException e)
{
await _deviceActionService.HideLoadingAsync();
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
}
}
}
}