Add resonite-like sort mode and make it the default

Closes #20
This commit is contained in:
Nutcake 2023-11-20 22:12:30 +01:00
parent 812148658d
commit 331cbb9767

View file

@ -8,13 +8,17 @@ import 'package:recon/models/records/record.dart';
enum SortMode { enum SortMode {
name, name,
date; date,
resonite;
int sortFunction(Record a, Record b, {bool reverse = false}) { int sortFunction(Record a, Record b, {bool reverse = false}) {
final func = switch (this) { final func = switch (this) {
SortMode.name => (Record x, Record y) => SortMode.name => (Record x, Record y) =>
x.formattedName.toString().toLowerCase().compareTo(y.formattedName.toString().toLowerCase()), x.formattedName.toString().toLowerCase().compareTo(y.formattedName.toString().toLowerCase()),
SortMode.date => (Record x, Record y) => x.creationTime.compareTo(y.creationTime), 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) { if (reverse) {
return func(b, a); return func(b, a);
@ -24,7 +28,8 @@ enum SortMode {
static const Map<SortMode, IconData> _iconsMap = { static const Map<SortMode, IconData> _iconsMap = {
SortMode.name: Icons.sort_by_alpha, 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; IconData get icon => _iconsMap[this] ?? Icons.question_mark;
@ -35,7 +40,7 @@ class InventoryClient extends ChangeNotifier {
final Map<String, Record> _selectedRecords = {}; final Map<String, Record> _selectedRecords = {};
Future<ResoniteDirectory>? _currentDirectory; Future<ResoniteDirectory>? _currentDirectory;
SortMode _sortMode = SortMode.name; SortMode _sortMode = SortMode.resonite;
bool _sortReverse = false; bool _sortReverse = false;
InventoryClient({required this.apiClient}); InventoryClient({required this.apiClient});