Create GallerySections model for holding data about a gallery
This commit is contained in:
61
mobile/lib/models/gallery/gallery_sections.dart
Normal file
61
mobile/lib/models/gallery/gallery_sections.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import "dart:core";
|
||||
|
||||
import "package:photos/models/file/file.dart";
|
||||
import "package:photos/ui/viewer/gallery/component/group/type.dart";
|
||||
import "package:uuid/uuid.dart";
|
||||
|
||||
class GallerySections {
|
||||
final List<EnteFile> allFiles;
|
||||
final GroupType groupType;
|
||||
final bool sortOrderAsc;
|
||||
GallerySections({
|
||||
required this.allFiles,
|
||||
required this.groupType,
|
||||
this.sortOrderAsc = true,
|
||||
});
|
||||
|
||||
late final List<String> _groupIDs;
|
||||
late final Map<String, List<EnteFile>> _groupIDToFilesMap;
|
||||
late Map<String, GroupHeaderData> _groupIdToheaderDataMap;
|
||||
|
||||
List<String> get groupIDs => _groupIDs;
|
||||
Map<String, List<EnteFile>> get groupIDToFilesMap => _groupIDToFilesMap;
|
||||
Map<String, GroupHeaderData> get groupIdToheaderDataMap =>
|
||||
_groupIdToheaderDataMap;
|
||||
|
||||
final _uuid = const Uuid();
|
||||
|
||||
void init() {
|
||||
List<EnteFile> dailyFiles = [];
|
||||
for (int index = 0; index < allFiles.length; index++) {
|
||||
if (index > 0 &&
|
||||
groupType.areFromSameGroup(allFiles[index - 1], allFiles[index])) {
|
||||
_createNewGroup(dailyFiles);
|
||||
dailyFiles = [];
|
||||
}
|
||||
dailyFiles.add(allFiles[index]);
|
||||
}
|
||||
if (dailyFiles.isNotEmpty) {
|
||||
_createNewGroup(dailyFiles);
|
||||
}
|
||||
}
|
||||
|
||||
void _createNewGroup(
|
||||
List<EnteFile> dailyFiles,
|
||||
) {
|
||||
final uuid = _uuid.v1();
|
||||
_groupIDs.add(uuid);
|
||||
_groupIDToFilesMap[uuid] = dailyFiles;
|
||||
_groupIdToheaderDataMap[uuid] = GroupHeaderData(
|
||||
title: dailyFiles.first.creationTime!.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GroupHeaderData {
|
||||
final String title;
|
||||
|
||||
GroupHeaderData({
|
||||
required this.title,
|
||||
});
|
||||
}
|
||||
@@ -379,6 +379,7 @@ class GalleryState extends State<Gallery> {
|
||||
sortOrderAsc: _sortOrderAsc,
|
||||
inSelectionMode: widget.inSelectionMode,
|
||||
type: widget.groupType,
|
||||
// Replace this with the new gallery and use `_allGalleryFiles`
|
||||
child: MultipleGroupsGalleryView(
|
||||
itemScroller: _itemScroller,
|
||||
groupedFiles: currentGroupedFiles,
|
||||
|
||||
Reference in New Issue
Block a user