diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index d676ec3d4..53503182e 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -66,6 +66,10 @@ namespace Bit.Droid var alarmManager = GetSystemService(AlarmService) as AlarmManager; alarmManager.Cancel(_lockAlarmPendingIntent); } + else if(message.Command == "finishMainActivity") + { + Finish(); + } }); } diff --git a/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs b/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs index 9f9b2bbb7..8429b8dc2 100644 --- a/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs +++ b/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs @@ -1,4 +1,5 @@ using Bit.App.Models; +using Bit.Core.Enums; using Xamarin.Forms; namespace Bit.App.Pages @@ -33,16 +34,26 @@ namespace Bit.App.Pages { return; } - if(e.SelectedItem is GroupingsPageListItem item && item.Cipher != null) { - // TODO + await _vm.SelectCipherAsync(item.Cipher, item.FuzzyAutofill); } } - private void AddButton_Clicked(object sender, System.EventArgs e) + private async void AddButton_Clicked(object sender, System.EventArgs e) { - + if(!DoOnce()) + { + return; + } + if(_appOptions.FillType.HasValue && _appOptions.FillType != CipherType.Login) + { + var pageForOther = new AddEditPage(type: _appOptions.FillType); + await Navigation.PushModalAsync(new NavigationPage(pageForOther)); + return; + } + var pageForLogin = new AddEditPage(null, CipherType.Login); + await Navigation.PushModalAsync(new NavigationPage(pageForLogin)); } private void Search_Clicked(object sender, System.EventArgs e) diff --git a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs index 9fad79d8e..0941a0186 100644 --- a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs +++ b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs @@ -1,7 +1,10 @@ -using Bit.App.Models; +using Bit.App.Abstractions; +using Bit.App.Models; using Bit.App.Resources; using Bit.Core; using Bit.Core.Abstractions; +using Bit.Core.Enums; +using Bit.Core.Exceptions; using Bit.Core.Models.View; using Bit.Core.Utilities; using System; @@ -16,9 +19,8 @@ namespace Bit.App.Pages public class AutofillCiphersPageViewModel : BaseViewModel { private readonly IPlatformUtilsService _platformUtilsService; + private readonly IDeviceActionService _deviceActionService; private readonly ICipherService _cipherService; - private readonly ISearchService _searchService; - private CancellationTokenSource _searchCancellationTokenSource; private AppOptions _appOptions; private string _name; @@ -30,7 +32,7 @@ namespace Bit.App.Pages { _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); _cipherService = ServiceContainer.Resolve("cipherService"); - _searchService = ServiceContainer.Resolve("searchService"); + _deviceActionService = ServiceContainer.Resolve("deviceActionService"); GroupedItems = new ExtendedObservableCollection(); CipherOptionsCommand = new Command(CipherOptionsAsync); @@ -75,7 +77,8 @@ namespace Bit.App.Pages var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(_uri, null); var matching = ciphers.Item1?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList(); var matchingGroup = new GroupingsPageListGroup(matching, AppResources.MatchingItems, matching.Count, false); - var fuzzy = ciphers.Item2?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList(); + var fuzzy = ciphers.Item2?.Select(c => new GroupingsPageListItem { Cipher = c, FuzzyAutofill = true }) + .ToList(); var fuzzyGroup = new GroupingsPageListGroup(fuzzy, AppResources.PossibleMatchingItems, fuzzy.Count, false); GroupedItems.ResetWithRange(new List { matchingGroup, fuzzyGroup }); @@ -83,9 +86,57 @@ namespace Bit.App.Pages ShowList = !ShowNoData; } - public async Task SelectCipherAsync(CipherView cipher) + public async Task SelectCipherAsync(CipherView cipher, bool fuzzy) { - // TODO + if(_deviceActionService.SystemMajorVersion() < 21) + { + // TODO + } + else + { + var autofillResponse = AppResources.Yes; + if(fuzzy) + { + var options = new List { AppResources.Yes }; + if(cipher.Type == CipherType.Login) + { + options.Add(AppResources.YesAndSave); + } + autofillResponse = await _deviceActionService.DisplayAlertAsync(null, + string.Format(AppResources.BitwardenAutofillServiceMatchConfirm, _name), AppResources.No, + options.ToArray()); + } + if(autofillResponse == AppResources.YesAndSave && cipher.Type == CipherType.Login) + { + var uris = cipher.Login?.Uris?.ToList(); + if(uris == null) + { + uris = new List(); + } + uris.Add(new LoginUriView + { + Uri = _uri, + Match = null + }); + cipher.Login.Uris = uris; + try + { + await _deviceActionService.ShowLoadingAsync(AppResources.Saving); + await _cipherService.SaveWithServerAsync(await _cipherService.EncryptAsync(cipher)); + await _deviceActionService.HideLoadingAsync(); + } + catch(ApiException e) + { + await _deviceActionService.HideLoadingAsync(); + await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), + AppResources.Ok); + } + } + if(autofillResponse == AppResources.Yes || autofillResponse == AppResources.YesAndSave) + { + _deviceActionService.Autofill(cipher); + } + } } private async void CipherOptionsAsync(CipherView cipher)