LastPlayedSortComparer.cs 848 B

12345678910111213141516171819202122232425262728293031
  1. using Ryujinx.Ui.App.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Ava.UI.Models.Generic
  5. {
  6. internal class LastPlayedSortComparer : IComparer<ApplicationData>
  7. {
  8. public LastPlayedSortComparer() { }
  9. public LastPlayedSortComparer(bool isAscending) { IsAscending = isAscending; }
  10. public bool IsAscending { get; }
  11. public int Compare(ApplicationData x, ApplicationData y)
  12. {
  13. DateTime aValue = DateTime.UnixEpoch, bValue = DateTime.UnixEpoch;
  14. if (x?.LastPlayed != null)
  15. {
  16. aValue = x.LastPlayed.Value;
  17. }
  18. if (y?.LastPlayed != null)
  19. {
  20. bValue = y.LastPlayed.Value;
  21. }
  22. return (IsAscending ? 1 : -1) * DateTime.Compare(aValue, bValue);
  23. }
  24. }
  25. }