diff options
Diffstat (limited to 'src/Ryujinx.Ava/UI/Models/Generic')
| -rw-r--r-- | src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs | 13 | ||||
| -rw-r--r-- | src/Ryujinx.Ava/UI/Models/Generic/TimePlayedSortComparer.cs | 31 |
2 files changed, 37 insertions, 7 deletions
diff --git a/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs b/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs index 8a434655..8340d39d 100644 --- a/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs +++ b/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs @@ -13,20 +13,19 @@ namespace Ryujinx.Ava.UI.Models.Generic public int Compare(ApplicationData x, ApplicationData y) { - var aValue = x.LastPlayed; - var bValue = y.LastPlayed; + DateTime aValue = DateTime.UnixEpoch, bValue = DateTime.UnixEpoch; - if (!aValue.HasValue) + if (x?.LastPlayed != null) { - aValue = DateTime.UnixEpoch; + aValue = x.LastPlayed.Value; } - if (!bValue.HasValue) + if (y?.LastPlayed != null) { - bValue = DateTime.UnixEpoch; + bValue = y.LastPlayed.Value; } - return (IsAscending ? 1 : -1) * DateTime.Compare(bValue.Value, aValue.Value); + return (IsAscending ? 1 : -1) * DateTime.Compare(aValue, bValue); } } } diff --git a/src/Ryujinx.Ava/UI/Models/Generic/TimePlayedSortComparer.cs b/src/Ryujinx.Ava/UI/Models/Generic/TimePlayedSortComparer.cs new file mode 100644 index 00000000..d53ff566 --- /dev/null +++ b/src/Ryujinx.Ava/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); + } + } +} |
