All books that pass the filter are counted as "visible" (#536)

This commit is contained in:
MBucari 2023-03-17 19:31:36 -06:00
parent 2725340994
commit 18cf20ecad
3 changed files with 35 additions and 14 deletions

View File

@ -5,7 +5,6 @@ using Avalonia.Threading;
using DataLayer; using DataLayer;
using LibationAvalonia.Dialogs.Login; using LibationAvalonia.Dialogs.Login;
using LibationUiBase.GridView; using LibationUiBase.GridView;
using NPOI.SS.Formula.Functions;
using ReactiveUI; using ReactiveUI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -32,10 +31,14 @@ namespace LibationAvalonia.ViewModels
public bool RemoveColumnVisivle { get => _removeColumnVisivle; private set => this.RaiseAndSetIfChanged(ref _removeColumnVisivle, value); } public bool RemoveColumnVisivle { get => _removeColumnVisivle; private set => this.RaiseAndSetIfChanged(ref _removeColumnVisivle, value); }
public List<LibraryBook> GetVisibleBookEntries() public List<LibraryBook> GetVisibleBookEntries()
=> GridEntries => FilteredInGridEntries?
.OfType<ILibraryBookEntry>() .OfType<ILibraryBookEntry>()
.Select(lbe => lbe.LibraryBook) .Select(lbe => lbe.LibraryBook)
.ToList(); .ToList()
?? SOURCE
.OfType<ILibraryBookEntry>()
.Select(lbe => lbe.LibraryBook)
.ToList();
private IEnumerable<ILibraryBookEntry> GetAllBookEntries() private IEnumerable<ILibraryBookEntry> GetAllBookEntries()
=> SOURCE => SOURCE
@ -122,7 +125,13 @@ namespace LibationAvalonia.ViewModels
} }
private void GridEntries_CollectionChanged(object sender = null, EventArgs e = null) private void GridEntries_CollectionChanged(object sender = null, EventArgs e = null)
=> VisibleCountChanged?.Invoke(this, GridEntries.OfType<ILibraryBookEntry>().Count()); {
var count
= FilteredInGridEntries?.OfType<ILibraryBookEntry>().Count()
?? SOURCE.OfType<ILibraryBookEntry>().Count();
VisibleCountChanged?.Invoke(this, count);
}
/// <summary> /// <summary>
/// Call when there's been a change to the library /// Call when there's been a change to the library

View File

@ -28,6 +28,18 @@ namespace LibationWinForms.GridView
/// <returns>All items in the list, including those filtered out.</returns> /// <returns>All items in the list, including those filtered out.</returns>
public List<IGridEntry> AllItems() => Items.Concat(FilterRemoved).ToList(); public List<IGridEntry> AllItems() => Items.Concat(FilterRemoved).ToList();
/// <summary>All items that pass the current filter</summary>
public IEnumerable<ILibraryBookEntry> GetFilteredInItems()
=> SearchResults is null
? FilterRemoved
.OfType<ILibraryBookEntry>()
.Union(Items.OfType<ILibraryBookEntry>())
: FilterRemoved
.OfType<ILibraryBookEntry>()
.Join(SearchResults.Docs, o => o.Book.AudibleProductId, i => i.ProductId, (o, _) => o)
.Union(Items.OfType<ILibraryBookEntry>());
public bool SupportsFiltering => true; public bool SupportsFiltering => true;
public string Filter { get => FilterString; set => ApplyFilter(value); } public string Filter { get => FilterString; set => ApplyFilter(value); }
@ -102,7 +114,7 @@ namespace LibationWinForms.GridView
public void CollapseItem(ISeriesEntry sEntry) public void CollapseItem(ISeriesEntry sEntry)
{ {
foreach (var episode in Items.BookEntries().Where(b => b.Parent == sEntry).ToList()) foreach (var episode in sEntry.Children.Join(Items.BookEntries(), o => o, i => i, (_, i) => i).ToList())
{ {
FilterRemoved.Add(episode); FilterRemoved.Add(episode);
base.Remove(episode); base.Remove(episode);
@ -115,7 +127,7 @@ namespace LibationWinForms.GridView
{ {
var sindex = Items.IndexOf(sEntry); var sindex = Items.IndexOf(sEntry);
foreach (var episode in FilterRemoved.BookEntries().Where(b => b.Parent == sEntry).ToList()) foreach (var episode in sEntry.Children.Join(FilterRemoved.BookEntries(), o => o, i => i, (_, i) => i).ToList())
{ {
if (SearchResults is null || SearchResults.Docs.Any(d => d.ProductId == episode.AudibleProductId)) if (SearchResults is null || SearchResults.Docs.Any(d => d.ProductId == episode.AudibleProductId))
{ {

View File

@ -7,7 +7,6 @@ using LibationWinForms.Dialogs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -34,7 +33,7 @@ namespace LibationWinForms.GridView
private GridEntryBindingList bindingList; private GridEntryBindingList bindingList;
internal IEnumerable<LibraryBook> GetVisibleBooks() internal IEnumerable<LibraryBook> GetVisibleBooks()
=> bindingList => bindingList
.BookEntries() .GetFilteredInItems()
.Select(lbe => lbe.LibraryBook); .Select(lbe => lbe.LibraryBook);
internal IEnumerable<ILibraryBookEntry> GetAllBookEntries() internal IEnumerable<ILibraryBookEntry> GetAllBookEntries()
=> bindingList.AllItems().BookEntries(); => bindingList.AllItems().BookEntries();
@ -84,7 +83,7 @@ namespace LibationWinForms.GridView
else else
bindingList.ExpandItem(sEntry); bindingList.ExpandItem(sEntry);
VisibleCountChanged?.Invoke(this, bindingList.BookEntries().Count()); VisibleCountChanged?.Invoke(this, bindingList.GetFilteredInItems().Count());
} }
else if (e.ColumnIndex == descriptionGVColumn.Index) else if (e.ColumnIndex == descriptionGVColumn.Index)
DescriptionClicked?.Invoke(sEntry, gridEntryDataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false)); DescriptionClicked?.Invoke(sEntry, gridEntryDataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false));
@ -248,7 +247,7 @@ namespace LibationWinForms.GridView
bindingList = new GridEntryBindingList(geList.OrderByDescending(e => e.DateAdded)); bindingList = new GridEntryBindingList(geList.OrderByDescending(e => e.DateAdded));
bindingList.CollapseAll(); bindingList.CollapseAll();
syncBindingSource.DataSource = bindingList; syncBindingSource.DataSource = bindingList;
VisibleCountChanged?.Invoke(this, bindingList.BookEntries().Count()); VisibleCountChanged?.Invoke(this, bindingList.GetFilteredInItems().Count());
} }
internal void UpdateGrid(List<LibraryBook> dbBooks) internal void UpdateGrid(List<LibraryBook> dbBooks)
@ -317,7 +316,7 @@ namespace LibationWinForms.GridView
//no need to re-filter for removed books //no need to re-filter for removed books
bindingList.Remove(removed); bindingList.Remove(removed);
VisibleCountChanged?.Invoke(this, bindingList.BookEntries().Count()); VisibleCountChanged?.Invoke(this, bindingList.GetFilteredInItems().Count());
} }
private void AddOrUpdateBook(LibraryBook book, ILibraryBookEntry existingBookEntry) private void AddOrUpdateBook(LibraryBook book, ILibraryBookEntry existingBookEntry)
@ -364,6 +363,7 @@ namespace LibationWinForms.GridView
//Series exists. Create and add episode child then update the SeriesEntry //Series exists. Create and add episode child then update the SeriesEntry
episodeEntry = new LibraryBookEntry<WinFormsEntryStatus>(episodeBook, seriesEntry); episodeEntry = new LibraryBookEntry<WinFormsEntryStatus>(episodeBook, seriesEntry);
seriesEntry.Children.Add(episodeEntry); seriesEntry.Children.Add(episodeEntry);
seriesEntry.Children.Sort((c1,c2) => c1.SeriesIndex.CompareTo(c2.SeriesIndex));
var seriesBook = dbBooks.Single(lb => lb.Book.AudibleProductId == seriesEntry.LibraryBook.Book.AudibleProductId); var seriesBook = dbBooks.Single(lb => lb.Book.AudibleProductId == seriesEntry.LibraryBook.Book.AudibleProductId);
seriesEntry.UpdateLibraryBook(seriesBook); seriesEntry.UpdateLibraryBook(seriesBook);
} }
@ -395,7 +395,7 @@ namespace LibationWinForms.GridView
syncBindingSource.Filter = searchString; syncBindingSource.Filter = searchString;
if (visibleCount != bindingList.Count) if (visibleCount != bindingList.Count)
VisibleCountChanged?.Invoke(this, bindingList.BookEntries().Count()); VisibleCountChanged?.Invoke(this, bindingList.GetFilteredInItems().Count());
} }
#endregion #endregion