IsBusy on syncing

This commit is contained in:
Kyle Spearrin 2019-06-05 09:39:30 -04:00
parent 65f2ea1df2
commit 9d86fac103
2 changed files with 29 additions and 3 deletions

View file

@ -65,13 +65,23 @@ namespace Bit.App.Pages
protected async override void OnAppearing() protected async override void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
if(_syncService.SyncInProgress)
{
IsBusy = true;
}
_broadcasterService.Subscribe(_pageName, async (message) => _broadcasterService.Subscribe(_pageName, async (message) =>
{ {
if(message.Command == "syncCompleted") if(message.Command == "syncStarted")
{
Device.BeginInvokeOnMainThread(() => IsBusy = true);
}
else if(message.Command == "syncCompleted")
{ {
await Task.Delay(500); await Task.Delay(500);
Device.BeginInvokeOnMainThread(() => Device.BeginInvokeOnMainThread(() =>
{ {
IsBusy = false;
var task = _vm.LoadAsync(); var task = _vm.LoadAsync();
}); });
} }
@ -156,6 +166,7 @@ namespace Bit.App.Pages
protected override void OnDisappearing() protected override void OnDisappearing()
{ {
base.OnDisappearing(); base.OnDisappearing();
IsBusy = false;
_broadcasterService.Unsubscribe(_pageName); _broadcasterService.Unsubscribe(_pageName);
} }

View file

@ -1,6 +1,7 @@
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
using Xamarin.Forms; using Xamarin.Forms;
namespace Bit.App.Pages namespace Bit.App.Pages
@ -8,12 +9,14 @@ namespace Bit.App.Pages
public partial class ViewPage : BaseContentPage public partial class ViewPage : BaseContentPage
{ {
private readonly IBroadcasterService _broadcasterService; private readonly IBroadcasterService _broadcasterService;
private readonly ISyncService _syncService;
private ViewPageViewModel _vm; private ViewPageViewModel _vm;
public ViewPage(string cipherId) public ViewPage(string cipherId)
{ {
InitializeComponent(); InitializeComponent();
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService"); _broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
_vm = BindingContext as ViewPageViewModel; _vm = BindingContext as ViewPageViewModel;
_vm.Page = this; _vm.Page = this;
_vm.CipherId = cipherId; _vm.CipherId = cipherId;
@ -34,12 +37,23 @@ namespace Bit.App.Pages
protected override async void OnAppearing() protected override async void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
_broadcasterService.Subscribe(nameof(ViewPage), (message) => if(_syncService.SyncInProgress)
{ {
if(message.Command == "syncCompleted") IsBusy = true;
}
_broadcasterService.Subscribe(nameof(ViewPage), async (message) =>
{ {
if(message.Command == "syncStarted")
{
Device.BeginInvokeOnMainThread(() => IsBusy = true);
}
else if(message.Command == "syncCompleted")
{
await Task.Delay(500);
Device.BeginInvokeOnMainThread(() => Device.BeginInvokeOnMainThread(() =>
{ {
IsBusy = false;
var data = message.Data as Dictionary<string, object>; var data = message.Data as Dictionary<string, object>;
if(data.ContainsKey("successfully")) if(data.ContainsKey("successfully"))
{ {
@ -90,6 +104,7 @@ namespace Bit.App.Pages
protected override void OnDisappearing() protected override void OnDisappearing()
{ {
base.OnDisappearing(); base.OnDisappearing();
IsBusy = false;
_broadcasterService.Unsubscribe(nameof(ViewPage)); _broadcasterService.Unsubscribe(nameof(ViewPage));
_vm.CleanUp(); _vm.CleanUp();
} }