mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-18 15:37:42 +01:00
populate add page from autofill
This commit is contained in:
parent
65f3a146fa
commit
9ab41c5de6
@ -9,15 +9,21 @@ namespace Bit.App.Pages
|
||||
{
|
||||
private AddEditPageViewModel _vm;
|
||||
private readonly AppOptions _appOptions;
|
||||
private bool _fromAutofill;
|
||||
|
||||
public AddEditPage(
|
||||
string cipherId = null,
|
||||
CipherType? type = null,
|
||||
string folderId = null,
|
||||
string collectionId = null,
|
||||
string name = null,
|
||||
string uri = null,
|
||||
bool fromAutofill = false,
|
||||
AppOptions appOptions = null)
|
||||
{
|
||||
_appOptions = appOptions;
|
||||
_fromAutofill = fromAutofill;
|
||||
FromAutofillFramework = _appOptions?.FromAutofillFramework ?? false;
|
||||
InitializeComponent();
|
||||
_vm = BindingContext as AddEditPageViewModel;
|
||||
_vm.Page = this;
|
||||
@ -25,6 +31,8 @@ namespace Bit.App.Pages
|
||||
_vm.FolderId = folderId;
|
||||
_vm.CollectionIds = collectionId != null ? new HashSet<string>(new List<string> { collectionId }) : null;
|
||||
_vm.Type = type;
|
||||
_vm.DefaultName = name ?? appOptions?.SaveName;
|
||||
_vm.DefaultUri = uri ?? appOptions?.Uri;
|
||||
_vm.Init();
|
||||
SetActivityIndicator();
|
||||
if(!_vm.EditMode)
|
||||
@ -41,6 +49,8 @@ namespace Bit.App.Pages
|
||||
_ownershipPicker.ItemDisplayBinding = new Binding("Key");
|
||||
}
|
||||
|
||||
public bool FromAutofillFramework { get; set; }
|
||||
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
@ -77,6 +87,16 @@ namespace Bit.App.Pages
|
||||
base.OnDisappearing();
|
||||
}
|
||||
|
||||
protected override bool OnBackButtonPressed()
|
||||
{
|
||||
if(FromAutofillFramework)
|
||||
{
|
||||
Application.Current.MainPage = new TabsPage();
|
||||
return true;
|
||||
}
|
||||
return base.OnBackButtonPressed();
|
||||
}
|
||||
|
||||
private async void PasswordHistory_Tapped(object sender, System.EventArgs e)
|
||||
{
|
||||
if(DoOnce())
|
||||
|
@ -142,6 +142,8 @@ namespace Bit.App.Pages
|
||||
public string FolderId { get; set; }
|
||||
public CipherType? Type { get; set; }
|
||||
public HashSet<string> CollectionIds { get; set; }
|
||||
public string DefaultName { get; set; }
|
||||
public string DefaultUri { get; set; }
|
||||
public List<KeyValuePair<string, CipherType>> TypeOptions { get; set; }
|
||||
public List<KeyValuePair<string, string>> CardBrandOptions { get; set; }
|
||||
public List<KeyValuePair<string, string>> CardExpMonthOptions { get; set; }
|
||||
@ -300,6 +302,7 @@ namespace Bit.App.Pages
|
||||
{
|
||||
Cipher = new CipherView
|
||||
{
|
||||
Name = DefaultName,
|
||||
OrganizationId = OrganizationId,
|
||||
FolderId = FolderId,
|
||||
Type = Type.GetValueOrDefault(CipherType.Login),
|
||||
@ -308,7 +311,7 @@ namespace Bit.App.Pages
|
||||
Identity = new IdentityView(),
|
||||
SecureNote = new SecureNoteView()
|
||||
};
|
||||
Cipher.Login.Uris = new List<LoginUriView> { new LoginUriView() };
|
||||
Cipher.Login.Uris = new List<LoginUriView> { new LoginUriView { Uri = DefaultUri } };
|
||||
Cipher.SecureNote.Type = SecureNoteType.Generic;
|
||||
TypeSelectedIndex = TypeOptions.FindIndex(k => k.Value == Cipher.Type);
|
||||
|
||||
@ -398,7 +401,16 @@ namespace Bit.App.Pages
|
||||
_platformUtilsService.ShowToast("success", null,
|
||||
EditMode ? AppResources.ItemUpdated : AppResources.NewItemCreated);
|
||||
_messagingService.Send(EditMode ? "editedCipher" : "addedCipher");
|
||||
|
||||
if((Page as AddEditPage).FromAutofillFramework)
|
||||
{
|
||||
// Close and go back to app
|
||||
_deviceActionService.CloseAutofill();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Page.Navigation.PopModalAsync();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch(ApiException e)
|
||||
|
@ -49,11 +49,12 @@ namespace Bit.App.Pages
|
||||
}
|
||||
if(_appOptions.FillType.HasValue && _appOptions.FillType != CipherType.Login)
|
||||
{
|
||||
var pageForOther = new AddEditPage(type: _appOptions.FillType);
|
||||
var pageForOther = new AddEditPage(type: _appOptions.FillType, fromAutofill: true);
|
||||
await Navigation.PushModalAsync(new NavigationPage(pageForOther));
|
||||
return;
|
||||
}
|
||||
var pageForLogin = new AddEditPage(null, CipherType.Login);
|
||||
var pageForLogin = new AddEditPage(null, CipherType.Login, uri: _vm.Uri, name: _vm.Name,
|
||||
fromAutofill: true);
|
||||
await Navigation.PushModalAsync(new NavigationPage(pageForLogin));
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,6 @@ namespace Bit.App.Pages
|
||||
private readonly ICipherService _cipherService;
|
||||
|
||||
private AppOptions _appOptions;
|
||||
private string _name;
|
||||
private string _uri;
|
||||
private bool _showList;
|
||||
private string _noDataText;
|
||||
|
||||
@ -38,6 +36,8 @@ namespace Bit.App.Pages
|
||||
CipherOptionsCommand = new Command<CipherView>(CipherOptionsAsync);
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public Command CipherOptionsCommand { get; set; }
|
||||
public ExtendedObservableCollection<GroupingsPageListGroup> GroupedItems { get; set; }
|
||||
|
||||
@ -56,25 +56,27 @@ namespace Bit.App.Pages
|
||||
public void Init(AppOptions appOptions)
|
||||
{
|
||||
_appOptions = appOptions;
|
||||
_uri = appOptions.Uri;
|
||||
if(_uri.StartsWith(Constants.AndroidAppProtocol))
|
||||
Uri = appOptions.Uri;
|
||||
string name = null;
|
||||
if(Uri.StartsWith(Constants.AndroidAppProtocol))
|
||||
{
|
||||
_name = _uri.Substring(Constants.AndroidAppProtocol.Length);
|
||||
name = Uri.Substring(Constants.AndroidAppProtocol.Length);
|
||||
}
|
||||
else if(!Uri.TryCreate(_uri, UriKind.Absolute, out Uri uri) ||
|
||||
!DomainName.TryParseBaseDomain(uri.Host, out _name))
|
||||
else if(!System.Uri.TryCreate(Uri, UriKind.Absolute, out Uri uri) ||
|
||||
!DomainName.TryParseBaseDomain(uri.Host, out name))
|
||||
{
|
||||
_name = "--";
|
||||
name = "--";
|
||||
}
|
||||
PageTitle = string.Format(AppResources.ItemsForUri, _name ?? "--");
|
||||
NoDataText = string.Format(AppResources.NoItemsForUri, _name ?? "--");
|
||||
Name = name;
|
||||
PageTitle = string.Format(AppResources.ItemsForUri, Name ?? "--");
|
||||
NoDataText = string.Format(AppResources.NoItemsForUri, Name ?? "--");
|
||||
}
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
ShowList = false;
|
||||
var groupedItems = new List<GroupingsPageListGroup>();
|
||||
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();
|
||||
if(matching?.Any() ?? false)
|
||||
{
|
||||
@ -109,7 +111,7 @@ namespace Bit.App.Pages
|
||||
options.Add(AppResources.YesAndSave);
|
||||
}
|
||||
autofillResponse = await _deviceActionService.DisplayAlertAsync(null,
|
||||
string.Format(AppResources.BitwardenAutofillServiceMatchConfirm, _name), AppResources.No,
|
||||
string.Format(AppResources.BitwardenAutofillServiceMatchConfirm, Name), AppResources.No,
|
||||
options.ToArray());
|
||||
}
|
||||
if(autofillResponse == AppResources.YesAndSave && cipher.Type == CipherType.Login)
|
||||
@ -121,7 +123,7 @@ namespace Bit.App.Pages
|
||||
}
|
||||
uris.Add(new LoginUriView
|
||||
{
|
||||
Uri = _uri,
|
||||
Uri = Uri,
|
||||
Match = null
|
||||
});
|
||||
cipher.Login.Uris = uris;
|
||||
|
Loading…
Reference in New Issue
Block a user