Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add dummy files to fill incomplete grid rows

ashilkn7907b5d52110
diff --git a/mobile/apps/photos/lib/models/file/dummy_file.dart b/mobile/apps/photos/lib/models/file/dummy_file.dart
new file mode 100644
index 0000000000..1340c8a2b7
--- /dev/null
+++ b/mobile/apps/photos/lib/models/file/dummy_file.dart
@@ -0,0 +1,29 @@
+import "package:photos/models/file/file.dart";
+
+/// A dummy file used to fill empty spaces in gallery grid rows.
+/// Can be uniquely identified by groupID and index within the group.
+class DummyFile extends EnteFile {
+ final String groupID;
+ final int index;
+
+ DummyFile({
+ required this.groupID,
+ required this.index,
+ }) {
+ // Set a unique generatedID based on groupID and index
+ // Using a negative number to distinguish from real files
+ generatedID = -(groupID.hashCode + index);
+ }
+
+ bool get isDummy => true;
+
+ @override
+ String get tag {
+ return "dummy_${groupID}_$index";
+ }
+
+ @override
+ String cacheKey() {
+ return "dummy_${groupID}_$index";
+ }
+}
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
index 3bb9e70c1d..3aef2eec1b 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
@@ -3,11 +3,13 @@ import "dart:core";
import "package:flutter/material.dart";
import "package:logging/logging.dart";
import "package:photos/core/configuration.dart";
+import "package:photos/models/file/dummy_file.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/gallery/fixed_extent_grid_row.dart";
import "package:photos/models/gallery/fixed_extent_section_layout.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart";
+import "package:photos/ui/viewer/gallery/component/dummy_file_widget.dart";
import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/type.dart";
@@ -59,6 +61,7 @@ class GalleryGroups {
late final int crossAxisCount;
late final List<FixedExtentSectionLayout> _groupLayouts;
+ late final List<EnteFile> _allFilesWithDummies;
final List<String> _groupIds = [];
final Map<String, List<EnteFile>> _groupIdToFilesMap = {};
@@ -84,6 +87,10 @@ class GalleryGroups {
List<({String groupID, String title})> get scrollbarDivisions =>
_scrollbarDivisions;
+ /// Returns allFiles with dummy entries added at appropriate positions to fill
+ /// incomplete rows in each group. Computed once during initialization.
+ List<EnteFile> get allFilesWithDummies => _allFilesWithDummies;
+
double? getOffsetOfFile(EnteFile file) {
final creationTime = file.creationTime;
if (creationTime == null) {
@@ -151,6 +158,13 @@ class GalleryGroups {
void init() {
crossAxisCount = localSettings.getPhotoGridSize();
_buildGroups();
+
+ // Build allFilesWithDummies by flattening groups in order
+ // This is computed once here for O(1) access via the getter
+ _allFilesWithDummies = _groupIds
+ .expand((groupId) => _groupIdToFilesMap[groupId]!)
+ .toList(growable: false);
+
_groupLayouts = _computeGroupLayouts();
assert(groupIDs.length == _groupIdToFilesMap.length);
@@ -223,27 +237,41 @@ class GalleryGroups {
bool endOfListReached = false;
int i = 0;
while (!endOfListReached) {
- gridRowChildren.add(
- RepaintBoundary(
- key: ValueKey(
- tagPrefix +
- filesInGroup[firstIndexOfRowWrtFilesInGroup + i]
- .tag,
+ final currentFile =
+ filesInGroup[firstIndexOfRowWrtFilesInGroup + i];
+
+ if (currentFile is DummyFile) {
+ // Add dummy widget for DummyFile
+ gridRowChildren.add(
+ RepaintBoundary(
+ key: ValueKey(tagPrefix + currentFile.tag),
+ child: DummyFileWidget(
+ file: currentFile,
+ selectedFiles: selectedFiles,
+ limitSelectionToOne: limitSelectionToOne,
+ ),
),
- child: GalleryFileWidget(
- file: filesInGroup[firstIndexOfRowWrtFilesInGroup + i],
- selectedFiles: selectedFiles,
- limitSelectionToOne: limitSelectionToOne,
- tag: tagPrefix,
- photoGridSize: crossAxisCount,
- currentUserID: currentUserID,
+ );
+ } else {
+ // Add normal GalleryFileWidget for real files
+ gridRowChildren.add(
+ RepaintBoundary(
+ key: ValueKey(
+ tagPrefix + currentFile.tag,
+ ),
+ child: GalleryFileWidget(
+ file: currentFile,
+ selectedFiles: selectedFiles,
+ limitSelectionToOne: limitSelectionToOne,
+ tag: tagPrefix,
+ photoGridSize: crossAxisCount,
+ currentUserID: currentUserID,
+ ),
),
- ),
- );
+ );
+ }
- endOfListReached =
- filesInGroup[firstIndexOfRowWrtFilesInGroup + i] ==
- lastFile;
+ endOfListReached = currentFile == lastFile;
i++;
}
} else {
@@ -338,12 +366,33 @@ class GalleryGroups {
Set<int> yearsInGroups,
) {
final uuid = _uuid.v1();
+
+ // Save original first and last files before adding dummies
+ final firstFile = groupFiles.first;
+ final lastFile = groupFiles.last;
+
+ // Add dummy files to fill the last row if needed
+ final filesInLastRow = groupFiles.length % crossAxisCount;
+ if (filesInLastRow != 0) {
+ final dummiesNeeded = crossAxisCount - filesInLastRow;
+ final filesWithDummies = List<EnteFile>.from(groupFiles);
+ for (int i = 0; i < dummiesNeeded; i++) {
+ filesWithDummies.add(
+ DummyFile(
+ groupID: uuid,
+ index: i,
+ ),
+ );
+ }
+ groupFiles = filesWithDummies;
+ }
+
_groupIds.add(uuid);
_groupIdToFilesMap[uuid] = groupFiles;
_groupIdToGroupDataMap[uuid] = (
groupType: groupType,
- startCreationTime: groupFiles.first.creationTime!,
- endCreationTime: groupFiles.last.creationTime!
+ startCreationTime: firstFile.creationTime!,
+ endCreationTime: lastFile.creationTime!
);
// For scrollbar divisions
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/dummy_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/dummy_file_widget.dart
new file mode 100644
index 0000000000..f5c6cb846f
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/dummy_file_widget.dart
@@ -0,0 +1,58 @@
+import "package:flutter/material.dart";
+import "package:photos/models/file/dummy_file.dart";
+import "package:photos/models/selected_files.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/ui/viewer/gallery/component/swipe_selectable_file_widget.dart";
+
+/// A widget that displays a dummy placeholder in the gallery grid.
+/// Participates in swipe gesture tracking but is not selectable.
+class DummyFileWidget extends StatefulWidget {
+ final DummyFile file;
+ final SelectedFiles? selectedFiles;
+ final bool limitSelectionToOne;
+
+ const DummyFileWidget({
+ required this.file,
+ required this.selectedFiles,
+ required this.limitSelectionToOne,
+ super.key,
+ });
+
+ @override
+ State<DummyFileWidget> createState() => _DummyFileWidgetState();
+}
+
+class _DummyFileWidgetState extends State<DummyFileWidget> {
+ @override
+ Widget build(BuildContext context) {
+ // Check if swipe selection should be enabled (same as GalleryFileWidget)
+ final shouldEnableSwipeSelection =
+ flagService.internalUser && !widget.limitSelectionToOne;
+
+ final Widget dummyContent = _buildDummyContent();
+
+ // Wrap with swipe selection if enabled
+ if (shouldEnableSwipeSelection) {
+ return SwipeSelectableFileWidget(
+ file: widget.file,
+ selectedFiles: widget.selectedFiles,
+ onPointerStateChanged: (pointerId, isInside) {
+ // Track pointer state but don't use it since dummies aren't selectable
+ },
+ child: dummyContent,
+ );
+ }
+
+ return dummyContent;
+ }
+
+ Widget _buildDummyContent() {
+ // Simple grey placeholder that doesn't respond to taps or selections
+ return Container(
+ color: Colors.grey.withValues(alpha: 0.3),
+ child: const Center(
+ child: Icon(Icons.image_outlined, color: Colors.grey),
+ ),
+ );
+ }
+}