2019-05-20 22:18:34 -04:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Resources;
|
2019-05-06 22:35:42 -04:00
|
|
|
|
using Bit.Core.Models.View;
|
2019-05-20 22:18:34 -04:00
|
|
|
|
using Bit.Core.Utilities;
|
2019-05-06 22:35:42 -04:00
|
|
|
|
using System;
|
|
|
|
|
using Xamarin.Forms;
|
2019-05-02 21:25:26 -04:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public partial class CiphersPage : BaseContentPage
|
|
|
|
|
{
|
2019-05-20 22:18:34 -04:00
|
|
|
|
private readonly string _autofillUrl;
|
|
|
|
|
private readonly IDeviceActionService _deviceActionService;
|
|
|
|
|
|
2019-05-02 21:25:26 -04:00
|
|
|
|
private CiphersPageViewModel _vm;
|
2019-05-06 22:35:42 -04:00
|
|
|
|
private bool _hasFocused;
|
2019-05-02 21:25:26 -04:00
|
|
|
|
|
2019-05-06 22:35:42 -04:00
|
|
|
|
public CiphersPage(Func<CipherView, bool> filter, bool folder = false, bool collection = false,
|
2019-05-20 22:18:34 -04:00
|
|
|
|
bool type = false, string autofillUrl = null)
|
2019-05-02 21:25:26 -04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_vm = BindingContext as CiphersPageViewModel;
|
|
|
|
|
_vm.Page = this;
|
2019-05-06 22:35:42 -04:00
|
|
|
|
_vm.Filter = filter;
|
2019-05-20 22:18:34 -04:00
|
|
|
|
_vm.AutofillUrl = _autofillUrl = autofillUrl;
|
2019-05-06 22:35:42 -04: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-20 22:18:34 -04:00
|
|
|
|
|
2019-06-14 17:40:21 -04:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
2019-06-11 21:31:51 -04:00
|
|
|
|
{
|
2019-06-14 17:40:21 -04:00
|
|
|
|
ToolbarItems.Add(_closeItem);
|
2019-06-24 11:53:19 -04:00
|
|
|
|
_searchBar.Placeholder = AppResources.Search;
|
|
|
|
|
_mainLayout.Children.Insert(0, _searchBar);
|
|
|
|
|
_mainLayout.Children.Insert(1, _separator);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NavigationPage.SetTitleView(this, _titleLayout);
|
2019-06-11 21:31:51 -04:00
|
|
|
|
}
|
2019-05-20 22:18:34 -04:00
|
|
|
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
2019-05-02 21:25:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 22:35:42 -04:00
|
|
|
|
public SearchBar SearchBar => _searchBar;
|
|
|
|
|
|
2019-06-08 12:18:49 -04:00
|
|
|
|
protected async override void OnAppearing()
|
2019-05-02 21:25:26 -04:00
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2019-06-08 12:18:49 -04:00
|
|
|
|
await _vm.InitAsync();
|
2019-05-06 22:35:42 -04:00
|
|
|
|
if(!_hasFocused)
|
|
|
|
|
{
|
|
|
|
|
_hasFocused = true;
|
2019-06-06 09:39:48 -04:00
|
|
|
|
RequestFocus(_searchBar);
|
2019-05-06 22:35:42 -04: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-12 08:12:55 -04:00
|
|
|
|
_vm.Search(e.NewTextValue, 500);
|
2019-05-06 22:35:42 -04: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-20 22:18:34 -04:00
|
|
|
|
if(string.IsNullOrWhiteSpace(_autofillUrl))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-05-06 22:35:42 -04:00
|
|
|
|
GoBack();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GoBack()
|
|
|
|
|
{
|
2019-05-06 22:49:57 -04:00
|
|
|
|
if(!DoOnce())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-20 22:18:34 -04:00
|
|
|
|
if(string.IsNullOrWhiteSpace(_autofillUrl))
|
|
|
|
|
{
|
|
|
|
|
Navigation.PopModalAsync(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_deviceActionService.CloseAutofill();
|
|
|
|
|
}
|
2019-05-06 22:35:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
((ListView)sender).SelectedItem = null;
|
2019-05-06 22:49:57 -04:00
|
|
|
|
if(!DoOnce())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 22:35:42 -04:00
|
|
|
|
if(e.SelectedItem is CipherView cipher)
|
|
|
|
|
{
|
|
|
|
|
await _vm.SelectCipherAsync(cipher);
|
|
|
|
|
}
|
2019-05-02 21:25:26 -04:00
|
|
|
|
}
|
2019-06-11 21:31:51 -04:00
|
|
|
|
|
2019-06-14 17:40:21 -04:00
|
|
|
|
private void Close_Clicked(object sender, EventArgs e)
|
2019-06-11 21:31:51 -04:00
|
|
|
|
{
|
2019-06-14 17:40:21 -04:00
|
|
|
|
GoBack();
|
2019-06-11 21:31:51 -04:00
|
|
|
|
}
|
2019-05-02 21:25:26 -04:00
|
|
|
|
}
|
|
|
|
|
}
|