Refactoring

This commit is contained in:
Michael Bucari-Tovo 2022-06-08 09:24:06 -06:00
parent 30ba69eca7
commit 31812bc2d9
4 changed files with 40 additions and 67 deletions

View file

@ -6,6 +6,7 @@ using LibationFileManager;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
@ -14,11 +15,16 @@ namespace LibationWinForms.GridView
/// <summary>The View Model base for the DataGridView</summary>
public abstract class GridEntry : AsyncNotifyPropertyChanged, IMemberComparable
{
public string AudibleProductId => Book.AudibleProductId;
public LibraryBook LibraryBook { get; protected set; }
protected Book Book => LibraryBook.Book;
[Browsable(false)] public string AudibleProductId => Book.AudibleProductId;
[Browsable(false)] public LibraryBook LibraryBook { get; protected set; }
[Browsable(false)] public float SeriesIndex { get; protected set; }
[Browsable(false)] public string LongDescription { get; protected set; }
[Browsable(false)] public abstract DateTime DateAdded { get; }
[Browsable(false)] protected Book Book => LibraryBook.Book;
#region Model properties exposed to the view
public abstract LiberateButtonStatus Liberate { get; }
public Image Cover
{
get => _cover;
@ -28,10 +34,7 @@ namespace LibationWinForms.GridView
NotifyPropertyChanged();
}
}
public float SeriesIndex { get; protected set; }
public string ProductRating { get; protected set; }
public string PurchaseDate { get; protected set; }
public string MyRating { get; protected set; }
public string Series { get; protected set; }
public string Title { get; protected set; }
public string Length { get; protected set; }
@ -40,10 +43,10 @@ namespace LibationWinForms.GridView
public string Category { get; protected set; }
public string Misc { get; protected set; }
public string Description { get; protected set; }
public string LongDescription { get; protected set; }
public abstract DateTime DateAdded { get; }
public string ProductRating { get; protected set; }
public string MyRating { get; protected set; }
public abstract string DisplayTags { get; }
public abstract LiberateButtonStatus Liberate { get; }
#endregion
#region Sorting
@ -98,9 +101,7 @@ namespace LibationWinForms.GridView
#region Static library display functions
/// <summary>
/// This information should not change during <see cref="GridEntry"/> lifetime, so call only once.
/// </summary>
/// <summary>This information should not change during <see cref="GridEntry"/> lifetime, so call only once.</summary>
protected static string GetDescriptionDisplay(Book book)
{
var doc = new HtmlAgilityPack.HtmlDocument();

View file

@ -3,6 +3,7 @@ using DataLayer;
using Dinah.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace LibationWinForms.GridView
@ -10,15 +11,16 @@ namespace LibationWinForms.GridView
/// <summary>The View Model for a LibraryBook that is ContentType.Product or ContentType.Episode</summary>
public class LibraryBookEntry : GridEntry
{
[Browsable(false)] public override DateTime DateAdded => LibraryBook.DateAdded;
[Browsable(false)] public SeriesEntry Parent { get; init; }
#region Model properties exposed to the view
private DateTime lastStatusUpdate = default;
private LiberatedStatus _bookStatus;
private LiberatedStatus? _pdfStatus;
public override DateTime DateAdded => LibraryBook.DateAdded;
public override string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated);
public override LiberateButtonStatus Liberate
{
get
@ -33,11 +35,10 @@ namespace LibationWinForms.GridView
return new LiberateButtonStatus { BookStatus = _bookStatus, PdfStatus = _pdfStatus, IsSeries = false };
}
}
public override string DisplayTags => string.Join("\r\n", Book.UserDefinedItem.TagsEnumerated);
#endregion
public SeriesEntry Parent { get; init; }
public LibraryBookEntry(LibraryBook libraryBook)
{
setLibraryBook(libraryBook);

View file

@ -2,6 +2,7 @@
using Dinah.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace LibationWinForms.GridView
@ -9,10 +10,15 @@ namespace LibationWinForms.GridView
/// <summary>The View Model for a LibraryBook that is ContentType.Parent</summary>
public class SeriesEntry : GridEntry
{
public List<LibraryBookEntry> Children { get; }
public override DateTime DateAdded => Children.Max(c => c.DateAdded);
public override string DisplayTags { get; } = string.Empty;
[Browsable(false)] public List<LibraryBookEntry> Children { get; }
[Browsable(false)] public override DateTime DateAdded => Children.Max(c => c.DateAdded);
#region Model properties exposed to the view
public override LiberateButtonStatus Liberate { get; }
public override string DisplayTags { get; } = string.Empty;
#endregion
private SeriesEntry(LibraryBook parent)
{