mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
throttle fast type searches
This commit is contained in:
parent
07dd9df3ec
commit
f394eddc01
2 changed files with 27 additions and 3 deletions
|
@ -8,6 +8,7 @@ using Bit.iOS.Core.Controllers;
|
|||
using Bit.App.Resources;
|
||||
using Bit.iOS.Core.Views;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.iOS.Autofill
|
||||
{
|
||||
|
@ -163,6 +164,7 @@ namespace Bit.iOS.Autofill
|
|||
public class SearchDelegate : UISearchBarDelegate
|
||||
{
|
||||
private readonly LoginSearchViewController _controller;
|
||||
private CancellationTokenSource _filterResultsCancellationTokenSource;
|
||||
|
||||
public SearchDelegate(LoginSearchViewController controller)
|
||||
{
|
||||
|
@ -171,9 +173,29 @@ namespace Bit.iOS.Autofill
|
|||
|
||||
public override void TextChanged(UISearchBar searchBar, string searchText)
|
||||
{
|
||||
((TableSource)_controller.TableView.Source).FilterResults(searchText, new CancellationToken());
|
||||
var cts = new CancellationTokenSource();
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(searchText))
|
||||
{
|
||||
await Task.Delay(300);
|
||||
if(searchText != searchBar.Text)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_filterResultsCancellationTokenSource?.Cancel();
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
((TableSource)_controller.TableView.Source).FilterResults(searchText, cts.Token);
|
||||
_controller.TableView.ReloadData();
|
||||
}
|
||||
catch(OperationCanceledException) { }
|
||||
}, cts.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,9 @@ namespace Bit.iOS.Core.Views
|
|||
combinedLogins.AddRange(logins);
|
||||
}
|
||||
|
||||
_allItems = combinedLogins.Select(s => new CipherViewModel(s))
|
||||
_allItems = combinedLogins
|
||||
.Where(c => c.Type == App.Enums.CipherType.Login)
|
||||
.Select(s => new CipherViewModel(s))
|
||||
.OrderBy(s => s.Name)
|
||||
.ThenBy(s => s.Username)
|
||||
.ToList() ?? new List<CipherViewModel>();
|
||||
|
|
Loading…
Reference in a new issue