From c7938a863010dfadeb28097f4ff66b35b72321c3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 5 Jun 2019 17:25:12 -0400 Subject: [PATCH] adjust toolbar after loading completes --- src/App/Pages/Vault/AddEditPage.xaml.cs | 128 +++++++++++++---------- src/App/Pages/Vault/ViewPage.xaml.cs | 67 ++++++------ src/App/Pages/Vault/ViewPageViewModel.cs | 4 +- 3 files changed, 114 insertions(+), 85 deletions(-) diff --git a/src/App/Pages/Vault/AddEditPage.xaml.cs b/src/App/Pages/Vault/AddEditPage.xaml.cs index a62cf8ced..3f913b109 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml.cs +++ b/src/App/Pages/Vault/AddEditPage.xaml.cs @@ -6,6 +6,7 @@ using Bit.Core.Abstractions; using Bit.Core.Enums; using Bit.Core.Utilities; using System.Collections.Generic; +using System.Threading.Tasks; using Xamarin.Forms; namespace Bit.App.Pages @@ -126,65 +127,15 @@ namespace Bit.App.Pages if(!success) { await Navigation.PopModalAsync(); + return; } - else if(!_vm.EditMode && string.IsNullOrWhiteSpace(_vm.Cipher.Name)) + AdjustToolbar(); + await ShowAlertsAsync(); + if(!_vm.EditMode && string.IsNullOrWhiteSpace(_vm.Cipher?.Name)) { RequestFocus(_nameEntry); } }); - if(_vm.EditMode && Device.RuntimePlatform == Device.Android) - { - if(_vm.Cipher.OrganizationId == null) - { - if(ToolbarItems.Contains(_collectionsItem)) - { - ToolbarItems.Remove(_collectionsItem); - } - if(!ToolbarItems.Contains(_shareItem)) - { - ToolbarItems.Insert(2, _shareItem); - } - } - else - { - if(ToolbarItems.Contains(_shareItem)) - { - ToolbarItems.Remove(_shareItem); - } - if(!ToolbarItems.Contains(_collectionsItem)) - { - ToolbarItems.Insert(2, _collectionsItem); - } - } - } - if(!_vm.EditMode) - { - var addLoginShown = await _storageService.GetAsync(Constants.AddSitePromptShownKey); - if(_vm.Cipher.Type == CipherType.Login && !_fromAutofill && !addLoginShown.GetValueOrDefault()) - { - await _storageService.SaveAsync(Constants.AddSitePromptShownKey, true); - if(Device.RuntimePlatform == Device.iOS) - { - if(_deviceActionService.SystemMajorVersion() < 12) - { - await DisplayAlert(AppResources.BitwardenAppExtension, - AppResources.BitwardenAppExtensionAlert2, AppResources.Ok); - } - else - { - await DisplayAlert(AppResources.PasswordAutofill, - AppResources.BitwardenAutofillAlert2, AppResources.Ok); - } - } - else if(Device.RuntimePlatform == Device.Android && - !_deviceActionService.AutofillAccessibilityServiceRunning() && - !_deviceActionService.AutofillServiceEnabled()) - { - await DisplayAlert(AppResources.BitwardenAutofillService, - AppResources.BitwardenAutofillServiceAlert2, AppResources.Ok); - } - } - } } protected override void OnDisappearing() @@ -281,5 +232,74 @@ namespace Bit.App.Pages await Navigation.PushModalAsync(new NavigationPage(page)); } } + + private async Task ShowAlertsAsync() + { + if(!_vm.EditMode) + { + if(_vm.Cipher == null) + { + return; + } + var addLoginShown = await _storageService.GetAsync(Constants.AddSitePromptShownKey); + if(_vm.Cipher.Type == CipherType.Login && !_fromAutofill && !addLoginShown.GetValueOrDefault()) + { + await _storageService.SaveAsync(Constants.AddSitePromptShownKey, true); + if(Device.RuntimePlatform == Device.iOS) + { + if(_deviceActionService.SystemMajorVersion() < 12) + { + await DisplayAlert(AppResources.BitwardenAppExtension, + AppResources.BitwardenAppExtensionAlert2, AppResources.Ok); + } + else + { + await DisplayAlert(AppResources.PasswordAutofill, + AppResources.BitwardenAutofillAlert2, AppResources.Ok); + } + } + else if(Device.RuntimePlatform == Device.Android && + !_deviceActionService.AutofillAccessibilityServiceRunning() && + !_deviceActionService.AutofillServiceEnabled()) + { + await DisplayAlert(AppResources.BitwardenAutofillService, + AppResources.BitwardenAutofillServiceAlert2, AppResources.Ok); + } + } + } + } + + private void AdjustToolbar() + { + if(_vm.EditMode && Device.RuntimePlatform == Device.Android) + { + if(_vm.Cipher == null) + { + return; + } + if(_vm.Cipher.OrganizationId == null) + { + if(ToolbarItems.Contains(_collectionsItem)) + { + ToolbarItems.Remove(_collectionsItem); + } + if(!ToolbarItems.Contains(_shareItem)) + { + ToolbarItems.Insert(2, _shareItem); + } + } + else + { + if(ToolbarItems.Contains(_shareItem)) + { + ToolbarItems.Remove(_shareItem); + } + if(!ToolbarItems.Contains(_collectionsItem)) + { + ToolbarItems.Insert(2, _collectionsItem); + } + } + } + } } } diff --git a/src/App/Pages/Vault/ViewPage.xaml.cs b/src/App/Pages/Vault/ViewPage.xaml.cs index 257f8e327..61df0945e 100644 --- a/src/App/Pages/Vault/ViewPage.xaml.cs +++ b/src/App/Pages/Vault/ViewPage.xaml.cs @@ -54,13 +54,12 @@ namespace Bit.App.Pages Device.BeginInvokeOnMainThread(() => { IsBusy = false; - var data = message.Data as Dictionary; - if(data.ContainsKey("successfully")) + if(message.Data is Dictionary data && data.ContainsKey("successfully")) { var success = data["successfully"] as bool?; - if(success.HasValue && success.Value) + if(success.GetValueOrDefault()) { - var task = _vm.LoadAsync(); + var task = _vm.LoadAsync(() => AdjustToolbar()); } } }); @@ -68,37 +67,12 @@ namespace Bit.App.Pages }); await LoadOnAppearedAsync(_scrollView, true, async () => { - var success = await _vm.LoadAsync(); + var success = await _vm.LoadAsync(() => AdjustToolbar()); if(!success) { await Navigation.PopModalAsync(); } }, _mainContent); - if(Device.RuntimePlatform == Device.Android) - { - if(_vm.Cipher.OrganizationId == null) - { - if(ToolbarItems.Contains(_collectionsItem)) - { - ToolbarItems.Remove(_collectionsItem); - } - if(!ToolbarItems.Contains(_shareItem)) - { - ToolbarItems.Insert(1, _shareItem); - } - } - else - { - if(ToolbarItems.Contains(_shareItem)) - { - ToolbarItems.Remove(_shareItem); - } - if(!ToolbarItems.Contains(_collectionsItem)) - { - ToolbarItems.Insert(1, _collectionsItem); - } - } - } } protected override void OnDisappearing() @@ -167,5 +141,38 @@ namespace Bit.App.Pages await Navigation.PushModalAsync(new NavigationPage(page)); } } + + private void AdjustToolbar() + { + if(Device.RuntimePlatform == Device.Android) + { + if(_vm.Cipher == null) + { + return; + } + if(_vm.Cipher.OrganizationId == null) + { + if(ToolbarItems.Contains(_collectionsItem)) + { + ToolbarItems.Remove(_collectionsItem); + } + if(!ToolbarItems.Contains(_shareItem)) + { + ToolbarItems.Insert(1, _shareItem); + } + } + else + { + if(ToolbarItems.Contains(_shareItem)) + { + ToolbarItems.Remove(_shareItem); + } + if(!ToolbarItems.Contains(_collectionsItem)) + { + ToolbarItems.Insert(1, _collectionsItem); + } + } + } + } } } diff --git a/src/App/Pages/Vault/ViewPageViewModel.cs b/src/App/Pages/Vault/ViewPageViewModel.cs index 53d148e29..d49fe6925 100644 --- a/src/App/Pages/Vault/ViewPageViewModel.cs +++ b/src/App/Pages/Vault/ViewPageViewModel.cs @@ -206,12 +206,13 @@ namespace Bit.App.Pages } } - public async Task LoadAsync() + public async Task LoadAsync(Action finishedLoadingAction = null) { CleanUp(); var cipher = await _cipherService.GetAsync(CipherId); if(cipher == null) { + finishedLoadingAction?.Invoke(); return false; } Cipher = await cipher.DecryptAsync(); @@ -235,6 +236,7 @@ namespace Bit.App.Pages return true; }); } + finishedLoadingAction?.Invoke(); return true; }