mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-23 11:45:38 +01:00
centralize some helpers
This commit is contained in:
parent
9499b7f562
commit
362ddd0339
@ -102,7 +102,7 @@ namespace Bit.App.Pages
|
|||||||
GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell(
|
GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell(
|
||||||
nameof(VaultListPageModel.AutofillGrouping.Name))),
|
nameof(VaultListPageModel.AutofillGrouping.Name))),
|
||||||
ItemTemplate = new DataTemplate(() => new VaultListViewCell(
|
ItemTemplate = new DataTemplate(() => new VaultListViewCell(
|
||||||
(VaultListPageModel.Cipher l) => MoreClickedAsync(l)))
|
(VaultListPageModel.Cipher c) => Helpers.CipherMoreClickedAsync(this, c, true)))
|
||||||
};
|
};
|
||||||
|
|
||||||
if(Device.RuntimePlatform == Device.iOS)
|
if(Device.RuntimePlatform == Device.iOS)
|
||||||
@ -229,7 +229,7 @@ namespace Bit.App.Pages
|
|||||||
|
|
||||||
if(_deviceInfoService.Version < 21)
|
if(_deviceInfoService.Version < 21)
|
||||||
{
|
{
|
||||||
MoreClickedAsync(cipher);
|
Helpers.CipherMoreClickedAsync(this, cipher, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -264,69 +264,6 @@ namespace Bit.App.Pages
|
|||||||
await Navigation.PushForDeviceAsync(pageForLogin);
|
await Navigation.PushForDeviceAsync(pageForLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void MoreClickedAsync(VaultListPageModel.Cipher cipher)
|
|
||||||
{
|
|
||||||
var buttons = new List<string> { AppResources.View, AppResources.Edit };
|
|
||||||
|
|
||||||
if(cipher.Type == CipherType.Login)
|
|
||||||
{
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.LoginPassword.Value))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopyPassword);
|
|
||||||
}
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.LoginUsername))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopyUsername);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(cipher.Type == CipherType.Card)
|
|
||||||
{
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.CardNumber))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopyNumber);
|
|
||||||
}
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.CardCode.Value))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopySecurityCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var selection = await DisplayActionSheet(cipher.Name, AppResources.Cancel, null, buttons.ToArray());
|
|
||||||
|
|
||||||
if(selection == AppResources.View)
|
|
||||||
{
|
|
||||||
var page = new VaultViewCipherPage(cipher.Type, cipher.Id);
|
|
||||||
await Navigation.PushForDeviceAsync(page);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.Edit)
|
|
||||||
{
|
|
||||||
var page = new VaultEditCipherPage(cipher.Id);
|
|
||||||
await Navigation.PushForDeviceAsync(page);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopyPassword)
|
|
||||||
{
|
|
||||||
Copy(cipher.LoginPassword.Value, AppResources.Password);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopyUsername)
|
|
||||||
{
|
|
||||||
Copy(cipher.LoginUsername, AppResources.Username);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopyNumber)
|
|
||||||
{
|
|
||||||
Copy(cipher.CardNumber, AppResources.Number);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopySecurityCode)
|
|
||||||
{
|
|
||||||
Copy(cipher.CardCode.Value, AppResources.SecurityCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Copy(string copyText, string alertLabel)
|
|
||||||
{
|
|
||||||
_deviceActionService.CopyToClipboard(copyText);
|
|
||||||
UserDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AddCipherToolBarItem : ExtendedToolbarItem
|
private class AddCipherToolBarItem : ExtendedToolbarItem
|
||||||
{
|
{
|
||||||
public AddCipherToolBarItem(VaultAutofillListCiphersPage page)
|
public AddCipherToolBarItem(VaultAutofillListCiphersPage page)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Acr.UserDialogs;
|
|
||||||
using Bit.App.Abstractions;
|
using Bit.App.Abstractions;
|
||||||
using Bit.App.Controls;
|
using Bit.App.Controls;
|
||||||
using Bit.App.Models.Page;
|
using Bit.App.Models.Page;
|
||||||
@ -11,21 +10,15 @@ using XLabs.Ioc;
|
|||||||
using Bit.App.Utilities;
|
using Bit.App.Utilities;
|
||||||
using Plugin.Settings.Abstractions;
|
using Plugin.Settings.Abstractions;
|
||||||
using Plugin.Connectivity.Abstractions;
|
using Plugin.Connectivity.Abstractions;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Bit.App.Enums;
|
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
public class VaultSearchCiphersPage : ExtendedContentPage
|
public class VaultSearchCiphersPage : ExtendedContentPage
|
||||||
{
|
{
|
||||||
private readonly IFolderService _folderService;
|
|
||||||
private readonly ICipherService _cipherService;
|
private readonly ICipherService _cipherService;
|
||||||
private readonly IUserDialogs _userDialogs;
|
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
private readonly IDeviceActionService _deviceActionService;
|
|
||||||
private readonly ISyncService _syncService;
|
private readonly ISyncService _syncService;
|
||||||
private readonly IPushNotificationService _pushNotification;
|
|
||||||
private readonly IDeviceInfoService _deviceInfoService;
|
private readonly IDeviceInfoService _deviceInfoService;
|
||||||
private readonly ISettings _settings;
|
private readonly ISettings _settings;
|
||||||
private readonly IAppSettingsService _appSettingsService;
|
private readonly IAppSettingsService _appSettingsService;
|
||||||
@ -35,13 +28,9 @@ namespace Bit.App.Pages
|
|||||||
public VaultSearchCiphersPage()
|
public VaultSearchCiphersPage()
|
||||||
: base(true)
|
: base(true)
|
||||||
{
|
{
|
||||||
_folderService = Resolver.Resolve<IFolderService>();
|
|
||||||
_cipherService = Resolver.Resolve<ICipherService>();
|
_cipherService = Resolver.Resolve<ICipherService>();
|
||||||
_connectivity = Resolver.Resolve<IConnectivity>();
|
_connectivity = Resolver.Resolve<IConnectivity>();
|
||||||
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
|
||||||
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
|
||||||
_syncService = Resolver.Resolve<ISyncService>();
|
_syncService = Resolver.Resolve<ISyncService>();
|
||||||
_pushNotification = Resolver.Resolve<IPushNotificationService>();
|
|
||||||
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
|
_deviceInfoService = Resolver.Resolve<IDeviceInfoService>();
|
||||||
_settings = Resolver.Resolve<ISettings>();
|
_settings = Resolver.Resolve<ISettings>();
|
||||||
_appSettingsService = Resolver.Resolve<IAppSettingsService>();
|
_appSettingsService = Resolver.Resolve<IAppSettingsService>();
|
||||||
@ -67,7 +56,7 @@ namespace Bit.App.Pages
|
|||||||
GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell(
|
GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell(
|
||||||
nameof(VaultListPageModel.NameGroup.Name), nameof(VaultListPageModel.NameGroup.Count))),
|
nameof(VaultListPageModel.NameGroup.Name), nameof(VaultListPageModel.NameGroup.Count))),
|
||||||
ItemTemplate = new DataTemplate(() => new VaultListViewCell(
|
ItemTemplate = new DataTemplate(() => new VaultListViewCell(
|
||||||
(VaultListPageModel.Cipher c) => MoreClickedAsync(c)))
|
(VaultListPageModel.Cipher c) => Helpers.CipherMoreClickedAsync(this, c, false)))
|
||||||
};
|
};
|
||||||
|
|
||||||
if(Device.RuntimePlatform == Device.iOS)
|
if(Device.RuntimePlatform == Device.iOS)
|
||||||
@ -186,8 +175,8 @@ namespace Bit.App.Pages
|
|||||||
ListView.ItemSelected += CipherSelected;
|
ListView.ItemSelected += CipherSelected;
|
||||||
Search.TextChanged += SearchBar_TextChanged;
|
Search.TextChanged += SearchBar_TextChanged;
|
||||||
Search.SearchButtonPressed += SearchBar_SearchButtonPressed;
|
Search.SearchButtonPressed += SearchBar_SearchButtonPressed;
|
||||||
|
|
||||||
_filterResultsCancellationTokenSource = FetchAndLoadVault();
|
_filterResultsCancellationTokenSource = FetchAndLoadVault();
|
||||||
|
Search.FocusWithDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDisappearing()
|
protected override void OnDisappearing()
|
||||||
@ -261,77 +250,5 @@ namespace Bit.App.Pages
|
|||||||
await Navigation.PushForDeviceAsync(page);
|
await Navigation.PushForDeviceAsync(page);
|
||||||
((ListView)sender).SelectedItem = null;
|
((ListView)sender).SelectedItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void MoreClickedAsync(VaultListPageModel.Cipher cipher)
|
|
||||||
{
|
|
||||||
var buttons = new List<string> { AppResources.View, AppResources.Edit };
|
|
||||||
|
|
||||||
if(cipher.Type == CipherType.Login)
|
|
||||||
{
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.LoginPassword.Value))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopyPassword);
|
|
||||||
}
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.LoginUsername))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopyUsername);
|
|
||||||
}
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.LoginUri) && (cipher.LoginUri.StartsWith("http://")
|
|
||||||
|| cipher.LoginUri.StartsWith("https://")))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.GoToWebsite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(cipher.Type == CipherType.Card)
|
|
||||||
{
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.CardNumber))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopyNumber);
|
|
||||||
}
|
|
||||||
if(!string.IsNullOrWhiteSpace(cipher.CardCode.Value))
|
|
||||||
{
|
|
||||||
buttons.Add(AppResources.CopySecurityCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var selection = await DisplayActionSheet(cipher.Name, AppResources.Cancel, null, buttons.ToArray());
|
|
||||||
|
|
||||||
if(selection == AppResources.View)
|
|
||||||
{
|
|
||||||
var page = new VaultViewCipherPage(cipher.Type, cipher.Id);
|
|
||||||
await Navigation.PushForDeviceAsync(page);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.Edit)
|
|
||||||
{
|
|
||||||
var page = new VaultEditCipherPage(cipher.Id);
|
|
||||||
await Navigation.PushForDeviceAsync(page);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopyPassword)
|
|
||||||
{
|
|
||||||
Copy(cipher.LoginPassword.Value, AppResources.Password);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopyUsername)
|
|
||||||
{
|
|
||||||
Copy(cipher.LoginUsername, AppResources.Username);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.GoToWebsite)
|
|
||||||
{
|
|
||||||
Device.OpenUri(new Uri(cipher.LoginUri));
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopyNumber)
|
|
||||||
{
|
|
||||||
Copy(cipher.CardNumber, AppResources.Number);
|
|
||||||
}
|
|
||||||
else if(selection == AppResources.CopySecurityCode)
|
|
||||||
{
|
|
||||||
Copy(cipher.CardCode.Value, AppResources.SecurityCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Copy(string copyText, string alertLabel)
|
|
||||||
{
|
|
||||||
_deviceActionService.CopyToClipboard(copyText);
|
|
||||||
_userDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,19 +37,19 @@ namespace Bit.App
|
|||||||
return !page.IsPortrait();
|
return !page.IsPortrait();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FocusWithDelay(this Entry entry, int delay = 1000)
|
public static void FocusWithDelay(this View view, int delay = 1000)
|
||||||
{
|
{
|
||||||
if(Device.RuntimePlatform == Device.Android)
|
if(Device.RuntimePlatform == Device.Android)
|
||||||
{
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(delay);
|
await Task.Delay(delay);
|
||||||
Device.BeginInvokeOnMainThread(() => entry.Focus());
|
Device.BeginInvokeOnMainThread(() => view.Focus());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entry.Focus();
|
view.Focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
using Bit.App.Abstractions;
|
using Acr.UserDialogs;
|
||||||
|
using Bit.App.Abstractions;
|
||||||
|
using Bit.App.Enums;
|
||||||
|
using Bit.App.Models.Page;
|
||||||
|
using Bit.App.Pages;
|
||||||
|
using Bit.App.Resources;
|
||||||
using Plugin.Settings.Abstractions;
|
using Plugin.Settings.Abstractions;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
using XLabs.Ioc;
|
||||||
|
|
||||||
namespace Bit.App.Utilities
|
namespace Bit.App.Utilities
|
||||||
{
|
{
|
||||||
@ -66,5 +73,76 @@ namespace Bit.App.Utilities
|
|||||||
|
|
||||||
return " ";
|
return " ";
|
||||||
}
|
}
|
||||||
|
public static async void CipherMoreClickedAsync(Page page, VaultListPageModel.Cipher cipher, bool autofill)
|
||||||
|
{
|
||||||
|
var buttons = new List<string> { AppResources.View, AppResources.Edit };
|
||||||
|
|
||||||
|
if(cipher.Type == CipherType.Login)
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrWhiteSpace(cipher.LoginPassword.Value))
|
||||||
|
{
|
||||||
|
buttons.Add(AppResources.CopyPassword);
|
||||||
|
}
|
||||||
|
if(!string.IsNullOrWhiteSpace(cipher.LoginUsername))
|
||||||
|
{
|
||||||
|
buttons.Add(AppResources.CopyUsername);
|
||||||
|
}
|
||||||
|
if(!autofill && !string.IsNullOrWhiteSpace(cipher.LoginUri) && (cipher.LoginUri.StartsWith("http://")
|
||||||
|
|| cipher.LoginUri.StartsWith("https://")))
|
||||||
|
{
|
||||||
|
buttons.Add(AppResources.GoToWebsite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(cipher.Type == CipherType.Card)
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrWhiteSpace(cipher.CardNumber))
|
||||||
|
{
|
||||||
|
buttons.Add(AppResources.CopyNumber);
|
||||||
|
}
|
||||||
|
if(!string.IsNullOrWhiteSpace(cipher.CardCode.Value))
|
||||||
|
{
|
||||||
|
buttons.Add(AppResources.CopySecurityCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, buttons.ToArray());
|
||||||
|
|
||||||
|
if(selection == AppResources.View)
|
||||||
|
{
|
||||||
|
var p = new VaultViewCipherPage(cipher.Type, cipher.Id);
|
||||||
|
await page.Navigation.PushForDeviceAsync(p);
|
||||||
|
}
|
||||||
|
else if(selection == AppResources.Edit)
|
||||||
|
{
|
||||||
|
var p = new VaultEditCipherPage(cipher.Id);
|
||||||
|
await page.Navigation.PushForDeviceAsync(p);
|
||||||
|
}
|
||||||
|
else if(selection == AppResources.CopyPassword)
|
||||||
|
{
|
||||||
|
CipherCopy(cipher.LoginPassword.Value, AppResources.Password);
|
||||||
|
}
|
||||||
|
else if(selection == AppResources.CopyUsername)
|
||||||
|
{
|
||||||
|
CipherCopy(cipher.LoginUsername, AppResources.Username);
|
||||||
|
}
|
||||||
|
else if(selection == AppResources.GoToWebsite)
|
||||||
|
{
|
||||||
|
Device.OpenUri(new Uri(cipher.LoginUri));
|
||||||
|
}
|
||||||
|
else if(selection == AppResources.CopyNumber)
|
||||||
|
{
|
||||||
|
CipherCopy(cipher.CardNumber, AppResources.Number);
|
||||||
|
}
|
||||||
|
else if(selection == AppResources.CopySecurityCode)
|
||||||
|
{
|
||||||
|
CipherCopy(cipher.CardCode.Value, AppResources.SecurityCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CipherCopy(string copyText, string alertLabel)
|
||||||
|
{
|
||||||
|
Resolver.Resolve<IDeviceActionService>().CopyToClipboard(copyText);
|
||||||
|
Resolver.Resolve<IUserDialogs>().Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user