Change episode default sorting to SeriesOrder descending
This commit is contained in:
parent
8a1b375f0d
commit
af8e1cd5ef
@ -118,7 +118,7 @@ namespace LibationAvalonia.ViewModels
|
|||||||
|
|
||||||
//Create the filtered-in list before adding entries to avoid a refresh
|
//Create the filtered-in list before adding entries to avoid a refresh
|
||||||
FilteredInGridEntries = geList.Union(geList.OfType<ISeriesEntry>().SelectMany(s => s.Children)).FilterEntries(FilterString);
|
FilteredInGridEntries = geList.Union(geList.OfType<ISeriesEntry>().SelectMany(s => s.Children)).FilterEntries(FilterString);
|
||||||
SOURCE.AddRange(geList.OrderByDescending(e => e.DateAdded));
|
SOURCE.AddRange(geList.OrderDescending(new RowComparer(null)));
|
||||||
|
|
||||||
//Add all children beneath their parent
|
//Add all children beneath their parent
|
||||||
foreach (var series in SOURCE.OfType<ISeriesEntry>().ToList())
|
foreach (var series in SOURCE.OfType<ISeriesEntry>().ToList())
|
||||||
|
|||||||
@ -16,11 +16,13 @@ namespace LibationAvalonia.ViewModels
|
|||||||
public RowComparer(DataGridColumn column)
|
public RowComparer(DataGridColumn column)
|
||||||
{
|
{
|
||||||
Column = column;
|
Column = column;
|
||||||
PropertyName = Column.SortMemberPath;
|
PropertyName = Column?.SortMemberPath ?? nameof(IGridEntry.DateAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Avalonia doesn't expose the column's CurrentSortingState, so we must get it through reflection
|
//Avalonia doesn't expose the column's CurrentSortingState, so we must get it through reflection
|
||||||
protected override ListSortDirection? GetSortOrder()
|
protected override ListSortDirection GetSortOrder()
|
||||||
=> CurrentSortingStatePi.GetValue(HeaderCellPi.GetValue(Column)) as ListSortDirection?;
|
=> Column is null ? ListSortDirection.Descending
|
||||||
|
: CurrentSortingStatePi.GetValue(HeaderCellPi.GetValue(Column)) is ListSortDirection lsd ? lsd
|
||||||
|
: ListSortDirection.Descending;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,7 @@ namespace LibationUiBase.GridView
|
|||||||
public abstract object BackgroundBrush { get; }
|
public abstract object BackgroundBrush { get; }
|
||||||
public object ButtonImage => GetLiberateIcon();
|
public object ButtonImage => GetLiberateIcon();
|
||||||
public string ToolTip => GetTooltip();
|
public string ToolTip => GetTooltip();
|
||||||
internal Book Book { get; }
|
private Book Book { get; }
|
||||||
|
|
||||||
private DateTime lastBookUpdate;
|
private DateTime lastBookUpdate;
|
||||||
private LiberatedStatus bookStatus;
|
private LiberatedStatus bookStatus;
|
||||||
|
|||||||
@ -61,16 +61,10 @@ namespace LibationUiBase.GridView
|
|||||||
{
|
{
|
||||||
//Podcast episodes usually all have the same PurchaseDate and DateAdded property:
|
//Podcast episodes usually all have the same PurchaseDate and DateAdded property:
|
||||||
//the date that the series was added to the library. So when sorting by PurchaseDate
|
//the date that the series was added to the library. So when sorting by PurchaseDate
|
||||||
//and DateAdded, compare SeriesOrder instead.
|
//and DateAdded, compare SeriesOrder instead..
|
||||||
//
|
|
||||||
//Note that DateAdded is not a grid column and users cannot sort by that property.
|
|
||||||
//Entries are only sorted by DateAdded as a default sorting order when no other
|
|
||||||
//sorting column has been chose. We negate the comparison so that episodes are listed
|
|
||||||
//in ascending order.
|
|
||||||
return PropertyName switch
|
return PropertyName switch
|
||||||
{
|
{
|
||||||
nameof(IGridEntry.PurchaseDate) => geA.SeriesOrder.CompareTo(geB.SeriesOrder),
|
nameof(IGridEntry.DateAdded) or nameof (IGridEntry.PurchaseDate) => geA.SeriesOrder.CompareTo(geB.SeriesOrder),
|
||||||
nameof(IGridEntry.DateAdded) => geA.SeriesOrder.CompareTo(geB.SeriesOrder) * (GetSortOrder() is ListSortDirection.Descending ? 1 : -1),
|
|
||||||
_ => InternalCompare(geA, geB),
|
_ => InternalCompare(geA, geB),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -79,7 +73,7 @@ namespace LibationUiBase.GridView
|
|||||||
return InternalCompare(parentA, parentB);
|
return InternalCompare(parentA, parentB);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ListSortDirection? GetSortOrder();
|
protected abstract ListSortDirection GetSortOrder();
|
||||||
|
|
||||||
private int InternalCompare(IGridEntry x, IGridEntry y)
|
private int InternalCompare(IGridEntry x, IGridEntry y)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -47,7 +47,7 @@ namespace LibationUiBase.GridView
|
|||||||
|
|
||||||
Children = children
|
Children = children
|
||||||
.Select(c => new LibraryBookEntry<TStatus>(c, this))
|
.Select(c => new LibraryBookEntry<TStatus>(c, this))
|
||||||
.OrderBy(c => c.SeriesIndex)
|
.OrderByDescending(c => c.SeriesOrder)
|
||||||
.ToList<ILibraryBookEntry>();
|
.ToList<ILibraryBookEntry>();
|
||||||
|
|
||||||
UpdateLibraryBook(parent);
|
UpdateLibraryBook(parent);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using Dinah.Core.DataBinding;
|
|
||||||
using LibationUiBase.GridView;
|
using LibationUiBase.GridView;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -25,6 +24,8 @@ namespace LibationWinForms.GridView
|
|||||||
public GridEntryBindingList(IEnumerable<IGridEntry> enumeration) : base(new List<IGridEntry>(enumeration))
|
public GridEntryBindingList(IEnumerable<IGridEntry> enumeration) : base(new List<IGridEntry>(enumeration))
|
||||||
{
|
{
|
||||||
SearchEngineCommands.SearchEngineUpdated += SearchEngineCommands_SearchEngineUpdated;
|
SearchEngineCommands.SearchEngineUpdated += SearchEngineCommands_SearchEngineUpdated;
|
||||||
|
|
||||||
|
refreshEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -216,9 +217,7 @@ namespace LibationWinForms.GridView
|
|||||||
{
|
{
|
||||||
var itemsList = (List<IGridEntry>)Items;
|
var itemsList = (List<IGridEntry>)Items;
|
||||||
//User Order/OrderDescending and replace items in list instead of using List.Sort() to achieve stable sorting.
|
//User Order/OrderDescending and replace items in list instead of using List.Sort() to achieve stable sorting.
|
||||||
var sortedItems
|
var sortedItems = Comparer.OrderEntries(itemsList).ToList();
|
||||||
= Comparer.SortOrder == ListSortDirection.Ascending ? itemsList.Order(Comparer).ToList()
|
|
||||||
: itemsList.OrderDescending(Comparer).ToList();
|
|
||||||
|
|
||||||
itemsList.Clear();
|
itemsList.Clear();
|
||||||
itemsList.AddRange(sortedItems);
|
itemsList.AddRange(sortedItems);
|
||||||
|
|||||||
@ -181,7 +181,7 @@ namespace LibationWinForms.GridView
|
|||||||
geList.AddRange(seriesEntry.Children);
|
geList.AddRange(seriesEntry.Children);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindingList = new GridEntryBindingList(geList.OrderByDescending(e => e.DateAdded));
|
bindingList = new GridEntryBindingList(geList);
|
||||||
bindingList.CollapseAll();
|
bindingList.CollapseAll();
|
||||||
syncBindingSource.DataSource = bindingList;
|
syncBindingSource.DataSource = bindingList;
|
||||||
VisibleCountChanged?.Invoke(this, bindingList.GetFilteredInItems().Count());
|
VisibleCountChanged?.Invoke(this, bindingList.GetFilteredInItems().Count());
|
||||||
|
|||||||
@ -1,12 +1,20 @@
|
|||||||
using LibationUiBase.GridView;
|
using LibationUiBase.GridView;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibationWinForms.GridView
|
namespace LibationWinForms.GridView
|
||||||
{
|
{
|
||||||
internal class RowComparer : RowComparerBase
|
internal class RowComparer : RowComparerBase
|
||||||
{
|
{
|
||||||
public ListSortDirection? SortOrder { get; set; }
|
public ListSortDirection SortOrder { get; set; } = ListSortDirection.Descending;
|
||||||
public override string PropertyName { get; set; }
|
public override string PropertyName { get; set; } = nameof(IGridEntry.DateAdded);
|
||||||
protected override ListSortDirection? GetSortOrder() => SortOrder;
|
protected override ListSortDirection GetSortOrder() => SortOrder;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper method for ordering grid entries
|
||||||
|
/// </summary>
|
||||||
|
public IOrderedEnumerable<IGridEntry> OrderEntries(IEnumerable<IGridEntry> entries)
|
||||||
|
=> SortOrder is ListSortDirection.Descending ? entries.OrderDescending(this) : entries.Order(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user