From 35ca6f26213fb30f8dcc5ff7286a050c5edf8d9e Mon Sep 17 00:00:00 2001 From: MBucari Date: Tue, 15 Jul 2025 22:50:28 -0600 Subject: [PATCH] Use built-in comparer and ReactiveObject types --- Source/LibationUiBase/GridView/EntryStatus.cs | 5 +-- .../GridView/GridEntry[TStatus].cs | 35 ++++++------------- .../GridView/ObjectComparer[T].cs | 10 ------ 3 files changed, 12 insertions(+), 38 deletions(-) delete mode 100644 Source/LibationUiBase/GridView/ObjectComparer[T].cs diff --git a/Source/LibationUiBase/GridView/EntryStatus.cs b/Source/LibationUiBase/GridView/EntryStatus.cs index 1e8bfc0d..95a5dc17 100644 --- a/Source/LibationUiBase/GridView/EntryStatus.cs +++ b/Source/LibationUiBase/GridView/EntryStatus.cs @@ -16,9 +16,8 @@ namespace LibationUiBase.GridView //This Class holds all book entry status info to help the grid properly render entries. //The reason this info is in here instead of GridEntry is because all of this info is needed //for the "Liberate" column's display and sorting functions. - public abstract class EntryStatus : SynchronizeInvoker, IComparable, INotifyPropertyChanged + public abstract class EntryStatus : ReactiveObject, IComparable { - public event PropertyChangedEventHandler PropertyChanged; public LiberatedStatus? PdfStatus => LibraryCommands.Pdf_Status(Book); public LiberatedStatus BookStatus { @@ -81,8 +80,6 @@ namespace LibationUiBase.GridView internal protected abstract object LoadImage(byte[] picture); protected abstract object GetResourceImage(string rescName); - public void RaisePropertyChanged(PropertyChangedEventArgs args) => this.UIThreadSync(() => PropertyChanged?.Invoke(this, args)); - public void RaisePropertyChanged(string propertyName) => RaisePropertyChanged(new PropertyChangedEventArgs(propertyName)); /// Refresh BookStatus (so partial download files are checked again in the filesystem) and raise PropertyChanged for property names. public void Invalidate(params string[] properties) diff --git a/Source/LibationUiBase/GridView/GridEntry[TStatus].cs b/Source/LibationUiBase/GridView/GridEntry[TStatus].cs index f8ef11d4..a57b52db 100644 --- a/Source/LibationUiBase/GridView/GridEntry[TStatus].cs +++ b/Source/LibationUiBase/GridView/GridEntry[TStatus].cs @@ -22,7 +22,7 @@ namespace LibationUiBase.GridView } /// The View Model base for the DataGridView - public abstract class GridEntry : SynchronizeInvoker, IGridEntry where TStatus : IEntryStatus + public abstract class GridEntry : ReactiveObject, IGridEntry where TStatus : IEntryStatus { [Browsable(false)] public string AudibleProductId => Book.AudibleProductId; [Browsable(false)] public LibraryBook LibraryBook { get; protected set; } @@ -183,19 +183,6 @@ namespace LibationUiBase.GridView } } - private TRet RaiseAndSetIfChanged(ref TRet backingField, TRet newValue, [CallerMemberName] string propertyName = null) - { - if (EqualityComparer.Default.Equals(backingField, newValue)) return newValue; - - backingField = newValue; - RaisePropertyChanged(new PropertyChangedEventArgs(propertyName)); - return newValue; - } - - public event PropertyChangedEventHandler PropertyChanged; - public void RaisePropertyChanged(PropertyChangedEventArgs args) => this.UIThreadSync(() => PropertyChanged?.Invoke(this, args)); - public void RaisePropertyChanged(string propertyName) => RaisePropertyChanged(new PropertyChangedEventArgs(propertyName)); - #endregion #region Sorting @@ -228,16 +215,16 @@ namespace LibationUiBase.GridView // Instantiate comparers for every exposed member object type. private static readonly Dictionary memberTypeComparers = new() { - { typeof(RemoveStatus), new ObjectComparer() }, - { typeof(string), new ObjectComparer() }, - { typeof(int), new ObjectComparer() }, - { typeof(float), new ObjectComparer() }, - { typeof(bool), new ObjectComparer() }, - { typeof(Rating), new ObjectComparer() }, - { typeof(DateTime), new ObjectComparer() }, - { typeof(EntryStatus), new ObjectComparer() }, - { typeof(SeriesOrder), new ObjectComparer() }, - { typeof(LastDownloadStatus), new ObjectComparer() }, + { typeof(RemoveStatus), Comparer.Default }, + { typeof(string), Comparer.Default }, + { typeof(int), Comparer .Default }, + { typeof(float), Comparer.Default }, + { typeof(bool), Comparer.Default }, + { typeof(Rating), Comparer.Default }, + { typeof(DateTime), Comparer.Default }, + { typeof(EntryStatus), Comparer.Default }, + { typeof(SeriesOrder), Comparer.Default }, + { typeof(LastDownloadStatus), Comparer.Default }, }; #endregion diff --git a/Source/LibationUiBase/GridView/ObjectComparer[T].cs b/Source/LibationUiBase/GridView/ObjectComparer[T].cs deleted file mode 100644 index e66beca0..00000000 --- a/Source/LibationUiBase/GridView/ObjectComparer[T].cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections; - -namespace LibationUiBase.GridView -{ - public class ObjectComparer : IComparer where T : IComparable - { - public int Compare(object x, object y) => ((T)x).CompareTo(y); - } -}