From 331cbb97678792a903f1127ad2a99651d1d680d4 Mon Sep 17 00:00:00 2001 From: Nutcake Date: Mon, 20 Nov 2023 22:12:30 +0100 Subject: [PATCH] Add resonite-like sort mode and make it the default Closes #20 --- lib/clients/inventory_client.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/clients/inventory_client.dart b/lib/clients/inventory_client.dart index c6176e1..a25026e 100644 --- a/lib/clients/inventory_client.dart +++ b/lib/clients/inventory_client.dart @@ -8,13 +8,17 @@ import 'package:recon/models/records/record.dart'; enum SortMode { name, - date; + date, + resonite; int sortFunction(Record a, Record b, {bool reverse = false}) { final func = switch (this) { SortMode.name => (Record x, Record y) => x.formattedName.toString().toLowerCase().compareTo(y.formattedName.toString().toLowerCase()), SortMode.date => (Record x, Record y) => x.creationTime.compareTo(y.creationTime), + SortMode.resonite => (Record x, Record y) => x.isItem + ? x.creationTime.compareTo(y.creationTime) + : x.formattedName.toString().toLowerCase().compareTo(y.formattedName.toString().toLowerCase()), }; if (reverse) { return func(b, a); @@ -24,7 +28,8 @@ enum SortMode { static const Map _iconsMap = { SortMode.name: Icons.sort_by_alpha, - SortMode.date: Icons.access_time_outlined + SortMode.date: Icons.access_time_outlined, + SortMode.resonite: Icons.star_border_purple500_sharp, }; IconData get icon => _iconsMap[this] ?? Icons.question_mark; @@ -35,7 +40,7 @@ class InventoryClient extends ChangeNotifier { final Map _selectedRecords = {}; Future? _currentDirectory; - SortMode _sortMode = SortMode.name; + SortMode _sortMode = SortMode.resonite; bool _sortReverse = false; InventoryClient({required this.apiClient});