From 9bbddd6aebe26d9b5de8088f41112b201450741b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 27 Nov 2017 15:42:36 -0500 Subject: [PATCH] show loading indicator if syncing an no items --- src/App/Controls/ExtendedContentPage.cs | 8 ++++---- src/App/Pages/Vault/VaultListCiphersPage.cs | 13 ++++++++++--- src/App/Pages/Vault/VaultListGroupingsPage.cs | 8 ++++++-- src/App/Services/SyncService.cs | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/App/Controls/ExtendedContentPage.cs b/src/App/Controls/ExtendedContentPage.cs index 678d32c65..6df9eead5 100644 --- a/src/App/Controls/ExtendedContentPage.cs +++ b/src/App/Controls/ExtendedContentPage.cs @@ -29,9 +29,9 @@ namespace Bit.App.Controls { if(_syncIndicator) { - MessagingCenter.Subscribe(_syncService, "SyncCompleted", + MessagingCenter.Subscribe(Application.Current, "SyncCompleted", (sender, success) => Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress)); - MessagingCenter.Subscribe(_syncService, "SyncStarted", + MessagingCenter.Subscribe(Application.Current, "SyncStarted", (sender) => Device.BeginInvokeOnMainThread(() => IsBusy = _syncService.SyncInProgress)); } @@ -48,8 +48,8 @@ namespace Bit.App.Controls { if(_syncIndicator) { - MessagingCenter.Unsubscribe(_syncService, "SyncCompleted"); - MessagingCenter.Unsubscribe(_syncService, "SyncStarted"); + MessagingCenter.Unsubscribe(Application.Current, "SyncCompleted"); + MessagingCenter.Unsubscribe(Application.Current, "SyncStarted"); } if(_syncIndicator) diff --git a/src/App/Pages/Vault/VaultListCiphersPage.cs b/src/App/Pages/Vault/VaultListCiphersPage.cs index ca0508b49..05c3a37b5 100644 --- a/src/App/Pages/Vault/VaultListCiphersPage.cs +++ b/src/App/Pages/Vault/VaultListCiphersPage.cs @@ -61,6 +61,7 @@ namespace Bit.App.Pages public Cipher[] Ciphers { get; set; } = new Cipher[] { }; public ListView ListView { get; set; } public SearchBar Search { get; set; } + public ActivityIndicator LoadingIndicator { get; set; } public StackLayout NoDataStackLayout { get; set; } public StackLayout ResultsStackLayout { get; set; } private AddCipherToolBarItem AddCipherItem { get; set; } @@ -156,12 +157,14 @@ namespace Bit.App.Pages Title = AppResources.SearchVault; } - Content = new ActivityIndicator + LoadingIndicator = new ActivityIndicator { IsRunning = true, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center }; + + Content = LoadingIndicator; } private void SearchBar_SearchButtonPressed(object sender, EventArgs e) @@ -249,7 +252,7 @@ namespace Bit.App.Pages protected override void OnAppearing() { base.OnAppearing(); - MessagingCenter.Subscribe(_syncService, "SyncCompleted", (sender, success) => + MessagingCenter.Subscribe(Application.Current, "SyncCompleted", (sender, success) => { if(success) { @@ -273,7 +276,7 @@ namespace Bit.App.Pages protected override void OnDisappearing() { base.OnDisappearing(); - MessagingCenter.Unsubscribe(_syncService, "SyncCompleted"); + MessagingCenter.Unsubscribe(Application.Current, "SyncCompleted"); AddCipherItem?.Dispose(); ListView.ItemSelected -= CipherSelected; @@ -345,6 +348,10 @@ namespace Bit.App.Pages { Content = ResultsStackLayout; } + else if(_syncService.SyncInProgress) + { + Content = LoadingIndicator; + } else { Content = NoDataStackLayout; diff --git a/src/App/Pages/Vault/VaultListGroupingsPage.cs b/src/App/Pages/Vault/VaultListGroupingsPage.cs index 1fb03f904..08530f0be 100644 --- a/src/App/Pages/Vault/VaultListGroupingsPage.cs +++ b/src/App/Pages/Vault/VaultListGroupingsPage.cs @@ -119,7 +119,7 @@ namespace Bit.App.Pages protected override void OnAppearing() { base.OnAppearing(); - MessagingCenter.Subscribe(_syncService, "SyncCompleted", (sender, success) => + MessagingCenter.Subscribe(Application.Current, "SyncCompleted", (sender, success) => { if(success) { @@ -168,7 +168,7 @@ namespace Bit.App.Pages protected override void OnDisappearing() { base.OnDisappearing(); - MessagingCenter.Unsubscribe(_syncService, "SyncCompleted"); + MessagingCenter.Unsubscribe(Application.Current, "SyncCompleted"); ListView.ItemSelected -= GroupingSelected; AddCipherItem?.Dispose(); @@ -229,6 +229,10 @@ namespace Bit.App.Pages { Content = ListView; } + else if(_syncService.SyncInProgress) + { + Content = LoadingIndicator; + } else { Content = NoDataStackLayout; diff --git a/src/App/Services/SyncService.cs b/src/App/Services/SyncService.cs index e2363d875..8fb769cee 100644 --- a/src/App/Services/SyncService.cs +++ b/src/App/Services/SyncService.cs @@ -554,7 +554,7 @@ namespace Bit.App.Services } SyncInProgress = true; - MessagingCenter.Send(this, "SyncStarted"); + MessagingCenter.Send(Application.Current, "SyncStarted"); } private void SyncCompleted(bool successfully) @@ -565,7 +565,7 @@ namespace Bit.App.Services } SyncInProgress = false; - MessagingCenter.Send(this, "SyncCompleted", successfully); + MessagingCenter.Send(Application.Current, "SyncCompleted", successfully); } private bool CheckSuccess(ApiResult result, bool logout = false)