/ src / Ryujinx / UI / Models / Generic / TimePlayedSortComparer.cs
TimePlayedSortComparer.cs
 1  using Ryujinx.UI.App.Common;
 2  using System;
 3  using System.Collections.Generic;
 4  
 5  namespace Ryujinx.Ava.UI.Models.Generic
 6  {
 7      internal class TimePlayedSortComparer : IComparer<ApplicationData>
 8      {
 9          public TimePlayedSortComparer() { }
10          public TimePlayedSortComparer(bool isAscending) { IsAscending = isAscending; }
11  
12          public bool IsAscending { get; }
13  
14          public int Compare(ApplicationData x, ApplicationData y)
15          {
16              TimeSpan aValue = TimeSpan.Zero, bValue = TimeSpan.Zero;
17  
18              if (x?.TimePlayed != null)
19              {
20                  aValue = x.TimePlayed;
21              }
22  
23              if (y?.TimePlayed != null)
24              {
25                  bValue = y.TimePlayed;
26              }
27  
28              return (IsAscending ? 1 : -1) * TimeSpan.Compare(aValue, bValue);
29          }
30      }
31  }