BaseContentPage on groupings page

This commit is contained in:
Kyle Spearrin 2019-05-01 10:20:05 -04:00
parent b4f4f24c24
commit a018369ae8
3 changed files with 21 additions and 26 deletions

View File

@ -18,7 +18,7 @@ namespace Bit.App.Pages
protected async Task LoadOnAppearedAsync(View viewToSet, bool fromModal, Func<Task> workFunction) protected async Task LoadOnAppearedAsync(View viewToSet, bool fromModal, Func<Task> workFunction)
{ {
async Task LoadAsync() async Task DoWorkAsync()
{ {
await workFunction.Invoke(); await workFunction.Invoke();
if(viewToSet != null) if(viewToSet != null)
@ -26,15 +26,15 @@ namespace Bit.App.Pages
Content = viewToSet; Content = viewToSet;
} }
} }
if(Device.RuntimePlatform == Device.iOS) if(!fromModal || Device.RuntimePlatform == Device.iOS)
{ {
await LoadAsync(); await DoWorkAsync();
return; return;
} }
await Task.Run(async () => await Task.Run(async () =>
{ {
await Task.Delay(fromModal ? 400 : 200); await Task.Delay(400);
Device.BeginInvokeOnMainThread(async () => await LoadAsync()); Device.BeginInvokeOnMainThread(async () => await DoWorkAsync());
}); });
} }
} }

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" <pages:BaseContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Pages.GroupingsPage" x:Class="Bit.App.Pages.GroupingsPage"
xmlns:pages="clr-namespace:Bit.App.Pages" xmlns:pages="clr-namespace:Bit.App.Pages"
@ -64,11 +64,7 @@
CollectionTemplate="{StaticResource collectionTemplate}" /> CollectionTemplate="{StaticResource collectionTemplate}" />
</ResourceDictionary> </ResourceDictionary>
</ContentPage.Resources> </ContentPage.Resources>
<StackLayout> <StackLayout x:Name="_mainLayout">
<ActivityIndicator VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
IsRunning="True"
IsVisible="{Binding Loading}"></ActivityIndicator>
<StackLayout VerticalOptions="CenterAndExpand" <StackLayout VerticalOptions="CenterAndExpand"
Padding="20, 0" Padding="20, 0"
Spacing="20" Spacing="20"
@ -105,4 +101,4 @@
</ListView> </ListView>
</StackLayout> </StackLayout>
</ContentPage> </pages:BaseContentPage>

View File

@ -1,17 +1,12 @@
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xamarin.Forms; using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
public partial class GroupingsPage : ContentPage public partial class GroupingsPage : BaseContentPage
{ {
private readonly IBroadcasterService _broadcasterService; private readonly IBroadcasterService _broadcasterService;
private readonly ISyncService _syncService; private readonly ISyncService _syncService;
@ -25,6 +20,7 @@ namespace Bit.App.Pages
string collectionId = null, string pageTitle = null) string collectionId = null, string pageTitle = null)
{ {
InitializeComponent(); InitializeComponent();
SetActivityIndicator();
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService"); _broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
_syncService = ServiceContainer.Resolve<ISyncService>("syncService"); _syncService = ServiceContainer.Resolve<ISyncService>("syncService");
_viewModel = BindingContext as GroupingsPageViewModel; _viewModel = BindingContext as GroupingsPageViewModel;
@ -52,18 +48,21 @@ namespace Bit.App.Pages
} }
}); });
if(!_syncService.SyncInProgress) await LoadOnAppearedAsync(_mainLayout, false, async () =>
{ {
await _viewModel.LoadAsync(); if(!_syncService.SyncInProgress)
}
else
{
await Task.Delay(5000);
if(!_viewModel.Loaded)
{ {
await _viewModel.LoadAsync(); await _viewModel.LoadAsync();
} }
} else
{
await Task.Delay(5000);
if(!_viewModel.Loaded)
{
await _viewModel.LoadAsync();
}
}
});
} }
protected override void OnDisappearing() protected override void OnDisappearing()