summaryrefslogtreecommitdiff
path: root/lib/model/entry/sort.dart
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /lib/model/entry/sort.dart
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'lib/model/entry/sort.dart')
-rw-r--r--lib/model/entry/sort.dart52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/model/entry/sort.dart b/lib/model/entry/sort.dart
new file mode 100644
index 0000000..e0e5573
--- /dev/null
+++ b/lib/model/entry/sort.dart
@@ -0,0 +1,52 @@
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/utils/time_utils.dart';
+import 'package:collection/collection.dart';
+
+class AvesEntrySort {
+ // compare by:
+ // 1) title ascending
+ // 2) extension ascending
+ static int compareByName(AvesEntry a, AvesEntry b) {
+ final c = compareAsciiUpperCaseNatural(a.bestTitle ?? '', b.bestTitle ?? '');
+ return c != 0 ? c : compareAsciiUpperCase(a.extension ?? '', b.extension ?? '');
+ }
+
+ // compare by:
+ // 1) date descending
+ // 2) name descending
+ static int compareByDate(AvesEntry a, AvesEntry b) {
+ var c = (b.bestDate ?? epoch).compareTo(a.bestDate ?? epoch);
+ if (c != 0) return c;
+ return compareByName(b, a);
+ }
+
+ // compare by:
+ // 1) rating descending
+ // 2) date descending
+ static int compareByRating(AvesEntry a, AvesEntry b) {
+ final c = b.rating.compareTo(a.rating);
+ return c != 0 ? c : compareByDate(a, b);
+ }
+
+ // compare by:
+ // 1) size descending
+ // 2) date descending
+ static int compareBySize(AvesEntry a, AvesEntry b) {
+ final c = (b.sizeBytes ?? 0).compareTo(a.sizeBytes ?? 0);
+ return c != 0 ? c : compareByDate(a, b);
+ }
+
+ // compare by:
+ // 1) duration descending
+ // 2) date descending
+ static int compareByDuration(AvesEntry a, AvesEntry b) {
+ final c = (b.durationMillis ?? 0).compareTo(a.durationMillis ?? 0);
+ return c != 0 ? c : compareByDate(a, b);
+ }
+
+ // compare by:
+ // 1) path ascending
+ static int compareByPath(AvesEntry a, AvesEntry b) {
+ return compareAsciiUpperCase(a.path ?? '', b.path ?? '');
+ }
+}