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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

138 lines
3.8 KiB
C#
Raw Normal View History

2019-05-21 04:18:34 +02:00
using System;
using System.Linq;
using Bit.App.Controls;
using Bit.App.Models;
2019-05-21 04:18:34 +02:00
using Bit.App.Resources;
using Bit.Core.Abstractions;
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 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 IAutofillHandler _autofillHandler;
2019-05-21 04:18:34 +02:00
private CiphersPageViewModel _vm;
2019-05-07 04:35:42 +02:00
private bool _hasFocused;
public CiphersPage(Func<CipherView, bool> filter,
string pageTitle = null,
string vaultFilterSelection = null,
bool deleted = false,
AppOptions appOptions = null)
{
InitializeComponent();
_vm = BindingContext as CiphersPageViewModel;
_vm.Page = this;
_autofillUrl = appOptions?.Uri;
_vm.Prepare(filter, deleted, appOptions);
if (pageTitle != null)
{
_vm.PageTitle = string.Format(AppResources.SearchGroup, pageTitle);
2019-05-07 04:35:42 +02:00
}
else
{
_vm.PageTitle = AppResources.SearchVault;
}
_vm.VaultFilterDescription = vaultFilterSelection;
2019-05-21 04:18:34 +02:00
if (Device.RuntimePlatform == Device.iOS)
2019-06-12 03:31:51 +02:00
{
2019-06-14 23:40:21 +02:00
ToolbarItems.Add(_closeItem);
2019-06-24 17:53:19 +02:00
_searchBar.Placeholder = AppResources.Search;
_mainLayout.Children.Insert(0, _searchBar);
_mainLayout.Children.Insert(1, _separator);
ShowModalAnimationDelay = 0;
2019-06-24 17:53:19 +02:00
}
else
{
NavigationPage.SetTitleView(this, _titleLayout);
2019-06-12 03:31:51 +02:00
}
_autofillHandler = ServiceContainer.Resolve<IAutofillHandler>();
}
2019-05-07 04:35:42 +02:00
public SearchBar SearchBar => _searchBar;
2019-06-08 18:18:49 +02:00
protected async override void OnAppearing()
{
base.OnAppearing();
2019-06-08 18:18:49 +02:00
await _vm.InitAsync();
if (!_hasFocused)
2019-05-07 04:35:42 +02:00
{
_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)
2019-05-07 04:35:42 +02:00
{
return;
}
_vm.Search(e.NewTextValue, 200);
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()
{
if (string.IsNullOrWhiteSpace(_autofillUrl))
2019-05-21 04:18:34 +02:00
{
return false;
}
2019-05-07 04:35:42 +02:00
GoBack();
return true;
}
private void GoBack()
{
if (!DoOnce())
2019-05-07 04:49:57 +02:00
{
return;
}
if (string.IsNullOrWhiteSpace(_autofillUrl))
2019-05-21 04:18:34 +02:00
{
Navigation.PopModalAsync(false);
}
else
{
_autofillHandler.CloseAutofill();
2019-05-21 04:18:34 +02:00
}
2019-05-07 04:35:42 +02:00
}
private async void RowSelected(object sender, SelectionChangedEventArgs e)
2019-05-07 04:35:42 +02:00
{
((ExtendedCollectionView)sender).SelectedItem = null;
if (!DoOnce())
2019-05-07 04:49:57 +02:00
{
return;
}
if (e.CurrentSelection?.FirstOrDefault() is CipherView cipher)
2019-05-07 04:35:42 +02:00
{
await _vm.SelectCipherAsync(cipher);
}
}
2019-06-12 03:31:51 +02:00
2019-06-14 23:40:21 +02:00
private void Close_Clicked(object sender, EventArgs e)
2019-06-12 03:31:51 +02:00
{
2019-06-14 23:40:21 +02:00
GoBack();
2019-06-12 03:31:51 +02:00
}
}
}