mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-11-21 17:40:52 +01:00
Fix arbitrary game ordering when sorting by Favorites (#7170)
* Fix arbitrary sorting by "Favorite" in the UI by making it the same as sorting alphabetically while giving favorites priority. * Use a more engineered solution rather than string hacks. * Address code style warnings. Add null checking. Make title name comparison case insensitive. * one more style fix --------- Co-authored-by: Logan Stromberg <lostromb@microsoft.com>
This commit is contained in:
parent
4f75e26ec7
commit
23fa5f4c9c
2 changed files with 45 additions and 2 deletions
43
src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs
Normal file
43
src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
using Ryujinx.UI.App.Common;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Ryujinx.Ava.UI.ViewModels
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implements a custom comparer which is used for sorting titles by favorite on a UI.
|
||||||
|
/// Returns a sorted list of favorites in alphabetical order, followed by all non-favorites sorted alphabetical.
|
||||||
|
/// </summary>
|
||||||
|
public readonly struct AppListFavoriteComparable : IComparable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The application data being compared.
|
||||||
|
/// </summary>
|
||||||
|
private readonly ApplicationData app;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new <see cref="AppListFavoriteComparable"/> with the specified application data.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="app">The app data being compared.</param>
|
||||||
|
public AppListFavoriteComparable(ApplicationData app)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(app, nameof(app));
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public readonly int CompareTo(object o)
|
||||||
|
{
|
||||||
|
if (o is AppListFavoriteComparable other)
|
||||||
|
{
|
||||||
|
if (app.Favorite == other.app.Favorite)
|
||||||
|
{
|
||||||
|
return string.Compare(app.Name, other.app.Name, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.Favorite ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidCastException($"Cannot cast {o.GetType()} to {nameof(AppListFavoriteComparable)}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -965,8 +965,8 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
: SortExpressionComparer<ApplicationData>.Descending(app => app.FileSize),
|
: SortExpressionComparer<ApplicationData>.Descending(app => app.FileSize),
|
||||||
ApplicationSort.Path => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Path)
|
ApplicationSort.Path => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Path)
|
||||||
: SortExpressionComparer<ApplicationData>.Descending(app => app.Path),
|
: SortExpressionComparer<ApplicationData>.Descending(app => app.Path),
|
||||||
ApplicationSort.Favorite => !IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => app.Favorite)
|
ApplicationSort.Favorite => IsAscending ? SortExpressionComparer<ApplicationData>.Ascending(app => new AppListFavoriteComparable(app))
|
||||||
: SortExpressionComparer<ApplicationData>.Descending(app => app.Favorite),
|
: SortExpressionComparer<ApplicationData>.Descending(app => new AppListFavoriteComparable(app)),
|
||||||
_ => null,
|
_ => null,
|
||||||
#pragma warning restore IDE0055
|
#pragma warning restore IDE0055
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue