Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remove redundant dummy file filtering and add documentation

ashilkn8311fd7b2479
diff --git a/mobile/apps/photos/lib/models/selected_files.dart b/mobile/apps/photos/lib/models/selected_files.dart
index 14ce019f5c..b63b309594 100644
--- a/mobile/apps/photos/lib/models/selected_files.dart
+++ b/mobile/apps/photos/lib/models/selected_files.dart
@@ -5,6 +5,17 @@ import 'package:photos/events/clear_selections_event.dart';
import 'package:photos/models/file/dummy_file.dart';
import 'package:photos/models/file/file.dart';
+/// Manages the set of currently selected files in the gallery.
+///
+/// This class serves as the single source of truth for file selection state
+/// and automatically filters out [DummyFile] instances from all selection
+/// operations. Dummy files are used for gallery layout purposes and should
+/// never be selected.
+///
+/// **Important:** All selection methods ([toggleSelection], [selectAll],
+/// [unSelectAll], [toggleGroupSelection]) automatically exclude dummy files.
+/// Calling code does not need to check for or filter out dummy files before
+/// calling these methods.
class SelectedFiles extends ChangeNotifier {
final files = <EnteFile>{};
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/swipe_to_select_helper.dart b/mobile/apps/photos/lib/ui/viewer/gallery/swipe_to_select_helper.dart
index 46dd9530b1..7b0ede609c 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/swipe_to_select_helper.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/swipe_to_select_helper.dart
@@ -1,6 +1,5 @@
import 'dart:math';
-import 'package:photos/models/file/dummy_file.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/selected_files.dart';
@@ -43,14 +42,11 @@ class SwipeToSelectHelper {
// Use forced mode if provided, otherwise determine based on initial file's selection state
_selecting = forceSelecting ?? !selectedFiles.isFileSelected(file);
- // If we're in selecting mode, immediately select the starting file
- // But skip if it's a DummyFile (dummies are not selectable)
- if (file is! DummyFile) {
- if (_selecting == true) {
- selectedFiles.selectAll({file});
- } else {
- selectedFiles.unSelectAll({file});
- }
+ // Immediately select/deselect the starting file based on mode
+ if (_selecting == true) {
+ selectedFiles.selectAll({file});
+ } else {
+ selectedFiles.unSelectAll({file});
}
}
@@ -82,13 +78,10 @@ class SwipeToSelectHelper {
final lastToIndex = _lastToIndex!;
final selecting = _selecting!;
- // Helper function to get range of files, excluding DummyFiles
+ // Helper function to get range of files
Set<EnteFile> getRange(int start, int end) {
if (start < end && start >= 0 && end <= allFiles.length) {
- return allFiles
- .getRange(start, end)
- .where((file) => file is! DummyFile)
- .toSet();
+ return allFiles.getRange(start, end).toSet();
}
return {};
}