2019-08-29 02:27:15 +02:00
|
|
|
|
using System;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
using Bit.iOS.Autofill.Models;
|
|
|
|
|
using Foundation;
|
|
|
|
|
using UIKit;
|
|
|
|
|
using Bit.iOS.Core.Controllers;
|
2024-02-08 20:05:26 +01:00
|
|
|
|
using Bit.Core.Resources.Localization;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
using Bit.iOS.Core.Views;
|
|
|
|
|
using Bit.iOS.Autofill.Utilities;
|
2019-07-01 21:12:40 +02:00
|
|
|
|
using Bit.iOS.Core.Utilities;
|
2021-05-21 15:13:54 +02:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.Core.Utilities;
|
2019-06-28 14:21:44 +02:00
|
|
|
|
|
|
|
|
|
namespace Bit.iOS.Autofill
|
|
|
|
|
{
|
|
|
|
|
public partial class LoginSearchViewController : ExtendedUITableViewController
|
|
|
|
|
{
|
|
|
|
|
public LoginSearchViewController(IntPtr handle)
|
|
|
|
|
: base(handle)
|
2020-10-15 20:34:31 +02:00
|
|
|
|
{
|
|
|
|
|
DismissModalAction = Cancel;
|
2021-05-21 15:13:54 +02:00
|
|
|
|
PasswordRepromptService = ServiceContainer.Resolve<IPasswordRepromptService>("passwordRepromptService");
|
2020-10-15 20:34:31 +02:00
|
|
|
|
}
|
2019-06-28 14:21:44 +02:00
|
|
|
|
|
|
|
|
|
public Context Context { get; set; }
|
|
|
|
|
public CredentialProviderViewController CPViewController { get; set; }
|
2019-07-03 01:35:01 +02:00
|
|
|
|
public bool FromList { get; set; }
|
2021-05-21 15:13:54 +02:00
|
|
|
|
public IPasswordRepromptService PasswordRepromptService { get; private set; }
|
2019-06-28 14:21:44 +02:00
|
|
|
|
|
|
|
|
|
public async override void ViewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
base.ViewDidLoad();
|
|
|
|
|
NavItem.Title = AppResources.SearchVault;
|
|
|
|
|
CancelBarButton.Title = AppResources.Cancel;
|
|
|
|
|
SearchBar.Placeholder = AppResources.Search;
|
2019-07-03 01:36:11 +02:00
|
|
|
|
SearchBar.BackgroundColor = SearchBar.BarTintColor = ThemeHelpers.ListHeaderBackgroundColor;
|
2022-06-07 16:43:25 +02:00
|
|
|
|
SearchBar.UpdateThemeIfNeeded();
|
2019-06-28 14:21:44 +02:00
|
|
|
|
|
|
|
|
|
TableView.RowHeight = UITableView.AutomaticDimension;
|
|
|
|
|
TableView.EstimatedRowHeight = 44;
|
|
|
|
|
TableView.Source = new TableSource(this);
|
|
|
|
|
SearchBar.Delegate = new ExtensionSearchDelegate(TableView);
|
|
|
|
|
await ((TableSource)TableView.Source).LoadItemsAsync(false, SearchBar.Text);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 15:23:41 +02:00
|
|
|
|
public override void ViewDidAppear(bool animated)
|
|
|
|
|
{
|
|
|
|
|
base.ViewDidAppear(animated);
|
|
|
|
|
SearchBar?.BecomeFirstResponder();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 14:21:44 +02:00
|
|
|
|
partial void CancelBarButton_Activated(UIBarButtonItem sender)
|
2020-10-15 20:34:31 +02:00
|
|
|
|
{
|
|
|
|
|
Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Cancel()
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (FromList)
|
2019-07-03 01:35:01 +02:00
|
|
|
|
{
|
|
|
|
|
DismissViewController(true, null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CPViewController.CompleteRequest();
|
|
|
|
|
}
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void AddBarButton_Activated(UIBarButtonItem sender)
|
|
|
|
|
{
|
|
|
|
|
PerformSegue("loginAddFromSearchSegue", this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (segue.DestinationViewController is UINavigationController navController)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (navController.TopViewController is LoginAddViewController addLoginController)
|
2019-06-28 14:21:44 +02:00
|
|
|
|
{
|
|
|
|
|
addLoginController.Context = Context;
|
|
|
|
|
addLoginController.LoginSearchController = this;
|
2020-10-15 20:34:31 +02:00
|
|
|
|
segue.DestinationViewController.PresentationController.Delegate =
|
|
|
|
|
new CustomPresentationControllerDelegate(addLoginController.DismissModalAction);
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DismissModal()
|
|
|
|
|
{
|
|
|
|
|
DismissViewController(true, async () =>
|
|
|
|
|
{
|
|
|
|
|
await ((TableSource)TableView.Source).LoadItemsAsync(false, SearchBar.Text);
|
|
|
|
|
TableView.ReloadData();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TableSource : ExtensionTableSource
|
|
|
|
|
{
|
|
|
|
|
private Context _context;
|
|
|
|
|
private LoginSearchViewController _controller;
|
|
|
|
|
|
|
|
|
|
public TableSource(LoginSearchViewController controller)
|
|
|
|
|
: base(controller.Context, controller)
|
|
|
|
|
{
|
|
|
|
|
_context = controller.Context;
|
|
|
|
|
_controller = controller;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async override void RowSelected(UITableView tableView, NSIndexPath indexPath)
|
|
|
|
|
{
|
|
|
|
|
await AutofillHelpers.TableRowSelectedAsync(tableView, indexPath, this,
|
2021-05-21 15:13:54 +02:00
|
|
|
|
_controller.CPViewController, _controller, _controller.PasswordRepromptService,
|
|
|
|
|
"loginAddFromSearchSegue");
|
2019-06-28 14:21:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|