mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-18 15:37:42 +01:00
autofill cipher
This commit is contained in:
parent
d038fb900e
commit
22366ec0a2
@ -66,6 +66,10 @@ namespace Bit.Droid
|
|||||||
var alarmManager = GetSystemService(AlarmService) as AlarmManager;
|
var alarmManager = GetSystemService(AlarmService) as AlarmManager;
|
||||||
alarmManager.Cancel(_lockAlarmPendingIntent);
|
alarmManager.Cancel(_lockAlarmPendingIntent);
|
||||||
}
|
}
|
||||||
|
else if(message.Command == "finishMainActivity")
|
||||||
|
{
|
||||||
|
Finish();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Bit.App.Models;
|
using Bit.App.Models;
|
||||||
|
using Bit.Core.Enums;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
@ -33,16 +34,26 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(e.SelectedItem is GroupingsPageListItem item && item.Cipher != null)
|
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)
|
private void Search_Clicked(object sender, System.EventArgs e)
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using Bit.App.Models;
|
using Bit.App.Abstractions;
|
||||||
|
using Bit.App.Models;
|
||||||
using Bit.App.Resources;
|
using Bit.App.Resources;
|
||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
using Bit.Core.Abstractions;
|
using Bit.Core.Abstractions;
|
||||||
|
using Bit.Core.Enums;
|
||||||
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Models.View;
|
using Bit.Core.Models.View;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using System;
|
using System;
|
||||||
@ -16,9 +19,8 @@ namespace Bit.App.Pages
|
|||||||
public class AutofillCiphersPageViewModel : BaseViewModel
|
public class AutofillCiphersPageViewModel : BaseViewModel
|
||||||
{
|
{
|
||||||
private readonly IPlatformUtilsService _platformUtilsService;
|
private readonly IPlatformUtilsService _platformUtilsService;
|
||||||
|
private readonly IDeviceActionService _deviceActionService;
|
||||||
private readonly ICipherService _cipherService;
|
private readonly ICipherService _cipherService;
|
||||||
private readonly ISearchService _searchService;
|
|
||||||
private CancellationTokenSource _searchCancellationTokenSource;
|
|
||||||
|
|
||||||
private AppOptions _appOptions;
|
private AppOptions _appOptions;
|
||||||
private string _name;
|
private string _name;
|
||||||
@ -30,7 +32,7 @@ namespace Bit.App.Pages
|
|||||||
{
|
{
|
||||||
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
|
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
|
||||||
_cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
|
_cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
|
||||||
_searchService = ServiceContainer.Resolve<ISearchService>("searchService");
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
|
|
||||||
GroupedItems = new ExtendedObservableCollection<GroupingsPageListGroup>();
|
GroupedItems = new ExtendedObservableCollection<GroupingsPageListGroup>();
|
||||||
CipherOptionsCommand = new Command<CipherView>(CipherOptionsAsync);
|
CipherOptionsCommand = new Command<CipherView>(CipherOptionsAsync);
|
||||||
@ -75,7 +77,8 @@ namespace Bit.App.Pages
|
|||||||
var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(_uri, null);
|
var ciphers = await _cipherService.GetAllDecryptedByUrlAsync(_uri, null);
|
||||||
var matching = ciphers.Item1?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList();
|
var matching = ciphers.Item1?.Select(c => new GroupingsPageListItem { Cipher = c }).ToList();
|
||||||
var matchingGroup = new GroupingsPageListGroup(matching, AppResources.MatchingItems, matching.Count, false);
|
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);
|
var fuzzyGroup = new GroupingsPageListGroup(fuzzy, AppResources.PossibleMatchingItems, fuzzy.Count, false);
|
||||||
GroupedItems.ResetWithRange(new List<GroupingsPageListGroup> { matchingGroup, fuzzyGroup });
|
GroupedItems.ResetWithRange(new List<GroupingsPageListGroup> { matchingGroup, fuzzyGroup });
|
||||||
|
|
||||||
@ -83,10 +86,58 @@ namespace Bit.App.Pages
|
|||||||
ShowList = !ShowNoData;
|
ShowList = !ShowNoData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SelectCipherAsync(CipherView cipher)
|
public async Task SelectCipherAsync(CipherView cipher, bool fuzzy)
|
||||||
|
{
|
||||||
|
if(_deviceActionService.SystemMajorVersion() < 21)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var autofillResponse = AppResources.Yes;
|
||||||
|
if(fuzzy)
|
||||||
|
{
|
||||||
|
var options = new List<string> { 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<LoginUriView>();
|
||||||
|
}
|
||||||
|
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)
|
private async void CipherOptionsAsync(CipherView cipher)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user