aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs')
-rw-r--r--src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs b/src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs
new file mode 100644
index 00000000..e8098450
--- /dev/null
+++ b/src/Ryujinx/UI/ViewModels/AppListFavoriteComparable.cs
@@ -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)}");
+ }
+ }
+}