adjust toolbar after loading completes

This commit is contained in:
Kyle Spearrin 2019-06-05 17:25:12 -04:00
parent bc0bb7c7bb
commit c7938a8630
3 changed files with 114 additions and 85 deletions

View File

@ -6,6 +6,7 @@ using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
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
@ -126,65 +127,15 @@ namespace Bit.App.Pages
if(!success) if(!success)
{ {
await Navigation.PopModalAsync(); 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); 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<bool?>(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() protected override void OnDisappearing()
@ -281,5 +232,74 @@ namespace Bit.App.Pages
await Navigation.PushModalAsync(new NavigationPage(page)); await Navigation.PushModalAsync(new NavigationPage(page));
} }
} }
private async Task ShowAlertsAsync()
{
if(!_vm.EditMode)
{
if(_vm.Cipher == null)
{
return;
}
var addLoginShown = await _storageService.GetAsync<bool?>(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);
}
}
}
}
} }
} }

View File

@ -54,13 +54,12 @@ namespace Bit.App.Pages
Device.BeginInvokeOnMainThread(() => Device.BeginInvokeOnMainThread(() =>
{ {
IsBusy = false; IsBusy = false;
var data = message.Data as Dictionary<string, object>; if(message.Data is Dictionary<string, object> data && data.ContainsKey("successfully"))
if(data.ContainsKey("successfully"))
{ {
var success = data["successfully"] as bool?; 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 () => await LoadOnAppearedAsync(_scrollView, true, async () =>
{ {
var success = await _vm.LoadAsync(); var success = await _vm.LoadAsync(() => AdjustToolbar());
if(!success) if(!success)
{ {
await Navigation.PopModalAsync(); await Navigation.PopModalAsync();
} }
}, _mainContent); }, _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() protected override void OnDisappearing()
@ -167,5 +141,38 @@ namespace Bit.App.Pages
await Navigation.PushModalAsync(new NavigationPage(page)); 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);
}
}
}
}
} }
} }

View File

@ -206,12 +206,13 @@ namespace Bit.App.Pages
} }
} }
public async Task<bool> LoadAsync() public async Task<bool> LoadAsync(Action finishedLoadingAction = null)
{ {
CleanUp(); CleanUp();
var cipher = await _cipherService.GetAsync(CipherId); var cipher = await _cipherService.GetAsync(CipherId);
if(cipher == null) if(cipher == null)
{ {
finishedLoadingAction?.Invoke();
return false; return false;
} }
Cipher = await cipher.DecryptAsync(); Cipher = await cipher.DecryptAsync();
@ -235,6 +236,7 @@ namespace Bit.App.Pages
return true; return true;
}); });
} }
finishedLoadingAction?.Invoke();
return true; return true;
} }