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

120 lines
3.2 KiB
C#
Raw Normal View History

2019-05-21 04:18:34 +02:00
using Bit.App.Abstractions;
using Bit.App.Resources;
2019-05-07 04:35:42 +02:00
using Bit.Core.Models.View;
2019-05-21 04:18:34 +02:00
using Bit.Core.Utilities;
2019-05-07 04:35:42 +02:00
using System;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public partial class CiphersPage : BaseContentPage
{
2019-05-21 04:18:34 +02:00
private readonly string _autofillUrl;
private readonly IDeviceActionService _deviceActionService;
private CiphersPageViewModel _vm;
2019-05-07 04:35:42 +02:00
private bool _hasFocused;
2019-05-07 04:35:42 +02:00
public CiphersPage(Func<CipherView, bool> filter, bool folder = false, bool collection = false,
2019-05-21 04:18:34 +02:00
bool type = false, string autofillUrl = null)
{
InitializeComponent();
_vm = BindingContext as CiphersPageViewModel;
_vm.Page = this;
2019-05-07 04:35:42 +02:00
_vm.Filter = filter;
2019-05-21 04:18:34 +02:00
_vm.AutofillUrl = _autofillUrl = autofillUrl;
2019-05-07 04:35:42 +02:00
if(folder)
{
_vm.PageTitle = AppResources.SearchFolder;
}
else if(collection)
{
_vm.PageTitle = AppResources.SearchCollection;
}
else if(type)
{
_vm.PageTitle = AppResources.SearchType;
}
else
{
_vm.PageTitle = AppResources.SearchVault;
}
2019-05-21 04:18:34 +02:00
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
}
2019-05-07 04:35:42 +02:00
public SearchBar SearchBar => _searchBar;
protected override void OnAppearing()
{
base.OnAppearing();
2019-05-07 04:35:42 +02:00
if(!_hasFocused)
{
_hasFocused = true;
RequestFocus(_searchBar);
2019-05-07 04:35:42 +02:00
}
}
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
var oldLength = e.OldTextValue?.Length ?? 0;
var newLength = e.NewTextValue?.Length ?? 0;
if(oldLength < 2 && newLength < 2 && oldLength < newLength)
{
return;
}
2019-06-07 02:34:59 +02:00
_vm.Search(e.NewTextValue, 300);
2019-05-07 04:35:42 +02:00
}
private void SearchBar_SearchButtonPressed(object sender, EventArgs e)
{
_vm.Search((sender as SearchBar).Text);
}
private void BackButton_Clicked(object sender, EventArgs e)
{
GoBack();
}
protected override bool OnBackButtonPressed()
{
2019-05-21 04:18:34 +02:00
if(string.IsNullOrWhiteSpace(_autofillUrl))
{
return false;
}
2019-05-07 04:35:42 +02:00
GoBack();
return true;
}
private void GoBack()
{
2019-05-07 04:49:57 +02:00
if(!DoOnce())
{
return;
}
2019-05-21 04:18:34 +02:00
if(string.IsNullOrWhiteSpace(_autofillUrl))
{
Navigation.PopModalAsync(false);
}
else
{
_deviceActionService.CloseAutofill();
}
2019-05-07 04:35:42 +02:00
}
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
{
((ListView)sender).SelectedItem = null;
2019-05-07 04:49:57 +02:00
if(!DoOnce())
{
return;
}
2019-05-07 04:35:42 +02:00
if(e.SelectedItem is CipherView cipher)
{
await _vm.SelectCipherAsync(cipher);
}
}
}
}