diff --git a/Source/LibationWinForms/GridView/GridEntry.cs b/Source/LibationWinForms/GridView/GridEntry.cs index b2e2ee21..69a23e10 100644 --- a/Source/LibationWinForms/GridView/GridEntry.cs +++ b/Source/LibationWinForms/GridView/GridEntry.cs @@ -17,7 +17,6 @@ namespace LibationWinForms.GridView public string AudibleProductId => Book.AudibleProductId; public LibraryBook LibraryBook { get; protected set; } protected Book Book => LibraryBook.Book; - private Image _cover; #region Model properties exposed to the view public Image Cover @@ -50,13 +49,13 @@ namespace LibationWinForms.GridView #region Sorting public GridEntry() => _memberValues = CreateMemberValueDictionary(); - private Dictionary> _memberValues { get; set; } - protected abstract Dictionary> CreateMemberValueDictionary(); // These methods are implementation of Dinah.Core.DataBinding.IMemberComparable // Used by GridEntryBindingList for all sorting public virtual object GetMemberValue(string memberName) => _memberValues[memberName](); public IComparer GetMemberComparer(Type memberType) => _memberTypeComparers[memberType]; + protected abstract Dictionary> CreateMemberValueDictionary(); + private Dictionary> _memberValues { get; set; } // Instantiate comparers for every exposed member object type. private static readonly Dictionary _memberTypeComparers = new() @@ -71,18 +70,19 @@ namespace LibationWinForms.GridView #endregion + #region Cover Art + + private Image _cover; protected void LoadCover() { // Get cover art. If it's default, subscribe to PictureCached - { - (bool isDefault, byte[] picture) = PictureStorage.GetPicture(new PictureDefinition(Book.PictureId, PictureSize._80x80)); + (bool isDefault, byte[] picture) = PictureStorage.GetPicture(new PictureDefinition(Book.PictureId, PictureSize._80x80)); - if (isDefault) - PictureStorage.PictureCached += PictureStorage_PictureCached; + if (isDefault) + PictureStorage.PictureCached += PictureStorage_PictureCached; - // Mutable property. Set the field so PropertyChanged isn't fired. - _cover = ImageReader.ToImage(picture); - } + // Mutable property. Set the field so PropertyChanged isn't fired. + _cover = ImageReader.ToImage(picture); } private void PictureStorage_PictureCached(object sender, PictureCachedEventArgs e) @@ -94,10 +94,12 @@ namespace LibationWinForms.GridView } } + #endregion + #region Static library display functions /// - /// This information should not change during lifetime, so call only once. + /// This information should not change during lifetime, so call only once. /// protected static string GetDescriptionDisplay(Book book) { @@ -116,7 +118,7 @@ namespace LibationWinForms.GridView /// - /// This information should not change during lifetime, so call only once. + /// This information should not change during lifetime, so call only once. /// Maximum of 5 text rows will fit in 80-pixel row height. /// protected static string GetMiscDisplay(LibraryBook libraryBook) diff --git a/Source/LibationWinForms/GridView/ProductsDisplay.cs b/Source/LibationWinForms/GridView/ProductsDisplay.cs index 5f91a581..7eb55455 100644 --- a/Source/LibationWinForms/GridView/ProductsDisplay.cs +++ b/Source/LibationWinForms/GridView/ProductsDisplay.cs @@ -87,7 +87,7 @@ namespace LibationWinForms.GridView try { // don't return early if lib size == 0. this will not update correctly if all books are removed - var lib = DbContexts.GetLibrary_Flat_NoTracking(); + var lib = DbContexts.GetLibrary_Flat_NoTracking(includeParents: true); if (!hasBeenDisplayed) { @@ -114,7 +114,7 @@ namespace LibationWinForms.GridView #endregion - internal List GetVisible() => productsGrid.GetVisible().Select(v => v.LibraryBook).ToList(); + internal List GetVisible() => productsGrid.GetVisibleBooks().ToList(); private void productsGrid_VisibleCountChanged(object sender, int count) { diff --git a/Source/LibationWinForms/GridView/ProductsGrid.cs b/Source/LibationWinForms/GridView/ProductsGrid.cs index b762a046..6305722f 100644 --- a/Source/LibationWinForms/GridView/ProductsGrid.cs +++ b/Source/LibationWinForms/GridView/ProductsGrid.cs @@ -25,9 +25,10 @@ namespace LibationWinForms.GridView public new event EventHandler Scroll; private GridEntryBindingList bindingList; - internal IEnumerable GetVisible() + internal IEnumerable GetVisibleBooks() => bindingList - .BookEntries(); + .BookEntries() + .Select(lbe => lbe.LibraryBook); public ProductsGrid() { diff --git a/Source/LibationWinForms/GridView/SeriesEntry.cs b/Source/LibationWinForms/GridView/SeriesEntry.cs index fd8411b8..e6882d77 100644 --- a/Source/LibationWinForms/GridView/SeriesEntry.cs +++ b/Source/LibationWinForms/GridView/SeriesEntry.cs @@ -14,52 +14,47 @@ namespace LibationWinForms.GridView public override string DisplayTags { get; } = string.Empty; public override LiberateButtonStatus Liberate { get; } - private SeriesEntry() + private SeriesEntry(LibraryBook parent) { Liberate = new LiberateButtonStatus { IsSeries = true }; SeriesIndex = -1; + LibraryBook = parent; + LoadCover(); } - public SeriesEntry(LibraryBook parent, IEnumerable children) : this() + public SeriesEntry(LibraryBook parent, IEnumerable children) : this(parent) { Children = children .Select(c => new LibraryBookEntry(c) { Parent = this }) .OrderBy(c => c.SeriesIndex) .ToList(); - UpdateSeries(parent); - LoadCover(); } - public SeriesEntry(LibraryBook parent, LibraryBook child) : this() + public SeriesEntry(LibraryBook parent, LibraryBook child) : this(parent) { Children = new() { new LibraryBookEntry(child) { Parent = this } }; - UpdateSeries(parent); - LoadCover(); } - public void UpdateSeries(LibraryBook libraryBook) + public void UpdateSeries(LibraryBook parent) { - LibraryBook = libraryBook; + LibraryBook = parent; - // Immutable properties - { - Title = Book.Title; - Series = Book.SeriesNames(); - MyRating = Book.UserDefinedItem.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace(""); - PurchaseDate = Children.Min(c => c.LibraryBook.DateAdded).ToString("d"); - ProductRating = Book.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace(""); - Authors = Book.AuthorNames(); - Narrators = Book.NarratorNames(); - Category = string.Join(" > ", Book.CategoriesNames()); - Misc = GetMiscDisplay(libraryBook); - LongDescription = GetDescriptionDisplay(Book); - Description = TrimTextToWord(LongDescription, 62); + Title = Book.Title; + Series = Book.SeriesNames(); + MyRating = Book.UserDefinedItem.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace(""); + PurchaseDate = Children.Min(c => c.LibraryBook.DateAdded).ToString("d"); + ProductRating = Book.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace(""); + Authors = Book.AuthorNames(); + Narrators = Book.NarratorNames(); + Category = string.Join(" > ", Book.CategoriesNames()); + Misc = GetMiscDisplay(LibraryBook); + LongDescription = GetDescriptionDisplay(Book); + Description = TrimTextToWord(LongDescription, 62); - int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes); - Length = bookLenMins == 0 ? "" : $"{bookLenMins / 60} hr {bookLenMins % 60} min"; - } + int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes); + Length = bookLenMins == 0 ? "" : $"{bookLenMins / 60} hr {bookLenMins % 60} min"; NotifyPropertyChanged(); }