mirror of
https://github.com/bitwarden/mobile
synced 2026-01-20 09:23:50 +00:00
add other items to autofill from app page
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Bit.App.Abstractions
|
||||
Task<Cipher> GetByIdAsync(string id);
|
||||
Task<IEnumerable<Cipher>> GetAllAsync();
|
||||
Task<IEnumerable<Cipher>> GetAllAsync(bool favorites);
|
||||
Task<Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>>> GetAllAsync(string uriString);
|
||||
Task<Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>, IEnumerable<Cipher>>> GetAllAsync(string uriString);
|
||||
Task<ApiResult<CipherResponse>> SaveAsync(Cipher cipher);
|
||||
Task UpsertDataAsync(CipherData cipher);
|
||||
Task<ApiResult> DeleteAsync(string id);
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Bit.App
|
||||
}
|
||||
else if(_options.Uri != null)
|
||||
{
|
||||
MainPage = new ExtendedNavigationPage(new VaultAutofillListCiphersPage(_options.Uri));
|
||||
MainPage = new ExtendedNavigationPage(new VaultAutofillListCiphersPage(_options));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Bit.App.Models
|
||||
{
|
||||
public bool MyVault { get; set; }
|
||||
public bool FromAutofillFramework { get; set; }
|
||||
public CipherType? FillType { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public CipherType? SaveType { get; set; }
|
||||
public string SaveName { get; set; }
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Bit.App.Models.Page
|
||||
{
|
||||
public Cipher(Models.Cipher cipher, IAppSettingsService appSettings)
|
||||
{
|
||||
CipherModel = cipher;
|
||||
Id = cipher.Id;
|
||||
Shared = !string.IsNullOrWhiteSpace(cipher.OrganizationId);
|
||||
HasAttachments = cipher.Attachments?.Any() ?? false;
|
||||
@@ -114,6 +115,7 @@ namespace Bit.App.Models.Page
|
||||
}
|
||||
}
|
||||
|
||||
public Models.Cipher CipherModel { get; set; }
|
||||
public string Id { get; set; }
|
||||
public bool Shared { get; set; }
|
||||
public bool HasAttachments { get; set; }
|
||||
|
||||
@@ -25,17 +25,18 @@ namespace Bit.App.Pages
|
||||
private readonly IAppSettingsService _appSettingsService;
|
||||
private CancellationTokenSource _filterResultsCancellationTokenSource;
|
||||
private readonly string _name;
|
||||
private readonly AppOptions _appOptions;
|
||||
|
||||
public VaultAutofillListCiphersPage(string uriString)
|
||||
public VaultAutofillListCiphersPage(AppOptions appOptions)
|
||||
: base(true)
|
||||
{
|
||||
Uri = uriString;
|
||||
|
||||
if(uriString?.StartsWith(Constants.AndroidAppProtocol) ?? false)
|
||||
_appOptions = appOptions;
|
||||
Uri = appOptions.Uri;
|
||||
if(Uri.StartsWith(Constants.AndroidAppProtocol))
|
||||
{
|
||||
_name = uriString.Substring(Constants.AndroidAppProtocol.Length);
|
||||
_name = Uri.Substring(Constants.AndroidAppProtocol.Length);
|
||||
}
|
||||
else if(!System.Uri.TryCreate(uriString, UriKind.Absolute, out Uri uri) ||
|
||||
else if(!System.Uri.TryCreate(Uri, UriKind.Absolute, out Uri uri) ||
|
||||
!DomainName.TryParseBaseDomain(uri.Host, out _name))
|
||||
{
|
||||
_name = "--";
|
||||
@@ -166,25 +167,41 @@ namespace Bit.App.Pages
|
||||
var autofillGroupings = new List<VaultListPageModel.AutofillGrouping>();
|
||||
var ciphers = await _cipherService.GetAllAsync(Uri);
|
||||
|
||||
var normalLogins = ciphers?.Item1.Select(l => new VaultListPageModel.AutofillCipher(
|
||||
l, _appSettingsService, false))
|
||||
.OrderBy(s => s.Name)
|
||||
.ThenBy(s => s.Subtitle)
|
||||
.ToList();
|
||||
if(normalLogins?.Any() ?? false)
|
||||
if(_appOptions.FillType.HasValue && _appOptions.FillType.Value != CipherType.Login)
|
||||
{
|
||||
autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(normalLogins, AppResources.MatchingItems));
|
||||
var others = ciphers?.Item3.Where(c => c.Type == _appOptions.FillType.Value)
|
||||
.Select(c => new VaultListPageModel.AutofillCipher(c, _appSettingsService, false))
|
||||
.OrderBy(s => s.Name)
|
||||
.ThenBy(s => s.Subtitle)
|
||||
.ToList();
|
||||
if(others?.Any() ?? false)
|
||||
{
|
||||
autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(others, AppResources.Items));
|
||||
}
|
||||
}
|
||||
|
||||
var fuzzyLogins = ciphers?.Item2.Select(l => new VaultListPageModel.AutofillCipher(
|
||||
l, _appSettingsService, true))
|
||||
.OrderBy(s => s.Name)
|
||||
.ThenBy(s => s.LoginUsername)
|
||||
.ToList();
|
||||
if(fuzzyLogins?.Any() ?? false)
|
||||
else
|
||||
{
|
||||
autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(fuzzyLogins,
|
||||
AppResources.PossibleMatchingItems));
|
||||
var normalLogins = ciphers?.Item1
|
||||
.Select(l => new VaultListPageModel.AutofillCipher(l, _appSettingsService, false))
|
||||
.OrderBy(s => s.Name)
|
||||
.ThenBy(s => s.Subtitle)
|
||||
.ToList();
|
||||
if(normalLogins?.Any() ?? false)
|
||||
{
|
||||
autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(normalLogins,
|
||||
AppResources.MatchingItems));
|
||||
}
|
||||
|
||||
var fuzzyLogins = ciphers?.Item2
|
||||
.Select(l => new VaultListPageModel.AutofillCipher(l, _appSettingsService, true))
|
||||
.OrderBy(s => s.Name)
|
||||
.ThenBy(s => s.Subtitle)
|
||||
.ToList();
|
||||
if(fuzzyLogins?.Any() ?? false)
|
||||
{
|
||||
autofillGroupings.Add(new VaultListPageModel.AutofillGrouping(fuzzyLogins,
|
||||
AppResources.PossibleMatchingItems));
|
||||
}
|
||||
}
|
||||
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
@@ -235,8 +252,15 @@ namespace Bit.App.Pages
|
||||
|
||||
private async void AddCipherAsync()
|
||||
{
|
||||
var page = new VaultAddCipherPage(CipherType.Login, Uri, _name, true);
|
||||
await Navigation.PushForDeviceAsync(page);
|
||||
if(_appOptions.FillType.HasValue && _appOptions.FillType != CipherType.Login)
|
||||
{
|
||||
var pageForOther = new VaultAddCipherPage(_appOptions.FillType.Value, null, null, true);
|
||||
await Navigation.PushForDeviceAsync(pageForOther);
|
||||
return;
|
||||
}
|
||||
|
||||
var pageForLogin = new VaultAddCipherPage(CipherType.Login, Uri, _name, true);
|
||||
await Navigation.PushForDeviceAsync(pageForLogin);
|
||||
}
|
||||
|
||||
private async void MoreClickedAsync(VaultListPageModel.Cipher cipher)
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Bit.App.Services
|
||||
return cipher;
|
||||
}
|
||||
|
||||
public async Task<Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>>> GetAllAsync(string uriString)
|
||||
public async Task<Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>, IEnumerable<Cipher>>> GetAllAsync(string uriString)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(uriString))
|
||||
{
|
||||
@@ -135,9 +135,16 @@ namespace Bit.App.Services
|
||||
var matchingFuzzyDomainsArray = matchingFuzzyDomains.ToArray();
|
||||
var matchingLogins = new List<Cipher>();
|
||||
var matchingFuzzyLogins = new List<Cipher>();
|
||||
var others = new List<Cipher>();
|
||||
var ciphers = await GetAllAsync();
|
||||
foreach(var cipher in ciphers)
|
||||
{
|
||||
if(cipher.Type != Enums.CipherType.Login)
|
||||
{
|
||||
others.Add(cipher);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(cipher.Type != Enums.CipherType.Login || cipher.Login?.Uri == null)
|
||||
{
|
||||
continue;
|
||||
@@ -190,7 +197,7 @@ namespace Bit.App.Services
|
||||
if(mobileApp && mobileAppSearchTerms != null && mobileAppSearchTerms.Length > 0)
|
||||
{
|
||||
var addedFromSearchTerm = false;
|
||||
var loginNameString = cipher.Name == null ? null :
|
||||
var loginNameString = cipher.Name == null ? null :
|
||||
cipher.Name.Decrypt(cipher.OrganizationId)?.ToLowerInvariant();
|
||||
foreach(var term in mobileAppSearchTerms)
|
||||
{
|
||||
@@ -216,7 +223,8 @@ namespace Bit.App.Services
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>>(matchingLogins, matchingFuzzyLogins);
|
||||
return new Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>, IEnumerable<Cipher>>(
|
||||
matchingLogins, matchingFuzzyLogins, others);
|
||||
}
|
||||
|
||||
public async Task<ApiResult<CipherResponse>> SaveAsync(Cipher cipher)
|
||||
|
||||
Reference in New Issue
Block a user