sort by path
This commit is contained in:
parent
32c5fcd41a
commit
0c0d3d3019
3 changed files with 55 additions and 28 deletions
|
@ -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 }
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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<String>());
|
||||
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<String>());
|
||||
return TitleSectionHeader(
|
||||
key: ValueKey(title),
|
||||
leading: albumIcon,
|
||||
title: title,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue