diff --git a/lib/model/image_collection.dart b/lib/model/image_collection.dart index e0b1b5f31..eb86bccf9 100644 --- a/lib/model/image_collection.dart +++ b/lib/model/image_collection.dart @@ -63,6 +63,9 @@ class ImageCollection with ChangeNotifier { MapEntry(null, _rawEntries), ])); break; + case SortFactor.name: + sections = Map.unmodifiable(groupBy(_rawEntries, (entry) => entry.directory)); + break; } notifyListeners(); } @@ -75,6 +78,9 @@ class ImageCollection with ChangeNotifier { case SortFactor.size: _rawEntries.sort((a, b) => b.sizeBytes.compareTo(a.sizeBytes)); break; + case SortFactor.name: + _rawEntries.sort((a, b) => a.path.compareTo(b.path)); + break; } } @@ -194,6 +200,6 @@ class ImageCollection with ChangeNotifier { } } -enum SortFactor { date, size } +enum SortFactor { date, size, name } enum GroupFactor { album, month, day } diff --git a/lib/widgets/album/all_collection_page.dart b/lib/widgets/album/all_collection_page.dart index 836a42724..9d553a33f 100644 --- a/lib/widgets/album/all_collection_page.dart +++ b/lib/widgets/album/all_collection_page.dart @@ -53,6 +53,10 @@ class _AllCollectionAppBar extends SliverAppBar { value: AlbumAction.sortBySize, child: MenuRow(text: 'Sort by size', checked: collection.sortFactor == SortFactor.size), ), + PopupMenuItem( + value: AlbumAction.sortByName, + child: MenuRow(text: 'Sort by name', checked: collection.sortFactor == SortFactor.name), + ), const PopupMenuDivider(), if (collection.sortFactor == SortFactor.date) ...[ PopupMenuItem( @@ -106,6 +110,10 @@ class _AllCollectionAppBar extends SliverAppBar { settings.collectionSortFactor = SortFactor.size; collection.sort(SortFactor.size); break; + case AlbumAction.sortByName: + settings.collectionSortFactor = SortFactor.name; + collection.sort(SortFactor.name); + break; } } @@ -121,4 +129,4 @@ class _AllCollectionAppBar extends SliverAppBar { } } -enum AlbumAction { debug, groupByAlbum, groupByMonth, groupByDay, sortByDate, sortBySize } +enum AlbumAction { debug, groupByAlbum, groupByMonth, groupByDay, sortByDate, sortBySize, sortByName } diff --git a/lib/widgets/album/collection_section.dart b/lib/widgets/album/collection_section.dart index 7c3c67695..1566eeecd 100644 --- a/lib/widgets/album/collection_section.dart +++ b/lib/widgets/album/collection_section.dart @@ -95,36 +95,49 @@ class SectionHeader extends StatelessWidget { @override Widget build(BuildContext context) { Widget header = const SizedBox.shrink(); - if (collection.sortFactor == SortFactor.date) { - switch (collection.groupFactor) { - case GroupFactor.album: - Widget albumIcon = IconUtils.getAlbumIcon(context, sectionKey as String); - if (albumIcon != null) { - albumIcon = Material( - type: MaterialType.circle, - elevation: 3, - color: Colors.transparent, - shadowColor: Colors.black, - child: albumIcon, - ); + switch (collection.sortFactor) { + case SortFactor.date: + if (collection.sortFactor == SortFactor.date) { + switch (collection.groupFactor) { + case GroupFactor.album: + header = _buildAlbumSectionHeader(context); + break; + case GroupFactor.month: + header = MonthSectionHeader(key: ValueKey(sectionKey), date: sectionKey as DateTime); + break; + case GroupFactor.day: + header = DaySectionHeader(key: ValueKey(sectionKey), date: sectionKey as DateTime); + break; } - var title = collection.getUniqueAlbumName(sectionKey as String, sections.keys.cast()); - header = TitleSectionHeader( - key: ValueKey(title), - leading: albumIcon, - title: title, - ); - break; - case GroupFactor.month: - header = MonthSectionHeader(key: ValueKey(sectionKey), date: sectionKey as DateTime); - break; - case GroupFactor.day: - header = DaySectionHeader(key: ValueKey(sectionKey), date: sectionKey as DateTime); - break; - } + } + break; + case SortFactor.size: + break; + case SortFactor.name: + header = _buildAlbumSectionHeader(context); + break; } return IgnorePointer( child: header, ); } + + Widget _buildAlbumSectionHeader(BuildContext context) { + Widget albumIcon = IconUtils.getAlbumIcon(context, sectionKey as String); + if (albumIcon != null) { + albumIcon = Material( + type: MaterialType.circle, + elevation: 3, + color: Colors.transparent, + shadowColor: Colors.black, + child: albumIcon, + ); + } + var title = collection.getUniqueAlbumName(sectionKey as String, sections.keys.cast()); + return TitleSectionHeader( + key: ValueKey(title), + leading: albumIcon, + title: title, + ); + } }