aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Ui/Models/Generic
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Ava/Ui/Models/Generic')
-rw-r--r--Ryujinx.Ava/Ui/Models/Generic/FileSizeSortComparer.cs50
-rw-r--r--Ryujinx.Ava/Ui/Models/Generic/LastPlayedSortComparer.cs33
-rw-r--r--Ryujinx.Ava/Ui/Models/Generic/TimePlayedSortComparer.cs66
3 files changed, 149 insertions, 0 deletions
diff --git a/Ryujinx.Ava/Ui/Models/Generic/FileSizeSortComparer.cs b/Ryujinx.Ava/Ui/Models/Generic/FileSizeSortComparer.cs
new file mode 100644
index 00000000..02c3c9b4
--- /dev/null
+++ b/Ryujinx.Ava/Ui/Models/Generic/FileSizeSortComparer.cs
@@ -0,0 +1,50 @@
+using Ryujinx.Ui.App.Common;
+using System.Collections.Generic;
+
+namespace Ryujinx.Ava.Ui.Models.Generic
+{
+ public class FileSizeSortComparer : IComparer<ApplicationData>
+ {
+ public FileSizeSortComparer() { }
+ public FileSizeSortComparer(bool isAscending) { _order = isAscending ? 1 : -1; }
+
+ private int _order;
+
+ public int Compare(ApplicationData x, ApplicationData y)
+ {
+ string aValue = x.FileSize;
+ string bValue = y.FileSize;
+
+ if (aValue[^2..] == "GB")
+ {
+ aValue = (float.Parse(aValue[0..^2]) * 1024).ToString();
+ }
+ else
+ {
+ aValue = aValue[0..^2];
+ }
+
+ if (bValue[^2..] == "GB")
+ {
+ bValue = (float.Parse(bValue[0..^2]) * 1024).ToString();
+ }
+ else
+ {
+ bValue = bValue[0..^2];
+ }
+
+ if (float.Parse(aValue) > float.Parse(bValue))
+ {
+ return -1 * _order;
+ }
+ else if (float.Parse(bValue) > float.Parse(aValue))
+ {
+ return 1 * _order;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.Ava/Ui/Models/Generic/LastPlayedSortComparer.cs b/Ryujinx.Ava/Ui/Models/Generic/LastPlayedSortComparer.cs
new file mode 100644
index 00000000..3d4d6700
--- /dev/null
+++ b/Ryujinx.Ava/Ui/Models/Generic/LastPlayedSortComparer.cs
@@ -0,0 +1,33 @@
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ui.App.Common;
+using System;
+using System.Collections.Generic;
+
+namespace Ryujinx.Ava.Ui.Models.Generic
+{
+ public class LastPlayedSortComparer : IComparer<ApplicationData>
+ {
+ public LastPlayedSortComparer() { }
+ public LastPlayedSortComparer(bool isAscending) { IsAscending = isAscending; }
+
+ public bool IsAscending { get; }
+
+ public int Compare(ApplicationData x, ApplicationData y)
+ {
+ string aValue = x.LastPlayed;
+ string bValue = y.LastPlayed;
+
+ if (aValue == LocaleManager.Instance["Never"])
+ {
+ aValue = DateTime.UnixEpoch.ToString();
+ }
+
+ if (bValue == LocaleManager.Instance["Never"])
+ {
+ bValue = DateTime.UnixEpoch.ToString();
+ }
+
+ return (IsAscending ? 1 : -1) * DateTime.Compare(DateTime.Parse(bValue), DateTime.Parse(aValue));
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.Ava/Ui/Models/Generic/TimePlayedSortComparer.cs b/Ryujinx.Ava/Ui/Models/Generic/TimePlayedSortComparer.cs
new file mode 100644
index 00000000..20b30b83
--- /dev/null
+++ b/Ryujinx.Ava/Ui/Models/Generic/TimePlayedSortComparer.cs
@@ -0,0 +1,66 @@
+using Ryujinx.Ui.App.Common;
+using System.Collections.Generic;
+
+namespace Ryujinx.Ava.Ui.Models.Generic
+{
+ public class TimePlayedSortComparer : IComparer<ApplicationData>
+ {
+ public TimePlayedSortComparer() { }
+ public TimePlayedSortComparer(bool isAscending) { _order = isAscending ? 1 : -1; }
+
+ private int _order;
+
+ public int Compare(ApplicationData x, ApplicationData y)
+ {
+ string aValue = x.TimePlayed;
+ string bValue = y.TimePlayed;
+
+ if (aValue.Length > 4 && aValue[^4..] == "mins")
+ {
+ aValue = (float.Parse(aValue[0..^5]) * 60).ToString();
+ }
+ else if (aValue.Length > 3 && aValue[^3..] == "hrs")
+ {
+ aValue = (float.Parse(aValue[0..^4]) * 3600).ToString();
+ }
+ else if (aValue.Length > 4 && aValue[^4..] == "days")
+ {
+ aValue = (float.Parse(aValue[0..^5]) * 86400).ToString();
+ }
+ else
+ {
+ aValue = aValue[0..^1];
+ }
+
+ if (bValue.Length > 4 && bValue[^4..] == "mins")
+ {
+ bValue = (float.Parse(bValue[0..^5]) * 60).ToString();
+ }
+ else if (bValue.Length > 3 && bValue[^3..] == "hrs")
+ {
+ bValue = (float.Parse(bValue[0..^4]) * 3600).ToString();
+ }
+ else if (bValue.Length > 4 && bValue[^4..] == "days")
+ {
+ bValue = (float.Parse(bValue[0..^5]) * 86400).ToString();
+ }
+ else
+ {
+ bValue = bValue[0..^1];
+ }
+
+ if (float.Parse(aValue) > float.Parse(bValue))
+ {
+ return -1 * _order;
+ }
+ else if (float.Parse(bValue) > float.Parse(aValue))
+ {
+ return 1 * _order;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+} \ No newline at end of file