From e717992b2b1c1072a6964a58b40b43c45046cdfd Mon Sep 17 00:00:00 2001 From: Matt Portune Date: Wed, 19 Jan 2022 12:06:45 -0500 Subject: [PATCH] account list status enhancements --- src/App/App.xaml.cs | 3 +- src/App/Pages/Accounts/HomePage.xaml | 3 +- src/App/Pages/Accounts/HomePage.xaml.cs | 7 ++-- src/App/Pages/Accounts/LockPage.xaml | 3 +- src/App/Pages/Accounts/LockPage.xaml.cs | 7 ++-- src/App/Pages/Accounts/LoginPage.xaml | 3 +- src/App/Pages/Accounts/LoginPage.xaml.cs | 7 ++-- src/App/Pages/BaseContentPage.cs | 35 ++++++++++--------- .../Vault/GroupingsPage/GroupingsPage.xaml | 3 +- .../Vault/GroupingsPage/GroupingsPage.xaml.cs | 7 ++-- src/Core/Abstractions/IStateService.cs | 2 +- src/Core/Services/StateService.cs | 4 +-- 12 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/App/App.xaml.cs b/src/App/App.xaml.cs index d854f084c..61e03b630 100644 --- a/src/App/App.xaml.cs +++ b/src/App/App.xaml.cs @@ -283,13 +283,14 @@ namespace Bit.App { await SetMainPageAsync(); } + await Task.Delay(50); UpdateTheme(); }); } private async Task SetMainPageAsync() { - await _stateService.RefreshAccountViews(); + await _stateService.RefreshAccountViewsAsync(); var authed = await _stateService.IsAuthenticatedAsync(); if (authed) { diff --git a/src/App/Pages/Accounts/HomePage.xaml b/src/App/Pages/Accounts/HomePage.xaml index c499b87b6..84025512c 100644 --- a/src/App/Pages/Accounts/HomePage.xaml +++ b/src/App/Pages/Accounts/HomePage.xaml @@ -79,7 +79,7 @@ Padding="0"> ShowAccountSwitcherAsync() - { - return await _stateService.HasMultipleAccountsAsync() - || await _stateService.IsAuthenticatedAsync(); - } - public bool DoOnce(Action action = null, int milliseconds = 1000) { if (LastPageAction.HasValue && (DateTime.UtcNow - LastPageAction.Value).TotalMilliseconds < milliseconds) @@ -115,23 +108,33 @@ namespace Bit.App.Pages }); } + protected async Task ShowAccountSwitcherAsync() + { + return await _stateService.HasMultipleAccountsAsync() + || await _stateService.IsAuthenticatedAsync(); + } + + protected async Task RefreshAccountViewsAsync(Xamarin.Forms.ListView accountListView) + { + await _stateService.RefreshAccountViewsAsync(); + // Property change trigger on account listview is yielding inconsistent results, using a hammer instead + accountListView.ItemsSource = null; + accountListView.ItemsSource = _stateService.AccountViews; + } protected async Task GetAvatarImageSourceAsync(bool useCurrentActiveAccount = true) { return new AvatarImageSource(useCurrentActiveAccount ? await _stateService.GetEmailAsync() : null); } - protected async Task ShowAccountListAsync(bool isVisible, View listView, View overlay, View fab = null) + protected async Task ShowAccountListAsync(bool isVisible, View listContainer, View overlay, View fab = null) { Device.BeginInvokeOnMainThread(async () => { // Not all animations are awaited. This is intentional to allow multiple simultaneous animations. if (isVisible) { - // Update account views to reflect current state - await _stateService.RefreshAccountViews(); - // start listView in default (off-screen) position - await listView.TranslateTo(0, listView.Height * -1, 0); + await listContainer.TranslateTo(0, listContainer.Height * -1, 0); // set overlay opacity to zero before making visible and start fade-in overlay.Opacity = 0; @@ -145,7 +148,7 @@ namespace Bit.App.Pages } // slide account list into view - await listView.TranslateTo(0, 0, 200, Easing.SinOut); + await listContainer.TranslateTo(0, 0, 200, Easing.SinOut); } else { @@ -159,7 +162,7 @@ namespace Bit.App.Pages } // slide account list out of view - await listView.TranslateTo(0, listView.Height * -1, 200, Easing.SinIn); + await listContainer.TranslateTo(0, listContainer.Height * -1, 200, Easing.SinIn); // remove overlay overlay.IsVisible = false; @@ -167,7 +170,7 @@ namespace Bit.App.Pages }); } - protected async Task AccountRowSelectedAsync(object sender, SelectedItemChangedEventArgs e, View listView, + protected async Task AccountRowSelectedAsync(object sender, SelectedItemChangedEventArgs e, View listContainer, View overlay, View fab = null, bool? allowActiveAccountSelection = false) { if (!DoOnce()) @@ -181,7 +184,7 @@ namespace Bit.App.Pages ((Xamarin.Forms.ListView)sender).SelectedItem = null; await Task.Delay(100); - await ShowAccountListAsync(false, listView, overlay, fab); + await ShowAccountListAsync(false, listContainer, overlay, fab); if (item.AccountView.IsAccount) { diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml index 28b24c1a4..f995d6730 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml @@ -172,7 +172,7 @@ Padding="0"> IsAuthenticatedAsync(string userId = null); Task HasMultipleAccountsAsync(); - Task RefreshAccountViews(); + Task RefreshAccountViewsAsync(); Task AddAccountAsync(Account account); Task ClearAsync(string userId); Task GetPreAuthEnvironmentUrlsAsync(); diff --git a/src/Core/Services/StateService.cs b/src/Core/Services/StateService.cs index 9544c2920..81e214f8d 100644 --- a/src/Core/Services/StateService.cs +++ b/src/Core/Services/StateService.cs @@ -85,7 +85,7 @@ namespace Bit.Core.Services return _state.Accounts?.Count > 1; } - public async Task RefreshAccountViews() + public async Task RefreshAccountViewsAsync() { await CheckStateAsync(); @@ -130,7 +130,7 @@ namespace Bit.Core.Services { await ScaffoldNewAccountAsync(account); await SetActiveUserAsync(account.Profile.UserId); - await RefreshAccountViews(); + await RefreshAccountViewsAsync(); } public async Task ClearAsync(string userId)