diff --git a/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs b/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs index 579fcf2c4..f04b3fc1d 100644 --- a/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs +++ b/src/App/Pages/Vault/VaultAutofillListCiphersPage.cs @@ -102,7 +102,7 @@ namespace Bit.App.Pages GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell( nameof(VaultListPageModel.AutofillGrouping.Name))), ItemTemplate = new DataTemplate(() => new VaultListViewCell( - (VaultListPageModel.Cipher l) => MoreClickedAsync(l))) + (VaultListPageModel.Cipher c) => Helpers.CipherMoreClickedAsync(this, c, true))) }; if(Device.RuntimePlatform == Device.iOS) @@ -229,7 +229,7 @@ namespace Bit.App.Pages if(_deviceInfoService.Version < 21) { - MoreClickedAsync(cipher); + Helpers.CipherMoreClickedAsync(this, cipher, true); } else { @@ -264,69 +264,6 @@ namespace Bit.App.Pages await Navigation.PushForDeviceAsync(pageForLogin); } - private async void MoreClickedAsync(VaultListPageModel.Cipher cipher) - { - var buttons = new List { 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 { public AddCipherToolBarItem(VaultAutofillListCiphersPage page) diff --git a/src/App/Pages/Vault/VaultSearchCiphersPage.cs b/src/App/Pages/Vault/VaultSearchCiphersPage.cs index 0fd6ee591..a81a7ad24 100644 --- a/src/App/Pages/Vault/VaultSearchCiphersPage.cs +++ b/src/App/Pages/Vault/VaultSearchCiphersPage.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Threading.Tasks; -using Acr.UserDialogs; using Bit.App.Abstractions; using Bit.App.Controls; using Bit.App.Models.Page; @@ -11,21 +10,15 @@ using XLabs.Ioc; using Bit.App.Utilities; using Plugin.Settings.Abstractions; using Plugin.Connectivity.Abstractions; -using System.Collections.Generic; using System.Threading; -using Bit.App.Enums; namespace Bit.App.Pages { public class VaultSearchCiphersPage : ExtendedContentPage { - private readonly IFolderService _folderService; private readonly ICipherService _cipherService; - private readonly IUserDialogs _userDialogs; private readonly IConnectivity _connectivity; - private readonly IDeviceActionService _deviceActionService; private readonly ISyncService _syncService; - private readonly IPushNotificationService _pushNotification; private readonly IDeviceInfoService _deviceInfoService; private readonly ISettings _settings; private readonly IAppSettingsService _appSettingsService; @@ -35,13 +28,9 @@ namespace Bit.App.Pages public VaultSearchCiphersPage() : base(true) { - _folderService = Resolver.Resolve(); _cipherService = Resolver.Resolve(); _connectivity = Resolver.Resolve(); - _userDialogs = Resolver.Resolve(); - _deviceActionService = Resolver.Resolve(); _syncService = Resolver.Resolve(); - _pushNotification = Resolver.Resolve(); _deviceInfoService = Resolver.Resolve(); _settings = Resolver.Resolve(); _appSettingsService = Resolver.Resolve(); @@ -67,7 +56,7 @@ namespace Bit.App.Pages GroupHeaderTemplate = new DataTemplate(() => new SectionHeaderViewCell( nameof(VaultListPageModel.NameGroup.Name), nameof(VaultListPageModel.NameGroup.Count))), ItemTemplate = new DataTemplate(() => new VaultListViewCell( - (VaultListPageModel.Cipher c) => MoreClickedAsync(c))) + (VaultListPageModel.Cipher c) => Helpers.CipherMoreClickedAsync(this, c, false))) }; if(Device.RuntimePlatform == Device.iOS) @@ -186,8 +175,8 @@ namespace Bit.App.Pages ListView.ItemSelected += CipherSelected; Search.TextChanged += SearchBar_TextChanged; Search.SearchButtonPressed += SearchBar_SearchButtonPressed; - _filterResultsCancellationTokenSource = FetchAndLoadVault(); + Search.FocusWithDelay(); } protected override void OnDisappearing() @@ -261,77 +250,5 @@ namespace Bit.App.Pages await Navigation.PushForDeviceAsync(page); ((ListView)sender).SelectedItem = null; } - - private async void MoreClickedAsync(VaultListPageModel.Cipher cipher) - { - var buttons = new List { 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)); - } } } diff --git a/src/App/Utilities/Extentions.cs b/src/App/Utilities/Extentions.cs index 1f84e3692..e1f9962ad 100644 --- a/src/App/Utilities/Extentions.cs +++ b/src/App/Utilities/Extentions.cs @@ -37,19 +37,19 @@ namespace Bit.App 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) { Task.Run(async () => { await Task.Delay(delay); - Device.BeginInvokeOnMainThread(() => entry.Focus()); + Device.BeginInvokeOnMainThread(() => view.Focus()); }); } else { - entry.Focus(); + view.Focus(); } } diff --git a/src/App/Utilities/Helpers.cs b/src/App/Utilities/Helpers.cs index 360716897..97bbaa916 100644 --- a/src/App/Utilities/Helpers.cs +++ b/src/App/Utilities/Helpers.cs @@ -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 System; +using System.Collections.Generic; using System.Threading.Tasks; using Xamarin.Forms; +using XLabs.Ioc; namespace Bit.App.Utilities { @@ -66,5 +73,76 @@ namespace Bit.App.Utilities return " "; } + public static async void CipherMoreClickedAsync(Page page, VaultListPageModel.Cipher cipher, bool autofill) + { + var buttons = new List { 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().CopyToClipboard(copyText); + Resolver.Resolve().Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel)); + } } }