secondary toolbar buttons

This commit is contained in:
Kyle Spearrin 2019-05-10 13:47:59 -04:00
parent 75cb67890d
commit 74c0e52458
5 changed files with 143 additions and 6 deletions

View file

@ -15,9 +15,8 @@
</ContentPage.BindingContext>
<ContentPage.ToolbarItems>
<ToolbarItem Text="{u:I18n Save}" Clicked="Save_Clicked" />
<ToolbarItem Text="{u:I18n Save}" Clicked="Save_Clicked" Order="Primary" />
<ToolbarItem Text="{u:I18n Attachments}" Clicked="Attachments_Clicked" Order="Secondary" />
<ToolbarItem Text="{u:I18n Share}" Clicked="Share_Clicked" Order="Secondary" />
<ToolbarItem Text="{u:I18n Delete}" Clicked="Delete_Clicked" Order="Secondary" IsDestructive="True" />
</ContentPage.ToolbarItems>
@ -26,6 +25,16 @@
<u:InverseBoolConverter x:Key="inverseBool" />
<u:StringHasValueConverter x:Key="stringHasValue" />
<u:IsNotNullConverter x:Key="notNull" />
<ToolbarItem Text="{u:I18n Collections}"
x:Key="collectionsItem"
x:Name="_collectionsItem"
Clicked="Collections_Clicked"
Order="Secondary" />
<ToolbarItem Text="{u:I18n Share}"
x:Key="shareItem"
x:Name="_shareItem"
Clicked="Share_Clicked"
Order="Secondary" />
</ResourceDictionary>
</ContentPage.Resources>
@ -412,9 +421,6 @@
HorizontalOptions="End" />
</StackLayout>
<BoxView StyleClass="box-row-separator" />
<Button Text="{u:I18n Attachments}" StyleClass="box-button-row"
IsVisible="{Binding EditMode}"
Clicked="Attachments_Clicked"></Button>
</StackLayout>
<StackLayout StyleClass="box">
<StackLayout StyleClass="box-row-header">

View file

@ -36,6 +36,31 @@ namespace Bit.App.Pages
{
base.OnAppearing();
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync());
if(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);
}
}
}
}
protected override void OnDisappearing()
@ -93,5 +118,13 @@ namespace Bit.App.Pages
await _vm.DeleteAsync();
}
}
private void Collections_Clicked(object sender, System.EventArgs e)
{
if(DoOnce())
{
// TODO
}
}
}
}

View file

@ -16,7 +16,9 @@
</ContentPage.BindingContext>
<ContentPage.ToolbarItems>
<ToolbarItem Text="{u:I18n Edit}" Clicked="EditToolbarItem_Clicked" />
<ToolbarItem Text="{u:I18n Edit}" Clicked="EditToolbarItem_Clicked" Order="Primary" />
<ToolbarItem Text="{u:I18n Attachments}" Clicked="Attachments_Clicked" Order="Secondary" />
<ToolbarItem Text="{u:I18n Delete}" Clicked="Delete_Clicked" Order="Secondary" IsDestructive="True" />
</ContentPage.ToolbarItems>
<ContentPage.Resources>
@ -24,6 +26,16 @@
<u:InverseBoolConverter x:Key="inverseBool" />
<u:StringHasValueConverter x:Key="stringHasValue" />
<u:IsNotNullConverter x:Key="notNull" />
<ToolbarItem Text="{u:I18n Collections}"
x:Key="collectionsItem"
x:Name="_collectionsItem"
Clicked="Collections_Clicked"
Order="Secondary" />
<ToolbarItem Text="{u:I18n Share}"
x:Key="shareItem"
x:Name="_shareItem"
Clicked="Share_Clicked"
Order="Secondary" />
<ScrollView x:Key="scrollView" x:Name="_scrollView">
<StackLayout Spacing="20" x:Name="_mainLayout">

View file

@ -50,6 +50,31 @@ namespace Bit.App.Pages
}
});
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync(), _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()
@ -79,5 +104,38 @@ namespace Bit.App.Pages
{
EditToolbarItem_Clicked(sender, e);
}
private void Attachments_Clicked(object sender, System.EventArgs e)
{
if(DoOnce())
{
// await Navigation.PushModalAsync();
}
}
private async void Share_Clicked(object sender, System.EventArgs e)
{
if(DoOnce())
{
var page = new SharePage(_vm.CipherId);
await Navigation.PushModalAsync(new NavigationPage(page));
}
}
private async void Delete_Clicked(object sender, System.EventArgs e)
{
if(DoOnce())
{
await _vm.DeleteAsync();
}
}
private void Collections_Clicked(object sender, System.EventArgs e)
{
if(DoOnce())
{
// TODO
}
}
}
}

View file

@ -2,6 +2,7 @@
using Bit.App.Resources;
using Bit.App.Utilities;
using Bit.Core.Abstractions;
using Bit.Core.Exceptions;
using Bit.Core.Models.View;
using Bit.Core.Utilities;
using System;
@ -20,6 +21,7 @@ namespace Bit.App.Pages
private readonly ITotpService _totpService;
private readonly IPlatformUtilsService _platformUtilsService;
private readonly IAuditService _auditService;
private readonly IMessagingService _messagingService;
private CipherView _cipher;
private List<ViewPageFieldViewModel> _fields;
private bool _canAccessPremium;
@ -39,6 +41,7 @@ namespace Bit.App.Pages
_totpService = ServiceContainer.Resolve<ITotpService>("totpService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_auditService = ServiceContainer.Resolve<IAuditService>("auditService");
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
CopyCommand = new Command<string>((id) => CopyAsync(id, null));
CopyUriCommand = new Command<LoginUriView>(CopyUri);
CopyFieldCommand = new Command<FieldView>(CopyField);
@ -245,6 +248,31 @@ namespace Bit.App.Pages
ShowCardCode = !ShowCardCode;
}
public async Task<bool> DeleteAsync()
{
var confirmed = await _platformUtilsService.ShowDialogAsync(AppResources.DoYouReallyWantToDelete,
null, AppResources.Yes, AppResources.No);
if(!confirmed)
{
return false;
}
try
{
await _deviceActionService.ShowLoadingAsync(AppResources.Deleting);
await _cipherService.DeleteWithServerAsync(Cipher.Id);
await _deviceActionService.HideLoadingAsync();
_platformUtilsService.ShowToast("success", null, AppResources.ItemDeleted);
_messagingService.Send("deletedCipher");
return true;
}
catch(ApiException e)
{
await _deviceActionService.HideLoadingAsync();
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
}
return false;
}
private async Task TotpUpdateCodeAsync()
{
if(Cipher == null || Cipher.Type != Core.Enums.CipherType.Login || Cipher.Login.Totp == null)