using Ryujinx.UI.App.Common; using System; namespace Ryujinx.Ava.UI.ViewModels { /// /// 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. /// public readonly struct AppListFavoriteComparable : IComparable { /// /// The application data being compared. /// private readonly ApplicationData app; /// /// Constructs a new with the specified application data. /// /// The app data being compared. public AppListFavoriteComparable(ApplicationData app) { ArgumentNullException.ThrowIfNull(app, nameof(app)); this.app = app; } /// 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)}"); } } }