diff --git a/lib/model/image_collection.dart b/lib/model/image_collection.dart index eb86bccf9..c74a09471 100644 --- a/lib/model/image_collection.dart +++ b/lib/model/image_collection.dart @@ -1,3 +1,5 @@ +import 'dart:collection'; + import 'package:aves/model/image_entry.dart'; import 'package:aves/model/image_file_service.dart'; import 'package:aves/model/image_metadata.dart'; @@ -64,7 +66,14 @@ class ImageCollection with ChangeNotifier { ])); break; case SortFactor.name: - sections = Map.unmodifiable(groupBy(_rawEntries, (entry) => entry.directory)); + final byAlbum = groupBy(_rawEntries, (ImageEntry entry) => entry.directory); + final albums = byAlbum.keys.toSet(); + final compare = (a, b) { + final ua = getUniqueAlbumName(a, albums); + final ub = getUniqueAlbumName(b, albums); + return compareAsciiUpperCase(ua, ub); + }; + sections = Map.unmodifiable(SplayTreeMap.from(byAlbum, compare)); break; } notifyListeners(); @@ -79,7 +88,7 @@ class ImageCollection with ChangeNotifier { _rawEntries.sort((a, b) => b.sizeBytes.compareTo(a.sizeBytes)); break; case SortFactor.name: - _rawEntries.sort((a, b) => a.path.compareTo(b.path)); + _rawEntries.sort((a, b) => compareAsciiUpperCase(a.title, b.title)); break; } } @@ -96,8 +105,8 @@ class ImageCollection with ChangeNotifier { } void updateAlbums() { - Set albums = _rawEntries.map((entry) => entry.directory).toSet(); - List sorted = albums.toList() + final albums = _rawEntries.map((entry) => entry.directory).toSet(); + final sorted = albums.toList() ..sort((a, b) { final ua = getUniqueAlbumName(a, albums); final ub = getUniqueAlbumName(b, albums); @@ -107,8 +116,8 @@ class ImageCollection with ChangeNotifier { } void updateTags() { - Set tags = _rawEntries.expand((entry) => entry.xmpSubjects).toSet(); - List sorted = tags.toList()..sort(compareAsciiUpperCase); + final tags = _rawEntries.expand((entry) => entry.xmpSubjects).toSet(); + final sorted = tags.toList()..sort(compareAsciiUpperCase); sortedTags = List.unmodifiable(sorted); }