Bitwarden-app-android-iphon.../src/App/Pages/Vault/AutofillCiphersPage.xaml.cs

81 lines
2.7 KiB
C#
Raw Normal View History

2019-05-17 19:14:26 +02:00
using Bit.App.Models;
2019-05-21 04:18:34 +02:00
using Bit.App.Resources;
using Bit.Core.Abstractions;
2019-05-17 20:46:31 +02:00
using Bit.Core.Enums;
2019-05-21 04:18:34 +02:00
using Bit.Core.Utilities;
2019-05-17 19:14:26 +02:00
using Xamarin.Forms;
namespace Bit.App.Pages
{
public partial class AutofillCiphersPage : BaseContentPage
{
private readonly AppOptions _appOptions;
2019-05-21 04:18:34 +02:00
private readonly IPlatformUtilsService _platformUtilsService;
private AutofillCiphersPageViewModel _vm;
2019-05-17 19:14:26 +02:00
public AutofillCiphersPage(AppOptions appOptions)
{
_appOptions = appOptions;
InitializeComponent();
_vm = BindingContext as AutofillCiphersPageViewModel;
_vm.Page = this;
2019-05-17 20:58:42 +02:00
_fab.Clicked = AddButton_Clicked;
2019-05-17 19:14:26 +02:00
_vm.Init(appOptions);
2019-05-21 04:18:34 +02:00
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
2019-05-17 19:14:26 +02:00
}
protected async override void OnAppearing()
{
base.OnAppearing();
await LoadOnAppearedAsync(_mainLayout, false, async () =>
{
await _vm.LoadAsync();
}, _mainContent);
}
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
{
((ListView)sender).SelectedItem = null;
if(!DoOnce())
{
return;
}
if(e.SelectedItem is GroupingsPageListItem item && item.Cipher != null)
{
2019-05-17 20:46:31 +02:00
await _vm.SelectCipherAsync(item.Cipher, item.FuzzyAutofill);
2019-05-17 19:14:26 +02:00
}
}
2019-05-17 20:46:31 +02:00
private async void AddButton_Clicked(object sender, System.EventArgs e)
2019-05-17 19:14:26 +02:00
{
2019-05-17 20:46:31 +02:00
if(!DoOnce())
{
return;
}
if(_appOptions.FillType.HasValue && _appOptions.FillType != CipherType.Login)
{
2019-05-17 21:24:15 +02:00
var pageForOther = new AddEditPage(type: _appOptions.FillType, fromAutofill: true);
2019-05-17 20:46:31 +02:00
await Navigation.PushModalAsync(new NavigationPage(pageForOther));
return;
}
2019-05-17 21:24:15 +02:00
var pageForLogin = new AddEditPage(null, CipherType.Login, uri: _vm.Uri, name: _vm.Name,
fromAutofill: true);
2019-05-17 20:46:31 +02:00
await Navigation.PushModalAsync(new NavigationPage(pageForLogin));
2019-05-17 19:14:26 +02:00
}
private void Search_Clicked(object sender, System.EventArgs e)
{
2019-05-21 04:18:34 +02:00
var page = new CiphersPage(null, autofillUrl: _vm.Uri);
Application.Current.MainPage = new NavigationPage(page);
_platformUtilsService.ShowToast("info", null,
string.Format(AppResources.BitwardenAutofillServiceSearch, _vm.Name),
new System.Collections.Generic.Dictionary<string, object>
{
["longDuration"] = true
});
2019-05-17 19:14:26 +02:00
}
}
}