Use built-in comparer and ReactiveObject types
This commit is contained in:
parent
4dab16837e
commit
35ca6f2621
@ -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));
|
||||
|
||||
/// <summary>Refresh BookStatus (so partial download files are checked again in the filesystem) and raise PropertyChanged for property names.</summary>
|
||||
public void Invalidate(params string[] properties)
|
||||
|
||||
@ -22,7 +22,7 @@ namespace LibationUiBase.GridView
|
||||
}
|
||||
|
||||
/// <summary>The View Model base for the DataGridView</summary>
|
||||
public abstract class GridEntry<TStatus> : SynchronizeInvoker, IGridEntry where TStatus : IEntryStatus
|
||||
public abstract class GridEntry<TStatus> : 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<TRet>(ref TRet backingField, TRet newValue, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<TRet>.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<Type, IComparer> memberTypeComparers = new()
|
||||
{
|
||||
{ typeof(RemoveStatus), new ObjectComparer<RemoveStatus>() },
|
||||
{ typeof(string), new ObjectComparer<string>() },
|
||||
{ typeof(int), new ObjectComparer<int>() },
|
||||
{ typeof(float), new ObjectComparer<float>() },
|
||||
{ typeof(bool), new ObjectComparer<bool>() },
|
||||
{ typeof(Rating), new ObjectComparer<Rating>() },
|
||||
{ typeof(DateTime), new ObjectComparer<DateTime>() },
|
||||
{ typeof(EntryStatus), new ObjectComparer<EntryStatus>() },
|
||||
{ typeof(SeriesOrder), new ObjectComparer<SeriesOrder>() },
|
||||
{ typeof(LastDownloadStatus), new ObjectComparer<LastDownloadStatus>() },
|
||||
{ typeof(RemoveStatus), Comparer<RemoveStatus>.Default },
|
||||
{ typeof(string), Comparer<string>.Default },
|
||||
{ typeof(int), Comparer <int>.Default },
|
||||
{ typeof(float), Comparer<float >.Default },
|
||||
{ typeof(bool), Comparer<bool>.Default },
|
||||
{ typeof(Rating), Comparer<Rating>.Default },
|
||||
{ typeof(DateTime), Comparer<DateTime>.Default },
|
||||
{ typeof(EntryStatus), Comparer<EntryStatus>.Default },
|
||||
{ typeof(SeriesOrder), Comparer<SeriesOrder>.Default },
|
||||
{ typeof(LastDownloadStatus), Comparer<LastDownloadStatus>.Default },
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace LibationUiBase.GridView
|
||||
{
|
||||
public class ObjectComparer<T> : IComparer where T : IComparable
|
||||
{
|
||||
public int Compare(object x, object y) => ((T)x).CompareTo(y);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user