Simplify and rename filter methods

This commit is contained in:
Dean Herbert 2017-12-16 16:27:39 +09:00
parent 3c406662ed
commit df7e795aa3
2 changed files with 17 additions and 14 deletions

View File

@ -67,7 +67,7 @@ public IEnumerable<BeatmapSetInfo> BeatmapSets
Task.Run(() =>
{
value.Select(createCarouselSet).Where(g => g != null).ForEach(newRoot.AddChild);
newRoot.Filter(criteria);
newRoot.Filter(activeCriteria);
}).ContinueWith(t =>
{
Schedule(() =>
@ -149,7 +149,7 @@ public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet)
root.AddChild(newSet);
Filter(debounce: false);
applyActiveCriteria(false);
//check if we can/need to maintain our current selection.
if (hadSelection)
@ -158,7 +158,7 @@ public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet)
updateItems();
}
public void SelectBeatmap(BeatmapInfo beatmap, bool animated = true)
public void SelectBeatmap(BeatmapInfo beatmap)
{
if (beatmap == null || beatmap.Hidden)
{
@ -212,14 +212,12 @@ public void SelectNext(int direction = 1, bool skipDifficulties = true)
}
}
private IEnumerable<CarouselBeatmapSet> getVisibleSets() => beatmapSets.Where(select => !select.Filtered);
public void SelectNextRandom()
{
if (!beatmapSets.Any())
return;
var visible = getVisibleSets().ToList();
var visible = beatmapSets.Where(select => !select.Filtered).ToList();
if (!visible.Any())
return;
@ -269,28 +267,33 @@ public void SelectPreviousRandom()
}
}
private FilterCriteria criteria = new FilterCriteria();
private FilterCriteria activeCriteria = new FilterCriteria();
protected ScheduledDelegate FilterTask;
public bool AllowSelection = true;
public void FlushPendingFilters()
public void FlushPendingFilterOperations()
{
if (FilterTask?.Completed == false)
Filter(debounce: false);
applyActiveCriteria(false);
}
public void Filter(FilterCriteria newCriteria = null, bool debounce = true)
public void Filter(FilterCriteria newCriteria, bool debounce = true)
{
if (newCriteria != null)
criteria = newCriteria;
activeCriteria = newCriteria;
applyActiveCriteria(debounce);
}
private void applyActiveCriteria(bool debounce)
{
Action perform = delegate
{
FilterTask = null;
root.Filter(criteria);
root.Filter(activeCriteria);
updateItems();
ScrollToSelected(false);

View File

@ -212,7 +212,7 @@ public void Start(BeatmapInfo beatmap)
{
// if we have a pending filter operation, we want to run it now.
// it could change selection (ie. if the ruleset has been changed).
carousel.FlushPendingFilters();
carousel.FlushPendingFilterOperations();
if (selectionChangedDebounce?.Completed == false)
{
@ -447,7 +447,7 @@ private void onBeatmapHidden(BeatmapInfo beatmap)
private void carouselBeatmapsLoaded()
{
if (Beatmap.Value.BeatmapSetInfo?.DeletePending == false)
carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo, false);
carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo);
else
carousel.SelectNextRandom();
}