Skip to content
Permalink
Browse files

Fix Search and Improve Speed and Responsiveness of Unrecognized Utility

  • Loading branch information
da3dsoul committed Oct 30, 2019
1 parent 5fe0668 commit 431756b9bd2d2d2b24130b6afec8b0da56bc97d3
Showing with 60 additions and 30 deletions.
  1. +60 −30 Shoko.Desktop/UserControls/UnrecognisedVideos.xaml.cs
@@ -42,7 +42,7 @@ public partial class UnrecognisedVideos : UserControl
public ICollectionView ViewSeries { get; set; }
public ObservableCollection<VM_AnimeSeries_User> AllSeries { get; set; }

private List<VM_AnimeSeries_User> Series { get; set; }
private List<VM_AnimeSeries_User> Series { get; set; } = new List<VM_AnimeSeries_User>();

public static readonly DependencyProperty AnyVideosSelectedProperty = DependencyProperty.Register("AnyVideosSelected",
typeof(bool), typeof(UnrecognisedVideos), new UIPropertyMetadata(false, null));
@@ -968,7 +968,7 @@ public void RefreshSeries(bool all=false)
}
}

public async void SearchAnime(object argument)
public void SearchAnime(object argument)
{
try
{
@@ -991,41 +991,71 @@ public async void SearchAnime(object argument)

try
{
series = await Task.FromResult(SearchAnime(tokenSource, argument));
Task.Factory.StartNew(() => SearchAnime(tokenSource, argument));
}
catch (TaskCanceledException)
{
// ignored
}
}

bool cancelled = runningTask.IsCancellationRequested;
runningTask = null;

if (cancelled) return;
private void EnableSeriesControls()
{
Application.Current?.Dispatcher?.Invoke(() =>
{
txtSeriesSearch.IsEnabled = true;
btnAddSeries.IsEnabled = true;
cboEpisodes.IsEnabled = true;
cboMultiType.IsEnabled = true;
lbSeries.IsEnabled = true;
});
}

// update
if (series != null)
private void SearchAnime(CancellationTokenSource token, object argument)
{
try
{
AllSeries.Clear();
series.ForEach(a => AllSeries.Add(a));
if (token.IsCancellationRequested)
{
EnableSeriesControls();
runningTask = null;
return;
}

if (AllSeries.Count >= 1)
lbSeries.SelectedIndex = 0;
}
List<VM_AnimeSeries_User> tempAnime = new List<VM_AnimeSeries_User>();
SearchAnime(token.Token, argument, tempAnime);

txtSeriesSearch.IsEnabled = true;
btnAddSeries.IsEnabled = true;
cboEpisodes.IsEnabled = true;
cboMultiType.IsEnabled = true;
lbSeries.IsEnabled = true;
}
if (token.IsCancellationRequested)
{
runningTask = null;
EnableSeriesControls();
return;
}

private List<VM_AnimeSeries_User> SearchAnime(CancellationTokenSource token, object argument)
{
if (token.IsCancellationRequested) return null;
List<VM_AnimeSeries_User> tempAnime = new List<VM_AnimeSeries_User>();
SearchAnime(token.Token, argument, tempAnime);
return token.IsCancellationRequested ? null : tempAnime;
Application.Current?.Dispatcher?.Invoke(() =>
{
AllSeries.Clear();
tempAnime.ForEach(a => AllSeries.Add(a));

if (AllSeries.Count >= 1)
lbSeries.SelectedIndex = 0;

// Duplicate, but doing it here to avoid multiple Dispatcher Invokes
txtSeriesSearch.IsEnabled = true;
btnAddSeries.IsEnabled = true;
cboEpisodes.IsEnabled = true;
cboMultiType.IsEnabled = true;
lbSeries.IsEnabled = true;
});

runningTask = null;
}
catch (Exception e)
{
EnableSeriesControls();
runningTask = null;
logger.Error(e);
}
}

private void SearchAnime(CancellationToken token, object argument, List<VM_AnimeSeries_User> tempAnime)
@@ -1044,7 +1074,7 @@ private void SearchAnime(CancellationToken token, object argument, List<VM_Anime
}
}

if (vidLocals == null)
if (vidLocals == null || vidLocals.Count == 0)
{
Series.Clear();
foreach (VM_AnimeSeries_User anime in VM_ShokoServer.Instance.ShokoServices
@@ -1099,8 +1129,8 @@ private void SearchAnime(CancellationToken token, object argument, List<VM_Anime
}

if (Series.Count == 0)
VM_ShokoServer.Instance.ShokoServices
.GetAllSeries(VM_ShokoServer.Instance.CurrentUser.JMMUserID).CastList<VM_AnimeSeries_User>();
Series.AddRange(VM_ShokoServer.Instance.ShokoServices
.GetAllSeries(VM_ShokoServer.Instance.CurrentUser.JMMUserID).CastList<VM_AnimeSeries_User>());


foreach (VM_AnimeSeries_User anime in Series)
@@ -1118,7 +1148,7 @@ private bool SeriesSearchFilter(object obj)
VM_AnimeSeries_User servm = obj as VM_AnimeSeries_User;
if (servm == null) return true;

return GroupSearchFilterHelper.EvaluateSeriesTextSearch(servm, txtSeriesSearch.Text.Replace("'", "`"));
return GroupSearchFilterHelper.EvaluateSeriesTextSearch(servm, txtSeriesSearch.Text);
}

private bool FileSearchFilter(object obj)

0 comments on commit 431756b

Please sign in to comment.
You can’t perform that action at this time.