aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx/UI/Models/Generic/TimePlayedSortComparer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx/UI/Models/Generic/TimePlayedSortComparer.cs')
-rw-r--r--src/Ryujinx/UI/Models/Generic/TimePlayedSortComparer.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Ryujinx/UI/Models/Generic/TimePlayedSortComparer.cs b/src/Ryujinx/UI/Models/Generic/TimePlayedSortComparer.cs
new file mode 100644
index 00000000..f0fb035d
--- /dev/null
+++ b/src/Ryujinx/UI/Models/Generic/TimePlayedSortComparer.cs
@@ -0,0 +1,31 @@
+using Ryujinx.UI.App.Common;
+using System;
+using System.Collections.Generic;
+
+namespace Ryujinx.Ava.UI.Models.Generic
+{
+ internal class TimePlayedSortComparer : IComparer<ApplicationData>
+ {
+ public TimePlayedSortComparer() { }
+ public TimePlayedSortComparer(bool isAscending) { IsAscending = isAscending; }
+
+ public bool IsAscending { get; }
+
+ public int Compare(ApplicationData x, ApplicationData y)
+ {
+ TimeSpan aValue = TimeSpan.Zero, bValue = TimeSpan.Zero;
+
+ if (x?.TimePlayed != null)
+ {
+ aValue = x.TimePlayed;
+ }
+
+ if (y?.TimePlayed != null)
+ {
+ bValue = y.TimePlayed;
+ }
+
+ return (IsAscending ? 1 : -1) * TimeSpan.Compare(aValue, bValue);
+ }
+ }
+}