CipherListOptions

This commit is contained in:
Kyle Spearrin 2019-05-29 23:35:34 -04:00
parent cc8b8f9ceb
commit 86d8d64bf6
5 changed files with 126 additions and 9 deletions

View file

@ -1,6 +1,7 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Models; using Bit.App.Models;
using Bit.App.Resources; using Bit.App.Resources;
using Bit.App.Utilities;
using Bit.Core; using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
@ -98,7 +99,7 @@ namespace Bit.App.Pages
{ {
if(_deviceActionService.SystemMajorVersion() < 21) if(_deviceActionService.SystemMajorVersion() < 21)
{ {
// TODO await AppHelpers.CipherListOptions(Page, cipher);
} }
else else
{ {

View file

@ -1,4 +1,5 @@
using Bit.App.Resources; using Bit.App.Resources;
using Bit.App.Utilities;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Models.Domain; using Bit.Core.Models.Domain;
@ -374,16 +375,10 @@ namespace Bit.App.Pages
private async void CipherOptionsAsync(CipherView cipher) private async void CipherOptionsAsync(CipherView cipher)
{ {
if(!(Page as BaseContentPage).DoOnce()) if((Page as BaseContentPage).DoOnce())
{ {
return; await AppHelpers.CipherListOptions(Page, cipher);
} }
var option = await Page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, "1", "2");
if(option == AppResources.Cancel)
{
return;
}
// TODO: process options
} }
} }
} }

View file

@ -987,6 +987,15 @@ namespace Bit.App.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Copy Notes.
/// </summary>
public static string CopyNotes {
get {
return ResourceManager.GetString("CopyNotes", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Copy Number. /// Looks up a localized string similar to Copy Number.
/// </summary> /// </summary>

View file

@ -1564,4 +1564,7 @@
<data name="Restarting" xml:space="preserve"> <data name="Restarting" xml:space="preserve">
<value>Restarting...</value> <value>Restarting...</value>
</data> </data>
<data name="CopyNotes" xml:space="preserve">
<value>Copy Notes</value>
</data>
</root> </root>

View file

@ -0,0 +1,109 @@
using Bit.App.Pages;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Models.View;
using Bit.Core.Utilities;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Bit.App.Utilities
{
public static class AppHelpers
{
public static async Task<string> CipherListOptions(ContentPage page, CipherView cipher)
{
var platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
var options = new List<string> { AppResources.View, AppResources.Edit };
if(cipher.Type == Core.Enums.CipherType.Login)
{
if(!string.IsNullOrWhiteSpace(cipher.Login.Username))
{
options.Add(AppResources.CopyUsername);
}
if(!string.IsNullOrWhiteSpace(cipher.Login.Password))
{
options.Add(AppResources.CopyPassword);
}
if(!string.IsNullOrWhiteSpace(cipher.Login.Totp))
{
options.Add(AppResources.CopyTotp);
}
if(cipher.Login.CanLaunch)
{
options.Add(AppResources.Launch);
}
}
else if(cipher.Type == Core.Enums.CipherType.Card)
{
if(!string.IsNullOrWhiteSpace(cipher.Card.Number))
{
options.Add(AppResources.CopyNumber);
}
if(!string.IsNullOrWhiteSpace(cipher.Card.Code))
{
options.Add(AppResources.CopySecurityCode);
}
}
else if(cipher.Type == Core.Enums.CipherType.SecureNote)
{
if(!string.IsNullOrWhiteSpace(cipher.Notes))
{
options.Add(AppResources.CopyNotes);
}
}
var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, options.ToArray());
if(selection == AppResources.View)
{
await page.Navigation.PushModalAsync(new NavigationPage(new ViewPage(cipher.Id)));
}
else if(selection == AppResources.Edit)
{
await page.Navigation.PushModalAsync(new NavigationPage(new AddEditPage(cipher.Id)));
}
else if(selection == AppResources.CopyUsername)
{
await platformUtilsService.CopyToClipboardAsync(cipher.Login.Username);
platformUtilsService.ShowToast("info", null, AppResources.CopiedUsername);
}
else if(selection == AppResources.CopyPassword)
{
await platformUtilsService.CopyToClipboardAsync(cipher.Login.Password);
platformUtilsService.ShowToast("info", null, AppResources.CopiedPassword);
}
else if(selection == AppResources.CopyTotp)
{
var totpService = ServiceContainer.Resolve<ITotpService>("totpService");
var totp = await totpService.GetCodeAsync(cipher.Login.Totp);
if(!string.IsNullOrWhiteSpace(totp))
{
await platformUtilsService.CopyToClipboardAsync(totp);
platformUtilsService.ShowToast("info", null, AppResources.CopiedTotp);
}
}
else if(selection == AppResources.Launch)
{
platformUtilsService.LaunchUri(cipher.Login.LaunchUri);
}
else if(selection == AppResources.CopyNumber)
{
await platformUtilsService.CopyToClipboardAsync(cipher.Card.Number);
platformUtilsService.ShowToast("info", null,
string.Format(AppResources.ValueHasBeenCopied, AppResources.Number));
}
else if(selection == AppResources.CopySecurityCode)
{
await platformUtilsService.CopyToClipboardAsync(cipher.Card.Code);
platformUtilsService.ShowToast("info", null,
string.Format(AppResources.ValueHasBeenCopied, AppResources.SecurityCode));
}
else if(selection == AppResources.CopyNotes)
{
await platformUtilsService.CopyToClipboardAsync(cipher.Notes);
platformUtilsService.ShowToast("info", null,
string.Format(AppResources.ValueHasBeenCopied, AppResources.Notes));
}
return selection;
}
}
}