Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prune Photos gallery comments

Manav Rathi213c992a7104
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
index 109b2ff564..98db42aa78 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
@@ -72,7 +72,6 @@ class CollectionPage extends StatelessWidget {
limit: limit,
asc: asc,
);
- // hide ignored files from home page UI
final ignoredIDs =
await IgnoredFilesService.instance.idToIgnoreReasonMap;
result.files.removeWhere(
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
index 2528faa43c..a8c6234fff 100644
--- 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
@@ -3,8 +3,6 @@ import "package:photos/models/file/dummy_file.dart";
import "package:photos/models/selected_files.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 StatelessWidget {
final DummyFile file;
final SelectedFiles? selectedFiles;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
index 8102e6cc1b..547fab91cd 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
@@ -175,7 +175,7 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
child: SelectAllStatusIcon(
isSelected: true,
size: 16,
- selectedFillColor: selectionColor, //same for both themes
+ selectedFillColor: selectionColor,
selectedTickCutsOut: true,
),
),
@@ -256,13 +256,11 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
_routeToDetailPage(file, context);
} else {
_toggleFileSelection(file);
- // Notify SwipeSelectableFileWidget if it exists
_handleLongPressForSwipe();
}
}
void _handleLongPressForSwipe() {
- // Use local state to determine if swipe should start
final swipeHelper = GallerySwipeHelper.of(context);
if (_currentPointerId != null &&
_isPointerInside &&
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart
index 4831a37a4e..193838fcb4 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart
@@ -147,7 +147,6 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {
child: widget.fadeInTrailingIcons
? Icon(
Icons.more_vert_outlined,
- // color: colorScheme.blurStrokeBase,
color: componentColors.textLighter,
).animate().fadeIn(
duration: const Duration(
@@ -165,7 +164,6 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {
)
: Icon(
Icons.more_vert_outlined,
- // color: colorScheme.blurStrokeBase,
color: componentColors.textLighter,
),
),
@@ -180,7 +178,6 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {
void _selectedFilesListener() {
if (widget.selectedFiles == null) return;
- // Filter out dummy files before checking selection state
final nonDummyFiles = widget.filesInGroup
.where((file) => file is! DummyFile)
.toSet();
@@ -212,7 +209,6 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {
}
bool _areAllFromGroupSelected() {
- // Filter out dummy files before checking selection state
final nonDummyFiles = widget.filesInGroup
.where((file) => file is! DummyFile)
.toSet();
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dart
index 53dc8b30be..12dda45687 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dart
@@ -67,11 +67,6 @@ extension GroupTypeExtension on GroupType {
}
}
- // returns true if the group should be refreshed.
- // If groupType is day, it should return true if the list of modified files contains a file that was created on the same day as the first file.
- // If groupType is week, it should return true if the list of modified files contains a file that was created in the same week as the first file.
- // If groupType is month, it should return true if the list of modified files contains a file that was created in the same month as the first file.
- // If groupType is year, it should return true if the list of modified files contains a file that was created in the same year as the first file.
bool areModifiedFilesPartOfGroup(
List<EnteFile> modifiedFiles,
EnteFile fistFile, {
@@ -118,7 +113,6 @@ extension GroupTypeExtension on GroupType {
}
}
- // for day, year, month, year type, return the microsecond range of the group
(int, int) getGroupRange(EnteFile file) {
switch (this) {
case GroupType.day:
@@ -213,7 +207,6 @@ extension GroupTypeExtension on GroupType {
final date = DateTime.fromMicrosecondsSinceEpoch(timestamp);
final now = DateTime.now();
- // Check if it's the current week
final startOfWeek = date.subtract(Duration(days: date.weekday - 1));
final nowStartOfWeek = now.subtract(Duration(days: now.weekday - 1));
@@ -223,7 +216,6 @@ extension GroupTypeExtension on GroupType {
return context.strings.thisWeek;
}
- // Check if it's the previous week
final lastWeekStart = nowStartOfWeek.subtract(const Duration(days: 7));
if (startOfWeek.year == lastWeekStart.year &&
startOfWeek.month == lastWeekStart.month &&
@@ -231,7 +223,6 @@ extension GroupTypeExtension on GroupType {
return context.strings.lastWeek;
}
- // Return formatted week range
final endOfWeek = startOfWeek.add(const Duration(days: 6));
return "${DateFormat.MMMd(Localizations.localeOf(context).languageCode).format(startOfWeek)} - ${DateFormat.MMMd(Localizations.localeOf(context).languageCode).format(endOfWeek)}, ${endOfWeek.year}";
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/sectioned_sliver_list.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/sectioned_sliver_list.dart
index c192e22883..821eed8329 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/sectioned_sliver_list.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/sectioned_sliver_list.dart
@@ -9,25 +9,14 @@ import "package:photos/models/gallery/fixed_extent_section_layout.dart";
// Copyright (c) 2020-2023 Thibault Deckers and contributors
// Licensed under BSD-3-Clause License
-// Using a Single SliverVariedExtentList or Using a combination where there are
-// multiple sliver delegate builders in a CustomScrollView doesn't scale.
-
-// With using a Single SliverKnownExtentList with each section being either a
-// group header or a row of grid, the problem is that scrolling becomes janky
-// the deeper the list is scrolled if the list is large enough.
-
-// With using multiple slivers (and hence multiple SliverChildBuilderDelegates)
-// in CustomScrollView, the deep scrolling issue exists and the first child
-// of every builderDelegate is always initialized, even if it's not in viewport
-// or in cacheExtent.
+// Flutter's standard slivers become janky deep in large galleries. Using one
+// sliver per section also builds every section's first child, even off-screen.
+//
+// This custom sliver uses precomputed section sizes to jump to visible rows.
// https://github.com/flutter/flutter/issues/168442
// https://github.com/flutter/flutter/issues/95028
-// A custom implementation of SliverMultiBoxAdaptorWidget
-// adapted from SliverFixedExtentBoxAdaptor. Optimizations in layout solves
-// the deep scrolling issue.
-
class SectionedListSliver<T> extends StatelessWidget {
final List<FixedExtentSectionLayout> sectionLayouts;
const SectionedListSliver({super.key, required this.sectionLayouts});
@@ -128,8 +117,7 @@ class _RenderSliverKnownExtentBoxAdaptor extends RenderSliverMultiBoxAdaptor {
double? leadingScrollOffset,
double? trailingScrollOffset,
}) {
- // default implementation is an estimation via `childManager.estimateMaxScrollOffset()`
- // but we have the accurate offset via pre-computed section layouts
+ // Section sizes give us the exact scroll extent; do not estimate it.
return _sectionLayouts.last.maxOffset;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart
index b6ae4054de..073e41e5f1 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart
@@ -4,10 +4,6 @@ import "package:photos/models/selected_files.dart";
import "package:photos/ui/common/touch_cross_detector.dart";
import "package:photos/ui/viewer/gallery/state/gallery_swipe_helper.dart";
-/// A wrapper widget that adds swipe-to-select functionality to a file widget.
-///
-/// This widget encapsulates all the swipe selection logic, keeping the
-/// GalleryFileWidget clean and focused on file display.
class SwipeSelectableFileWidget extends StatefulWidget {
final Widget child;
final EnteFile file;
@@ -40,14 +36,12 @@ class _SwipeSelectableFileWidgetState extends State<SwipeSelectableFileWidget> {
return ValueListenableBuilder<bool>(
valueListenable: swipeActiveNotifier ?? ValueNotifier(false),
builder: (context, isSwipeActive, child) {
- // Check if we need to start selection when swipe becomes active
if (isSwipeActive &&
_isPointerInside &&
swipeHelper != null &&
!swipeHelper.isActive &&
widget.selectedFiles != null &&
widget.selectedFiles!.files.isNotEmpty) {
- // Schedule the selection to happen after the current build
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted &&
isSwipeActive &&
@@ -62,35 +56,26 @@ class _SwipeSelectableFileWidgetState extends State<SwipeSelectableFileWidget> {
onPointerDown: (event) {
_isPointerInside = true;
widget.onPointerStateChanged?.call(event.pointer, true);
- // If files are already selected and swipe is not active, prepare for potential swipe
- // The actual selection will start when horizontal movement is detected
},
onHover: (event) {
_isPointerInside = true;
- // Handle the initial file selection when swipe becomes active
- // This is mainly for horizontal swipe detection since vertical after long press
- // is already handled by swipeHelper being active
if (swipeActiveNotifier?.value == true &&
swipeHelper != null &&
!swipeHelper.isActive &&
widget.selectedFiles != null &&
widget.selectedFiles!.files.isNotEmpty) {
- // Start selection for the first file when horizontal swipe is detected
swipeHelper.startSelection(widget.file);
}
},
onEnter: (event) {
_isPointerInside = true;
widget.onPointerStateChanged?.call(event.pointer, true);
- // Check if swipe is active (either from horizontal swipe or from long press)
if ((swipeActiveNotifier?.value == true ||
swipeHelper?.isActive == true) &&
swipeHelper != null) {
if (!swipeHelper.isActive) {
- // Start selection when first entering a file during active swipe
swipeHelper.startSelection(widget.file);
} else {
- // Update selection for subsequent files
swipeHelper.updateSelection(widget.file);
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 19f5633227..54c50aa32e 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -76,32 +76,23 @@ class Gallery extends StatefulWidget {
final GalleryType? galleryType;
final bool showGallerySettingsCTA;
- /// Returns eligible additions, or null when the gallery must reload.
+ // Return null to force a full reload.
final NewLocalFilesResolver? newLocalFilesResolver;
- /// When true, selection will be limited to one item. Tapping on any item
- /// will select even when no other item is selected.
+ // Single-selection mode also selects on the first tap.
final bool limitSelectionToOne;
final bool addHeaderOrFooterEmptyState;
- /// When true, the gallery will be in selection mode. Tapping on any item
- /// will select it even when no other item is selected. This is only used to
- /// make selection possible without long pressing. If a gallery has selected
- /// files, it's not necessary that this will be true.
final bool inSelectionMode;
final bool showSelectAll;
- // add a Function variable to get sort value in bool
final SortAscFn? sortAsyncFn;
- /// Pass value to override default group type.
final GroupType? groupType;
final bool disablePinnedGroupHeader;
final bool disableVerticalPaddingForScrollbar;
- /// File to jump to when gallery is loaded. The gallery will scroll to the
- /// group containing this file.
final EnteFile? fileToJumpTo;
const Gallery({
@@ -185,7 +176,7 @@ class GalleryState extends State<Gallery> {
_automationScrollIdentifier = _buildAutomationScrollIdentifier(
widget.tagPrefix,
);
- // end the tag with x to avoid `.` in the end if logger name
+ // Avoid a trailing "." in the logger name.
_logTag =
"Gallery_${widget.tagPrefix}${kDebugMode ? "_" + widget.albumName! : ""}_x";
_logger = Logger(_logTag);
@@ -236,8 +227,6 @@ class GalleryState extends State<Gallery> {
: _debouncer;
targetDebouncer.run(() async {
- // In soft refresh, setState is called for entire gallery only when
- // number of child change
_logger.info(
"${isPriorityEvent ? 'Priority' : 'Soft'} refresh on ${event.reason}",
);
@@ -286,7 +275,6 @@ class GalleryState extends State<Gallery> {
_onFilesLoaded(widget.initialFiles!);
}
- // First load
_loadFiles(limit: kInitialLoadLimit).then((result) async {
_setFilesAndReload(result.files);
if (result.hasMore) {
@@ -325,7 +313,6 @@ class GalleryState extends State<Gallery> {
}
WidgetsBinding.instance.addPostFrameCallback((_) async {
- // To set the initial value of scrollbar bottom padding
_selectedFilesListener();
try {
final headerRenderBox = await miscUtil
@@ -395,10 +382,8 @@ class GalleryState extends State<Gallery> {
);
galleryGroups = groups;
- // Cache the list with dummies
+ // Keep dummy cells in the swipe index so it matches the rendered grid.
_allFilesWithDummies = groups.allFilesWithDummies;
-
- // Always update SwipeHelper when cache is updated
_updateSwipeHelper();
if (callSetState) {
@@ -406,23 +391,6 @@ class GalleryState extends State<Gallery> {
}
}
- // void _setScrollController({required bool allFilesLoaded}) {
- // if (widget.fileToJumpScrollTo != null && allFilesLoaded) {
- // final fileOffset =
- // galleryGroups.getOffsetOfFile(widget.fileToJumpScrollTo!);
- // if (fileOffset == null) {
- // _logger.warning(
- // "File offset is null, cannot set initial scroll controller",
- // );
- // }
-
- // _scrollController?.jumpTo(fileOffset ?? 0);
- // } else {
- // _scrollController = ScrollController();
- // }
- // setState(() {});
- // }
-
void _selectedFilesListener() {
final bottomInset = MediaQuery.paddingOf(context).bottom;
final extra = widget.galleryType == GalleryType.homepage ? 76.0 : 0.0;
@@ -454,7 +422,6 @@ class GalleryState extends State<Gallery> {
if (event.source == 'uploadCompleted') {
final Map<int, EnteFile> genIDToUploadedFiles = {};
for (int i = 0; i < event.updatedFiles.length; i++) {
- // matching happens on generatedID and localID
if (event.updatedFiles[i].generatedID == null) {
return true;
}
@@ -489,8 +456,6 @@ class GalleryState extends State<Gallery> {
return shouldReloadFromDB;
}
- // Handle event when an local file was already uploaded and we have now
- // added localID link link to the remote file
bool _shouldReloadOnFileMissingLocal(FilesUpdatedEvent event) {
bool shouldReloadFromDB = true;
if (event.source != 'fileMissingLocal' ||
@@ -502,8 +467,6 @@ class GalleryState extends State<Gallery> {
}
final Map<int, EnteFile> genIDToUploadedFiles = {};
for (int i = 0; i < event.updatedFiles.length; i++) {
- // the file should have generatedID, localID and should not be uploaded for
- // following logic to work
if (event.updatedFiles[i].generatedID == null ||
event.updatedFiles[i].localID == null ||
event.updatedFiles[i].isUploaded) {
@@ -615,11 +578,7 @@ class GalleryState extends State<Gallery> {
void _updateSwipeHelper() {
if (widget.selectedFiles != null && _allFilesWithDummies.isNotEmpty) {
- // Dispose existing helper if present
_swipeHelper?.dispose();
- // Use allFilesWithDummies to match the rendered grid structure.
- // This allows SwipeHelper to track pointer position through dummy
- // placeholders while filtering them from selection operations.
_swipeHelper = SwipeToSelectHelper(
allFiles: _allFilesWithDummies,
selectedFiles: widget.selectedFiles!,
@@ -648,7 +607,6 @@ class GalleryState extends State<Gallery> {
"ms",
);
- /// To curate filters when a gallery is first opened.
if (!result.hasMore) {
if (!mounted) {
return result;
@@ -677,7 +635,6 @@ class GalleryState extends State<Gallery> {
@override
void dispose() {
- // Clear scroll controller reference
_boundariesProvider?.setScrollController(null);
_reloadEventSubscription?.cancel();
@@ -734,14 +691,12 @@ class GalleryState extends State<Gallery> {
final appBarPinnedHeight = appBarGeometry?.minExtent ?? 0;
final appBarCollapseExtent = appBarGeometry?.collapseExtent ?? 0;
- // Share scroll controller with boundaries provider after build
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
_boundariesProvider?.setScrollController(_scrollController);
}
});
- // Jump to date logic
if (widget.fileToJumpTo != null &&
!_completedJumpToDate &&
_allFilesLoaded &&
@@ -841,7 +796,6 @@ class GalleryState extends State<Gallery> {
);
}
- // Check if width changed due to orientation change and update gallery groups
if (groups.widthAvailable != widthAvailable) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
@@ -1087,20 +1041,16 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader>
widget.headerHeightNotifier.value!;
if (normalizedScrollOffset < 0) {
_setBaseTopBoundary();
- // No change in group ID, no need to call setState
if (currentGroupId == null) return;
currentGroupId = null;
} else {
final groupScrollOffsets = widget.galleryGroups.groupScrollOffsets;
- // Binary search to find the index of the largest scrollOffset in
- // groupScrollOffsets which is <= scrollPosition
+ // Find the last group whose offset is at or before the viewport.
int low = 0;
int high = groupScrollOffsets.length - 1;
int floorIndex = 0;
- // Handle the case where scrollPosition is smaller than the first key.
- // In this scenario, we associate it with the first heading.
if (normalizedScrollOffset < groupScrollOffsets.first) {
return;
}
@@ -1110,14 +1060,9 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader>
final midValue = groupScrollOffsets[mid];
if (midValue <= normalizedScrollOffset) {
- // This key is less than or equal to the target scrollPosition.
- // It's a potential floor. Store its index and try searching higher
- // for a potentially closer floor value.
floorIndex = mid;
low = mid + 1;
} else {
- // This key is greater than the target scrollPosition.
- // The floor must be in the lower half.
high = mid - 1;
}
}
@@ -1125,7 +1070,6 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader>
widget
.galleryGroups
.scrollOffsetToGroupIdMap[groupScrollOffsets[floorIndex]]) {
- // No change in group ID, no need to call setState
return;
}
currentGroupId = widget
@@ -1295,11 +1239,9 @@ class GalleryIndexUpdatedEvent {
GalleryIndexUpdatedEvent(this.tag, this.index);
}
-/// Custom scroll physics that extends [BouncingScrollPhysics] to provide
-/// exponential bouncing behavior for scrollable widgets.
-///
-/// TODO: Revert this PR https://github.com/ente/ente/pull/8401 after Jan 1, 2026.
-/// This was implemented temporarily for the Christmas banner and should be removed afterwards.
+// TODO: Revert this PR https://github.com/ente/ente/pull/8401 after Jan 1,
+// 2026. This was implemented temporarily for the Christmas banner and should
+// be removed afterwards.
class ExponentialBouncingScrollPhysics extends BouncingScrollPhysics {
const ExponentialBouncingScrollPhysics({super.parent});
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_actions.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_actions.dart
index 6bd207a353..b50574bbc7 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_actions.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_actions.dart
@@ -4,7 +4,6 @@ import "package:ente_components/ente_components.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
-/// Shared trailing-action surface for the gallery / people / cluster app bars.
class GalleryAppBarIconButtonSurface extends StatelessWidget {
const GalleryAppBarIconButtonSurface({required this.icon, super.key});
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
index 80fbaf253e..2b55b57a80 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -479,7 +479,6 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
List<Widget> _getDefaultActions(BuildContext context) {
final List<Widget> actions = <Widget>[];
- // If the user has selected files, don't show any actions
if (widget.selectedFiles.files.isNotEmpty ||
!Configuration.instance.hasConfiguredAccount()) {
return actions;
@@ -1051,7 +1050,6 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
Future<void> _trashCollection() async {
- // Fetch the count by-passing the cache to avoid any stale data
final int count = await CollectionsService.instance.getFileCount(
widget.collection!,
useCache: false,
@@ -1217,13 +1215,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
Future<void> _onGalleryGuestViewClick() async {
if (await LocalAuthentication().isDeviceSupported()) {
- // Get all files from the collection with proper sort order
late final List<EnteFile> collectionFiles;
if (widget.files != null) {
- // If files are already provided, use them
collectionFiles = widget.files!;
} else if (widget.collection != null) {
- // Fetch all files from the collection
final filesResult = await FilesDB.instance.getFilesInCollection(
widget.collection!.id,
galleryLoadStartTime,
@@ -1243,7 +1238,6 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
return;
}
- // Use the same logic as selected files guest view
final page = DetailPage(
DetailPageConfiguration(
collectionFiles,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
index 023dfda8a5..533db35f48 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
@@ -58,7 +58,6 @@ class AddPhotosPhotoWidget extends StatelessWidget {
});
final Set<int> hiddenCollectionIDs = CollectionsService.instance
.getHiddenCollectionIds();
- // Hide the current collection files from suggestions
hiddenCollectionIDs.add(collection.id);
return Container(
@@ -233,9 +232,8 @@ class AddPhotosPhotoWidget extends StatelessWidget {
}
}
- // _getAssetPickerTextDelegate returns the text delegate for the asset picker
- // This custom method is required to enforce English as the default fallback
- // instead of Chinese.
+ // AssetPicker's fallback is Chinese. Unsupported locales use its English
+ // delegate.
Future<AssetPickerTextDelegate> _getAssetPickerTextDelegate() async {
final Locale locale = (await getLocale())!;
switch (locale.languageCode.toLowerCase()) {
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/edit_album_details_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/edit_album_details_sheet.dart
index 132abae6be..b724ffa834 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/edit_album_details_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/edit_album_details_sheet.dart
@@ -20,8 +20,7 @@ class AlbumDetailsUpdate {
final String name;
final String description;
- /// Null when the cover was not edited. Zero resets the cover to the album's
- /// default photo.
+ // Null means unchanged; zero restores the default cover.
final int? coverID;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_cover_photo.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_cover_photo.dart
index 321d8821d6..2642f65733 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_cover_photo.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_cover_photo.dart
@@ -82,7 +82,6 @@ class _PickCoverPhotoWidgetState extends State<PickCoverPhotoWidget> {
limit: limit,
asc: asc,
);
- // Hide ignored files from the picker.
final ignoredIDs =
await IgnoredFilesService.instance.idToIgnoreReasonMap;
result.files.removeWhere(
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
index b7b1c4f651..1da03548ab 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
@@ -92,12 +92,6 @@ class PickPersonCoverPhotoWidget extends StatelessWidget {
return result;
},
- // reloadEvent: Bus.instance
- // .on<CollectionUpdatedEvent>()
- // .where(
- // (event) =>
- // event.collectionID == collection.id,
- // ),
tagPrefix: "pick_center_point_gallery",
selectedFiles: selectedFiles,
limitSelectionToOne: true,
@@ -123,7 +117,6 @@ class PickPersonCoverPhotoWidget extends StatelessWidget {
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 428),
child: Padding(
- //inner stroke of 1pt + 15 pts of top padding = 16 pts
padding: const EdgeInsets.fromLTRB(16, 15, 16, 8),
child: ValueListenableBuilder(
valueListenable: isFileSelected,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/jump_to_date_gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/jump_to_date_gallery.dart
index 08d777b0bd..577ffa02c5 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/jump_to_date_gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/jump_to_date_gallery.dart
@@ -68,7 +68,6 @@ class _JumpToDateGalleryState extends State<JumpToDateGallery> {
}
});
- // Load files asynchronously
_loadFiles();
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/large_files_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/large_files_page.dart
index 5f50b5c5ef..3eab2dd4f1 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/large_files_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/large_files_page.dart
@@ -85,7 +85,6 @@ class _LargeFilesPagePageState extends State<LargeFilesPagePage> {
}
}
}
- // sort by file size descending
filesWithSize.sort((a, b) => b.fileSize!.compareTo(a.fileSize!));
final FileLoadResult result = FileLoadResult(filesWithSize, false);
return result;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar.dart
index 89081e59ff..534b3f03b4 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/custom_scroll_bar.dart
@@ -40,11 +40,8 @@ class _CustomScrollBarState extends State<CustomScrollBar> {
late bool _showScrollbarDivisions;
late bool _showThumb;
- // Scrollbar's thumb height is not fixed by default. If the scrollable is short
- // enough, the scrollbar's height can go above the minimum length.
- // In our case, we only depend on this value for showing scrollbar divisions,
- // which we do not show unless scrollable is long enough. So we can safely
- // assume that the scrollbar's height will always this minimum value.
+ // Divisions only appear in long galleries, where the thumb stays at this
+ // minimum height.
static const _kScrollbarMinLength = 36.0;
@override
@@ -93,8 +90,6 @@ class _CustomScrollBarState extends State<CustomScrollBar> {
});
}
- // Reason for calling _computePositionToTileMap here is, it needs
- // heightOfScrollbarDivider to be set.
WidgetsBinding.instance.addPostFrameCallback((_) {
_computePositionToTitleMap();
});
@@ -102,11 +97,8 @@ class _CustomScrollBarState extends State<CustomScrollBar> {
}
}
- // Galleries where this scrollbar is used can gave different extents of headers
- // and footers. These extents are not taken into account while computing
- // the position of scrollbar divisions since we only show scrollbar divisions
- // if the scrollable is long enough, where the header and footer extents
- // are negligible compared to max extent of the scrollable.
+ // Division positions ignore header and footer heights. They are negligible
+ // in the long galleries that show divisions.
Future<void> _computePositionToTitleMap() async {
_logger.info("Computing position to title map");
final result = <({double position, String title})>[];
@@ -134,25 +126,13 @@ class _CustomScrollBarState extends State<CustomScrollBar> {
if (groupScrollOffsetToUse < 0) {
result.add((position: 0, title: scrollbarDivision.title));
} else {
- // By default, the exact scroll position of the scrollable isn't tied
- // to the center or one constant point of it's scrollbar. This point of
- // the scrollbar moves from top to bottom across it when the scrollable
- // is scolled from top to bottom.
-
- // This correction is to ensure that the scrollbar division elements
- // appear at the same point of the scrollbar everytime and are
- // accurate in terms of UX (that is, when scrollbar's is dragged to a
- // particular scrollbar division (start of the division in gallery),
- // the division element is always at the same point of the scrollbar).
- // Ideally this point should be the mid of the scrollbar, but it's
- // slightly off, not sure why. But this is fine enough.
+ // Account for the thumb's height so each label lines up with its
+ // gallery section while dragging.
final fractionOfGroupScrollOffsetWrtMaxExtent =
groupScrollOffsetToUse / maxScrollExtent;
late final double positionCorrection;
- // This value is the distance from the mid of the scrollbar to the mid
- // of the scrollbar divider element when both pinned to the top, that
- // is, their top edges are overlapping.
+ // Offset between the thumb and label centers at the top.
final value = (_kScrollbarMinLength - heightOfScrollbarDivider!) / 2;
if (fractionOfGroupScrollOffsetWrtMaxExtent < 0.5) {
@@ -180,10 +160,10 @@ class _CustomScrollBarState extends State<CustomScrollBar> {
return;
}
- // Remove first scrollbar division since it doesn't add value in terms of UX
+ // The first division marks the top and adds no useful landmark.
result.removeAt(0);
- // Filter out positions that are too close to each other
+ // Keep division labels at least 48 pixels apart.
if (result.isNotEmpty) {
filteredResult.add(result.first);
for (int i = 1; i < result.length; i++) {
@@ -205,7 +185,8 @@ class _CustomScrollBarState extends State<CustomScrollBar> {
if (renderBox == null) {
return Future.value(0);
}
- // Retry for : https://github.com/flutter/flutter/issues/25827
+ // RenderBox height may initially be zero:
+ // https://github.com/flutter/flutter/issues/25827
return MiscUtil()
.getNonZeroDoubleWithRetry(
() => renderBox.size.height,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart
index db269775d7..1248015329 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/scrollbar/scroll_bar_with_use_notifier.dart
@@ -1,5 +1,4 @@
-// Modified Scrollbar that accepts a ValueNotifier<bool> to indicate if the
-// scrollbar is in use plus with modified scrollbar theme.
+// Flutter's Scrollbar modified to report when its thumb is in use.
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
@@ -16,72 +15,7 @@ const Radius _kScrollbarRadius = Radius.circular(8.0);
const Duration _kScrollbarFadeDuration = Duration(milliseconds: 300);
const Duration _kScrollbarTimeToFade = Duration(milliseconds: 600);
-/// A Material Design scrollbar.
-///
-/// To add a scrollbar to a [ScrollView], wrap the scroll view
-/// widget in a [ScrollbarWithUseNotifer] widget.
-///
-/// {@youtube 560 315 https://www.youtube.com/watch?v=DbkIQSvwnZc}
-///
-/// {@macro flutter.widgets.Scrollbar}
-///
-/// Dynamically changes to a [CupertinoScrollbar], an iOS style scrollbar, by
-/// default on the iOS platform.
-///
-/// The color of the Scrollbar thumb will change when [WidgetState.dragged],
-/// or [WidgetState.hovered] on desktop and web platforms. These stateful
-/// color choices can be changed using [ScrollbarThemeData.thumbColor].
-///
-/// {@tool dartpad}
-/// This sample shows a [ScrollbarWithUseNotifer] that executes a fade animation as scrolling
-/// occurs. The Scrollbar will fade into view as the user scrolls, and fade out
-/// when scrolling stops.
-///
-/// ** See code in examples/api/lib/material/scrollbar/scrollbar.0.dart **
-/// {@end-tool}
-///
-/// {@tool dartpad}
-/// When [thumbVisibility] is true, the scrollbar thumb will remain visible
-/// without the fade animation. This requires that a [ScrollController] is
-/// provided to controller, or that the [PrimaryScrollController] is available.
-///
-/// When a [ScrollView.scrollDirection] is [Axis.horizontal], it is recommended
-/// that the [ScrollbarWithUseNotifer] is always visible, since scrolling in the horizontal
-/// axis is less discoverable.
-///
-/// ** See code in examples/api/lib/material/scrollbar/scrollbar.1.dart **
-/// {@end-tool}
-///
-/// A scrollbar track can be added using [trackVisibility]. This can also be
-/// drawn when triggered by a hover event, or based on any [WidgetState] by
-/// using [ScrollbarThemeData.trackVisibility].
-///
-/// The [thickness] of the track and scrollbar thumb can be changed dynamically
-/// in response to [WidgetState]s using [ScrollbarThemeData.thickness].
-///
-/// See also:
-///
-/// * [RawScrollbar], a basic scrollbar that fades in and out, extended
-/// by this class to add more animations and behaviors.
-/// * [ScrollbarTheme], which configures the Scrollbar's appearance.
-/// * [CupertinoScrollbar], an iOS style scrollbar.
-/// * [ListView], which displays a linear, scrollable list of children.
-/// * [GridView], which displays a 2 dimensional, scrollable array of children.
class ScrollbarWithUseNotifer extends StatelessWidget {
- /// Creates a Material Design scrollbar that by default will connect to the
- /// closest Scrollable descendant of [child].
- ///
- /// The [child] should be a source of [ScrollNotification] notifications,
- /// typically a [Scrollable] widget.
- ///
- /// If the [controller] is null, the default behavior is to
- /// enable scrollbar dragging using the [PrimaryScrollController].
- ///
- /// When null, [thickness] defaults to 8.0 pixels on desktop and web, and 4.0
- /// pixels when on mobile platforms. A null [radius] will result in a default
- /// of an 8.0 pixel circular radius about the corners of the scrollbar thumb,
- /// except for when executing on [TargetPlatform.android], which will render the
- /// thumb without a radius.
const ScrollbarWithUseNotifer({
super.key,
required this.child,
@@ -99,57 +33,22 @@ class ScrollbarWithUseNotifer extends StatelessWidget {
this.scrollbarPadding,
});
- /// {@macro flutter.widgets.Scrollbar.child}
final Widget child;
- /// {@macro flutter.widgets.Scrollbar.controller}
final ScrollController? controller;
- /// {@macro flutter.widgets.Scrollbar.thumbVisibility}
- ///
- /// If this property is null, then [ScrollbarThemeData.thumbVisibility] of
- /// [ThemeData.scrollbarTheme] is used. If that is also null, the default value
- /// is false.
- ///
- /// If the thumb visibility is related to the scrollbar's material state,
- /// use the global [ScrollbarThemeData.thumbVisibility] or override the
- /// sub-tree's theme data.
final bool? thumbVisibility;
- /// {@macro flutter.widgets.Scrollbar.trackVisibility}
- ///
- /// If this property is null, then [ScrollbarThemeData.trackVisibility] of
- /// [ThemeData.scrollbarTheme] is used. If that is also null, the default value
- /// is false.
- ///
- /// If the track visibility is related to the scrollbar's material state,
- /// use the global [ScrollbarThemeData.trackVisibility] or override the
- /// sub-tree's theme data.
final bool? trackVisibility;
- /// The thickness of the scrollbar in the cross axis of the scrollable.
- ///
- /// If null, the default value is platform dependent. On [TargetPlatform.android],
- /// the default thickness is 4.0 pixels. On [TargetPlatform.iOS],
- /// [CupertinoScrollbar.defaultThickness] is used. The remaining platforms have a
- /// default thickness of 8.0 pixels.
final double? thickness;
- /// The [Radius] of the scrollbar thumb's rounded rectangle corners.
- ///
- /// If null, the default value is platform dependent. On [TargetPlatform.android],
- /// no radius is applied to the scrollbar thumb. On [TargetPlatform.iOS],
- /// [CupertinoScrollbar.defaultRadius] is used. The remaining platforms have a
- /// default [Radius.circular] of 8.0 pixels.
final Radius? radius;
- /// {@macro flutter.widgets.Scrollbar.interactive}
final bool? interactive;
- /// {@macro flutter.widgets.Scrollbar.notificationPredicate}
final ScrollNotificationPredicate? notificationPredicate;
- /// {@macro flutter.widgets.Scrollbar.scrollbarOrientation}
final ScrollbarOrientation? scrollbarOrientation;
final ValueNotifier<bool> inUseNotifier;
@@ -230,7 +129,6 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
bool _hoverIsActive = false;
late ColorScheme _colorScheme;
late ScrollbarThemeData _scrollbarTheme;
- // On Android, scrollbars should match native appearance.
late bool _useAndroidScrollbar;
@override
@@ -286,8 +184,7 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
return _scrollbarTheme.thumbColor?.resolve(states) ?? dragColor;
}
- // If the track is visible, the thumb color hover animation is ignored and
- // changes immediately.
+ // A visible track changes the thumb color without the hover animation.
if (_trackVisibility.resolve(states)) {
return _scrollbarTheme.thumbColor?.resolve(states) ?? hoverColor;
}
@@ -344,7 +241,6 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
_scrollbarTheme.thickness?.resolve(states) ??
_kScrollbarThicknessWithTrack;
}
- // The default scrollbar thickness is smaller on mobile.
return widget.thickness ??
_scrollbarTheme.thickness?.resolve(states) ??
(_kScrollbarThickness / (_useAndroidScrollbar ? 2 : 1));
@@ -424,15 +320,12 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
@override
void handleHover(PointerHoverEvent event) {
super.handleHover(event);
- // Check if the position of the pointer falls over the painted scrollbar
if (isPointerOverScrollbar(event.position, event.kind, forHover: true)) {
- // Pointer is hovering over the scrollbar
setState(() {
_hoverIsActive = true;
});
_hoverAnimationController.forward();
} else if (_hoverIsActive) {
- // Pointer was, but is no longer over painted scrollbar.
setState(() {
_hoverIsActive = false;
});
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart
index 615d222db6..0832ab0c78 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/shared_public_collection_page.dart
@@ -60,7 +60,6 @@ class _SharedPublicCollectionPageState
super.initState();
logger.info("Init SharedPublicCollectionPage");
- // Show join dialog after the page is built if requested
if (widget.shouldShowJoinDialog) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_showJoinDialog();
@@ -125,8 +124,6 @@ class _SharedPublicCollectionPageState
? [widget.c.thumbnail!]
: null;
- // Determine groupType based on collection layout.
- // masonry/continuous (or unset) map to non-grouped rendering.
final normalizedLayout = normalizePublicLinkLayout(
widget.c.collection.pubMagicMetadata.layout,
);
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart
index 19e5527167..46c2f99111 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart
@@ -5,18 +5,11 @@ import 'package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart'
enum BoundaryPosition { top, bottom }
-/// Mixin for widgets that act as boundaries for auto-scroll
-/// Reports their position to GalleryBoundariesProvider with debouncing
mixin BoundaryReporter<T extends StatefulWidget> on State<T> {
final _boundaryKey = GlobalKey();
Timer? _boundaryUpdateTimer;
- /// Report this widget's boundary to the provider
- /// Call this when the widget is first built and when its size or position changes.
- /// Note: If using boundaryWidget() wrapper, boundaries are reported automatically
- /// after each build - manual calls are only needed for dynamic updates (e.g., visibility changes).
void reportBoundary(BoundaryPosition position) {
- // Debounce updates to avoid excessive recalculation
_boundaryUpdateTimer?.cancel();
_boundaryUpdateTimer = Timer(const Duration(milliseconds: 100), () {
if (!mounted) return;
@@ -34,11 +27,8 @@ mixin BoundaryReporter<T extends StatefulWidget> on State<T> {
if (renderBox != null && renderBox.hasSize) {
final offset = renderBox.localToGlobal(Offset.zero);
final boundary = position == BoundaryPosition.top
- ? offset.dy +
- renderBox
- .size
- .height // Bottom edge of top widget
- : offset.dy; // Top edge of bottom widget
+ ? offset.dy + renderBox.size.height
+ : offset.dy;
if (position == BoundaryPosition.top) {
provider.setTopBoundary(boundary);
@@ -46,7 +36,6 @@ mixin BoundaryReporter<T extends StatefulWidget> on State<T> {
provider.setBottomBoundary(boundary);
}
} else {
- // RenderBox not available (widget hidden/removed) - clear boundary
if (position == BoundaryPosition.top) {
provider.setTopBoundary(null);
} else {
@@ -56,13 +45,11 @@ mixin BoundaryReporter<T extends StatefulWidget> on State<T> {
});
}
- /// Widget that should have its boundary tracked
- /// Wrap your widget content with this
Widget boundaryWidget({
required Widget child,
required BoundaryPosition position,
}) {
- // Report boundary after frame is rendered
+ // Report after layout so the RenderBox has a position.
WidgetsBinding.instance.addPostFrameCallback((_) {
reportBoundary(position);
});
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dart
index 2db737eaef..cd06eb004b 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dart
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
-/// StatefulWidget that manages gallery boundaries and scroll controller lifecycle
class GalleryBoundariesProvider extends StatefulWidget {
final Widget child;
@@ -16,16 +15,13 @@ class GalleryBoundariesProvider extends StatefulWidget {
}
}
-/// State class that manages the lifecycle of boundary notifiers
class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {
- /// Bottom edge position of the top fixed widget (e.g., AppBar)
+ // Bottom edge of the top fixed widget.
late final ValueNotifier<double?> topBoundaryNotifier;
- /// Top edge position of the bottom fixed widget (e.g., FileSelectionOverlayBar)
+ // Top edge of the bottom fixed widget.
late final ValueNotifier<double?> bottomBoundaryNotifier;
- /// Reference to Gallery's ScrollController
- /// Using ValueNotifier to maintain immutability
late final ValueNotifier<ScrollController?> scrollControllerNotifier;
@override
@@ -44,17 +40,14 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {
super.dispose();
}
- /// Set the scroll controller from Gallery widget
void setScrollController(ScrollController? controller) {
scrollControllerNotifier.value = controller;
}
- /// Set the top boundary position
void setTopBoundary(double? boundary) {
topBoundaryNotifier.value = boundary;
}
- /// Set the bottom boundary position
void setBottomBoundary(double? boundary) {
bottomBoundaryNotifier.value = boundary;
}
@@ -65,8 +58,6 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {
}
}
-/// Public InheritedWidget to share gallery boundaries and scroll controller
-/// between Gallery and its surrounding widgets for auto-scroll functionality
class InheritedGalleryBoundaries extends InheritedWidget {
final GalleryBoundariesProviderState state;
@@ -76,28 +67,22 @@ class InheritedGalleryBoundaries extends InheritedWidget {
required super.child,
});
- /// Bottom edge position of the top fixed widget (e.g., AppBar)
ValueNotifier<double?> get topBoundaryNotifier => state.topBoundaryNotifier;
- /// Top edge position of the bottom fixed widget (e.g., FileSelectionOverlayBar)
ValueNotifier<double?> get bottomBoundaryNotifier =>
state.bottomBoundaryNotifier;
- /// Reference to Gallery's ScrollController
ValueNotifier<ScrollController?> get scrollControllerNotifier =>
state.scrollControllerNotifier;
- /// Set the scroll controller from Gallery widget
void setScrollController(ScrollController? controller) {
state.setScrollController(controller);
}
- /// Set the top boundary position
void setTopBoundary(double? boundary) {
state.setTopBoundary(boundary);
}
- /// Set the bottom boundary position
void setBottomBoundary(double? boundary) {
state.setBottomBoundary(boundary);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dart
index ae324fd5d4..2e7e7d447a 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dart
@@ -3,7 +3,6 @@ import "package:photos/models/gallery_type.dart";
import "package:photos/ui/viewer/gallery/component/group/type.dart";
class GalleryContextState extends InheritedWidget {
- ///Sorting by creation time
final bool sortOrderAsc;
final bool inSelectionMode;
final GroupType type;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_files_inherited_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_files_inherited_widget.dart
index 58c2093285..02758c2ed1 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_files_inherited_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_files_inherited_widget.dart
@@ -5,10 +5,7 @@ import "package:photos/models/file/file.dart";
class GalleryFilesState extends InheritedWidget {
GalleryFilesState({super.key, required super.child});
- ///Should be assigned later in gallery when files are loaded.
- ///Note: EnteFiles in this list should be references of the same EnteFiles
- ///that are grouped in gallery, so that when files are added/deleted,
- ///both lists are in sync.
+ // Keep the same file objects used by galleryGroups so mutations stay in sync.
List<EnteFile>? _galleryFiles;
set setGalleryFiles(List<EnteFile> galleryFiles) {
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart
index 26d76cb5e7..c815827204 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart
@@ -1,10 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:photos/ui/viewer/gallery/swipe_to_select_helper.dart';
-/// InheritedWidget to provide SwipeToSelectHelper to descendant widgets.
-///
-/// This allows GalleryFileWidget instances to access the swipe helper
-/// without passing it through multiple widget constructors.
class GallerySwipeHelper extends InheritedWidget {
final SwipeToSelectHelper? helper;
final ValueNotifier<bool>? swipeActiveNotifier;
@@ -16,14 +12,12 @@ class GallerySwipeHelper extends InheritedWidget {
required super.child,
});
- /// Get the SwipeToSelectHelper from the nearest ancestor GallerySwipeHelper.
static SwipeToSelectHelper? of(BuildContext context) {
final widget = context
.dependOnInheritedWidgetOfExactType<GallerySwipeHelper>();
return widget?.helper;
}
- /// Get the swipeActiveNotifier from the nearest ancestor GallerySwipeHelper.
static ValueNotifier<bool>? swipeActiveNotifierOf(BuildContext context) {
final widget = context
.dependOnInheritedWidgetOfExactType<GallerySwipeHelper>();
@@ -32,7 +26,6 @@ class GallerySwipeHelper extends InheritedWidget {
@override
bool updateShouldNotify(GallerySwipeHelper oldWidget) {
- // Notify if either the helper instance or notifier changes
return helper != oldWidget.helper ||
swipeActiveNotifier != oldWidget.swipeActiveNotifier;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/inherited_search_filter_data.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/inherited_search_filter_data.dart
index d5ebdc7d17..5757250571 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/inherited_search_filter_data.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/inherited_search_filter_data.dart
@@ -34,8 +34,7 @@ class _InheritedSearchFilterDataWrapperState
}
}
-/// Use [InheritedSearchFilterDataWrapper] instead if using
-/// [InheritedSearchFilterData] as a parent widget
+// Prefer InheritedSearchFilterDataWrapper so the provider is disposed.
class InheritedSearchFilterData extends InheritedWidget {
const InheritedSearchFilterData({
super.key,
@@ -43,7 +42,6 @@ class InheritedSearchFilterData extends InheritedWidget {
required super.child,
});
- /// Pass null if gallery doesn't need hierarchical search
final SearchFilterDataProvider? searchFilterDataProvider;
bool get isHierarchicalSearchable =>
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart
index ec72aa7279..7262827881 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/search_filter_data_provider.dart
@@ -6,15 +6,13 @@ import "package:photos/models/search/hierarchical/only_them_filter.dart";
class SearchFilterDataProvider {
final _appliedFiltersNotifier = _AppliedFiltersNotifier();
- /// [_recommededFiltersNotifier.value] are filters sorted by decreasing
- /// order of relevance
final _recommendedFiltersNotifier = _RecommendedFiltersNotifier();
final isSearchingNotifier = ValueNotifier(false);
HierarchicalSearchFilter initialGalleryFilter;
SearchFilterDataProvider({required this.initialGalleryFilter});
- /// [recommendations] are sorted by decreasing order of relevance
+ // Ordered from most to least relevant.
List<HierarchicalSearchFilter> get recommendations =>
_recommendedFiltersNotifier.recommendedFilters;
List<HierarchicalSearchFilter> get appliedFilters =>
@@ -110,10 +108,6 @@ class SearchFilterDataProvider {
);
}
- /// [InheritedSearchFilterDataWrapper] calls this method in its [dispose] so
- /// if [InheritedSearchFilterDataWrapper] is an ancestor on the widget where
- /// [SearchFilterDataProvider] is used, it's not necessary to call this method
- /// explicitly
void dispose() {
_appliedFiltersNotifier.dispose();
_recommendedFiltersNotifier.dispose();
@@ -149,9 +143,6 @@ class _RecommendedFiltersNotifier extends ChangeNotifier {
void addFilters(
List<HierarchicalSearchFilter> filters, {
-
- ///This is to ensure that the filters that are being added are not already
- ///already in recommendations or applied filters
required List<HierarchicalSearchFilter> filtersToAvoid,
}) {
for (HierarchicalSearchFilter filter in filters) {
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/selection_state.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/selection_state.dart
index 82615f7557..2a46e19680 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/selection_state.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/selection_state.dart
@@ -2,8 +2,7 @@ import "package:flutter/material.dart";
import "package:logging/logging.dart";
import "package:photos/models/selected_files.dart";
-///This is an inherited widget that needs to be wrapped around Gallery and
-///FileSelectionOverlayBar to make select all work.
+// Gallery and FileSelectionOverlayBar must share this ancestor for select-all.
// ignore: must_be_immutable
class SelectionState extends InheritedWidget {
final SelectedFiles selectedFiles;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/swipe_selection_wrapper.dart b/mobile/apps/photos/lib/ui/viewer/gallery/swipe_selection_wrapper.dart
index e24aff9664..ad0851e168 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/swipe_selection_wrapper.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/swipe_selection_wrapper.dart
@@ -9,8 +9,6 @@ import 'package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart'
import 'package:photos/ui/viewer/gallery/state/gallery_swipe_helper.dart';
import 'package:photos/ui/viewer/gallery/swipe_to_select_helper.dart';
-/// A wrapper widget that handles swipe-to-select gesture detection and state management
-/// for the Gallery widget.
class SwipeSelectionWrapper extends StatefulWidget {
final Widget child;
final SwipeToSelectHelper? swipeHelper;
@@ -39,7 +37,6 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
bool _pointerDownForFirstSelection = false;
final _logger = Logger('SwipeSelectionWrapper');
- // Auto-scroll related fields
Ticker? _autoScrollTicker;
double _currentPointerY = 0;
double _currentPointerX = 0;
@@ -47,23 +44,18 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
double? _cachedScreenHeight;
double _accumulatedScrollDelta = 0;
- // Auto-scroll state tracking to avoid ticker recreation
- int? _currentScrollDirection; // -1 for up, 1 for down, null for not scrolling
+ int? _currentScrollDirection;
double _currentScrollSpeed = 0;
ScrollController? _activeScrollController;
Duration _lastElapsed = Duration.zero;
- // Frame rate adaptive fields
- late double _maxScrollSpeed; // Max scroll speed in pixels per second
+ late double _maxScrollSpeed;
- // Auto-scroll constants
- static const double _syntheticEventThreshold =
- 10.0; // Pixels before generating event
- static const double _minAvailableSpace =
- 30.0; // Minimum widget height for safety
+ static const double _syntheticEventThreshold = 10.0;
+ static const double _minAvailableSpace = 30.0;
static const double _baselineRefreshRate = 120.0;
- static const double _baselineMaxScrollSpeed = 12.0; // 1440 px/s (12 * 120fps)
- static const double _speedExponent = 1.20; // Power curve exponent
+ static const double _baselineMaxScrollSpeed = 12.0; // px/frame at 120 Hz
+ static const double _speedExponent = 1.20;
static const double _movementThreshold = 4.0;
@override
@@ -73,17 +65,12 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
}
void _initializeFrameRateConstants() {
- // Convert baseline speed from "px/frame at 120fps" to "px/second"
- // This ensures consistent visual speed across all refresh rates
- // E.g., baseline 10 px/frame at 120fps = 1200 px/second
- // All devices (60fps, 90fps, 120fps) will scroll at this same visual speed
_maxScrollSpeed = _baselineMaxScrollSpeed * _baselineRefreshRate;
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
- // Update cached screen height when dependencies change (includes orientation changes)
final newHeight = MediaQuery.of(context).size.height;
if (_cachedScreenHeight != newHeight) {
_cachedScreenHeight = newHeight;
@@ -93,12 +80,10 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
@override
Widget build(BuildContext context) {
final boundariesProvider = GalleryBoundariesProvider.of(context);
- // If swipe selection is not enabled, just return the child without wrapper
if (!widget.isEnabled) {
return widget.child;
}
- // Wrap with GallerySwipeHelper and Listener for swipe detection
return GallerySwipeHelper(
helper: widget.swipeHelper,
swipeActiveNotifier: widget.swipeActiveNotifier,
@@ -107,10 +92,7 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
_currentPointerX = event.position.dx;
_currentPointerY = event.position.dy;
_activePointer = event.pointer;
- // Reset initial movement tracking for new gesture
_initialMovementWasHorizontal = null;
- // Track if pointer down happened when no files were selected
- // This indicates it's the initial selection gesture (long-press)
_pointerDownForFirstSelection =
widget.selectedFiles?.files.isEmpty ?? false;
},
@@ -118,50 +100,40 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
_currentPointerX = event.position.dx;
_currentPointerY = event.position.dy;
_activePointer = event.pointer;
- // Handle case where pointer is dragged after first selection in gallery
+ // A long press selects the first file before its drag starts.
if (widget.selectedFiles != null &&
widget.selectedFiles!.files.length == 1 &&
!widget.swipeActiveNotifier.value &&
_pointerDownForFirstSelection) {
- // Activate swipe mode for any significant movement when only one file is selected
- // This handles the case of long-press to select first file, then immediate swipe
- // including vertical movement without initial horizontal movement
- // Only applies if pointer down was for the initial selection (continuous gesture)
final dx = event.delta.dx.abs();
final dy = event.delta.dy.abs();
if (dx > _movementThreshold || dy > _movementThreshold) {
widget.swipeActiveNotifier.value = true;
}
}
- // Check for horizontal swipe if multiple files are selected and swipe is not already active
+ // Existing selections start swipe mode only from horizontal movement.
else if (!widget.swipeActiveNotifier.value &&
widget.selectedFiles != null &&
widget.selectedFiles!.files.isNotEmpty) {
- // Check if movement is primarily horizontal and if delta x is significant
final dx = event.delta.dx.abs();
final dy = event.delta.dy.abs();
- // Track initial movement direction if not yet determined
if (_initialMovementWasHorizontal == null &&
(dx > _movementThreshold || dy > _movementThreshold)) {
_initialMovementWasHorizontal = dx > dy;
}
- // Only activate swipe if initial movement was horizontal
if (_initialMovementWasHorizontal == true && dx > dy && dx > 0.1) {
- // Horizontal swipe detected, activate swipe mode
widget.swipeActiveNotifier.value = true;
}
}
- // Check for auto-scroll if swipe is active
if (widget.swipeActiveNotifier.value) {
_checkAndHandleAutoScroll(boundariesProvider);
}
},
onPointerUp: (_) {
_stopAutoScroll();
- // End swipe selection when pointer is released
widget.swipeHelper?.endSelection();
widget.swipeActiveNotifier.value = false;
_initialMovementWasHorizontal = null;
@@ -169,7 +141,6 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
},
onPointerCancel: (_) {
_stopAutoScroll();
- // Also end selection on cancel
widget.swipeHelper?.endSelection();
widget.swipeActiveNotifier.value = false;
_initialMovementWasHorizontal = null;
@@ -180,7 +151,6 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
);
}
- /// Calculate scroll speed based on widget penetration percentage with power curve
double _calculateScrollSpeed(
double distanceFromBoundary,
double boundaryPosition,
@@ -191,32 +161,22 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
final screenHeight =
_cachedScreenHeight ?? MediaQuery.of(context).size.height;
- // Calculate available space (widget height) from boundary to screen edge
final widgetHeight = scrollingUp
- ? boundaryPosition // Space from top boundary to screen top
- : (screenHeight -
- boundaryPosition); // Space from bottom boundary to screen bottom
+ ? boundaryPosition
+ : (screenHeight - boundaryPosition);
- // Apply safety floor and cap at 150px
- // Small widgets (< 150px): Speed ramps up over their full height
- // Large widgets (>= 150px): Speed maxes out at 150px from boundary
final safeWidgetHeight = math.max(
_minAvailableSpace,
math.min(150.0, widgetHeight),
);
- // Calculate penetration percentage (0.0 to 1.0)
- // Clamped to 1.0 to handle cases where pointer goes beyond widget bounds
final penetration = math.min(1.0, distanceFromBoundary / safeWidgetHeight);
- // Apply power curve for slightly exponential feel
- // speed = maxSpeed Γ— (penetration ^ exponent)
final speed = _maxScrollSpeed * math.pow(penetration, _speedExponent);
return speed;
}
- /// Check if pointer is inside/outside boundaries and start/stop auto-scroll
void _checkAndHandleAutoScroll(InheritedGalleryBoundaries? provider) {
if (provider == null) return;
@@ -226,7 +186,6 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
if (scrollController == null || !scrollController.hasClients) return;
- // Validate boundaries don't overlap (viewport too small)
if (topBoundary != null &&
bottomBoundary != null &&
topBoundary >= bottomBoundary) {
@@ -238,22 +197,17 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
return;
}
- // Determine if we need to scroll and in which direction
if (topBoundary != null && _currentPointerY < topBoundary) {
- // Pointer is above top boundary - scroll up
final distance = topBoundary - _currentPointerY;
_startAutoScroll(scrollController, -1, distance, topBoundary, true);
} else if (bottomBoundary != null && _currentPointerY > bottomBoundary) {
- // Pointer is below bottom boundary - scroll down
final distance = _currentPointerY - bottomBoundary;
_startAutoScroll(scrollController, 1, distance, bottomBoundary, false);
} else {
- // Pointer is within boundaries - stop scrolling
_stopAutoScroll();
}
}
- /// Start auto-scrolling in the specified direction
void _startAutoScroll(
ScrollController controller,
int direction,
@@ -267,66 +221,49 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
scrollingUp,
);
- // Check if we're already scrolling in the same direction
- // If yes, just update the speed without recreating the ticker
if (_autoScrollTicker != null &&
_currentScrollDirection == direction &&
_activeScrollController == controller) {
- // Just update the scroll speed, ticker continues running
_currentScrollSpeed = scrollSpeed;
return;
}
- // Direction changed or starting fresh - recreate ticker
_stopAutoScroll();
_currentScrollDirection = direction;
_currentScrollSpeed = scrollSpeed;
_activeScrollController = controller;
_lastElapsed = Duration.zero;
- // Create vsync-synchronized ticker for smooth scrolling
_autoScrollTicker = createTicker((elapsed) {
if (!mounted || !controller.hasClients) {
_stopAutoScroll();
return;
}
- // Calculate delta time since last frame
final deltaTime = elapsed - _lastElapsed;
_lastElapsed = elapsed;
- // Calculate scroll distance for this frame using delta-time
- // Convert microseconds to seconds for calculation
final deltaSeconds = deltaTime.inMicroseconds / 1000000.0;
- // Formula: pixels_per_second Γ— direction Γ— actual_frame_time_in_seconds
- // _currentScrollSpeed is in "pixels per second" (e.g., 4800 px/s for max speed)
- // Multiplying by deltaSeconds gives actual pixels to scroll this frame
- // Example at 60fps: 4800px/s Γ— 0.0166s β‰ˆ 80px per frame
- // Example at 120fps: 4800px/s Γ— 0.00833s β‰ˆ 40px per frame
- // Visual speed is the same: both scroll 4800 pixels per second
final scrollDelta =
_currentScrollSpeed * _currentScrollDirection! * deltaSeconds;
- // Calculate new scroll position
final currentOffset = controller.offset;
final newOffset = currentOffset + scrollDelta;
- // Clamp to scroll bounds
final clampedOffset = newOffset.clamp(
controller.position.minScrollExtent,
controller.position.maxScrollExtent,
);
- // Use jumpTo for immediate positioning
if (clampedOffset != currentOffset) {
final actualScrollDelta = (clampedOffset - currentOffset).abs();
controller.jumpTo(clampedOffset);
- // Accumulate scroll delta for synthetic event generation
_accumulatedScrollDelta += actualScrollDelta;
- // Generate synthetic pointer event when threshold is reached
+ // Scrolling does not move the pointer, so dispatch a move to extend
+ // selection.
if (_accumulatedScrollDelta >= _syntheticEventThreshold &&
widget.swipeActiveNotifier.value &&
_activePointer != null) {
@@ -336,17 +273,14 @@ class _SwipeSelectionWrapperState extends State<SwipeSelectionWrapper>
timeStamp: elapsed,
);
GestureBinding.instance.handlePointerEvent(syntheticEvent);
- // Reset accumulator after generating event
_accumulatedScrollDelta = 0;
}
}
});
- // Start the ticker
_autoScrollTicker!.start();
}
- /// Stop auto-scrolling
void _stopAutoScroll() {
_autoScrollTicker?.dispose();
_autoScrollTicker = null;
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 b62387e3ab..c19b67fe0a 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
@@ -4,13 +4,6 @@ import 'package:flutter/services.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/selected_files.dart';
-/// Helper class to manage swipe-to-select gesture logic.
-///
-/// This class implements an efficient range selection algorithm that:
-/// - Maintains a continuous selection from anchor to current position
-/// - Only modifies the delta between previous and current position
-/// - Supports bidirectional dragging
-/// - Has two modes: adding (from unselected) or removing (from selected)
class SwipeToSelectHelper {
final List<EnteFile> allFiles;
final SelectedFiles selectedFiles;
@@ -19,28 +12,22 @@ class SwipeToSelectHelper {
selectedFiles.addListener(_onSelectionChanged);
}
- int? _fromIndex; // Anchor point (where swipe started)
- int? _lastToIndex; // Previous position during drag
- bool? _selecting; // true = adding, false = removing
+ int? _fromIndex;
+ int? _lastToIndex;
+ bool? _selecting;
- /// Whether a swipe gesture is currently active
- /// Note: There is some edge case where this isn't perfectly accurate, so
- /// _swipeActiveNotifier was added to GallerySwipeHelper for more reliable
- /// tracking. Not removing this since this is still useful for some logic.
+ // isActive can be stale; use GallerySwipeHelper's notifier to track the
+ // pointer gesture.
bool get isActive => _fromIndex != null;
- /// Start a selection gesture at the given file
- /// [forceSelecting] - if true, forces adding mode regardless of file's current state
void startSelection(EnteFile file, {bool? forceSelecting}) {
final index = allFiles.indexOf(file);
if (index == -1) return;
_fromIndex = index;
_lastToIndex = index;
- // Use forced mode if provided, otherwise determine based on initial file's selection state
_selecting = forceSelecting ?? !selectedFiles.isFileSelected(file);
- // Immediately select/deselect the starting file based on mode
if (_selecting == true) {
selectedFiles.selectAll({file});
HapticFeedback.selectionClick();
@@ -50,7 +37,6 @@ class SwipeToSelectHelper {
}
}
- /// Update selection as the pointer moves to a new file
void updateSelection(EnteFile file) {
if (_fromIndex == null) return;
@@ -61,14 +47,12 @@ class SwipeToSelectHelper {
_lastToIndex = toIndex;
}
- /// End the selection gesture
void endSelection() {
_fromIndex = null;
_lastToIndex = null;
_selecting = null;
}
- /// Core algorithm that efficiently updates selection ranges
void _toggleSelectionToIndex(int toIndex) {
if (_fromIndex == null || _lastToIndex == null || _selecting == null) {
return;
@@ -78,7 +62,7 @@ class SwipeToSelectHelper {
final lastToIndex = _lastToIndex!;
final selecting = _selecting!;
- // Helper function to get range of files
+ // Reversing the drag undoes changes outside the new start-to-pointer range.
Set<EnteFile> getRange(int start, int end) {
if (start < end && start >= 0 && end <= allFiles.length) {
return allFiles.getRange(start, end).toSet();
@@ -87,17 +71,13 @@ class SwipeToSelectHelper {
}
if (selecting) {
- // Adding mode: maintain continuous selection from fromIndex to toIndex
if (toIndex <= fromIndex) {
- // Moving left of starting point
if (toIndex < lastToIndex) {
- // Extending leftward
final itemsToAdd = getRange(toIndex, min(fromIndex, lastToIndex));
if (itemsToAdd.isNotEmpty) {
selectedFiles.selectAll(itemsToAdd);
HapticFeedback.selectionClick();
}
- // Remove items to the right of start if we were previously there
if (fromIndex < lastToIndex) {
final itemsToRemove = getRange(fromIndex + 1, lastToIndex + 1);
if (itemsToRemove.isNotEmpty) {
@@ -106,7 +86,6 @@ class SwipeToSelectHelper {
}
}
} else if (lastToIndex < toIndex) {
- // Contracting from left
final itemsToRemove = getRange(lastToIndex, toIndex);
if (itemsToRemove.isNotEmpty) {
selectedFiles.unSelectAll(itemsToRemove);
@@ -114,15 +93,12 @@ class SwipeToSelectHelper {
}
}
} else if (fromIndex < toIndex) {
- // Moving right of starting point
if (lastToIndex < toIndex) {
- // Extending rightward
final itemsToAdd = getRange(max(fromIndex, lastToIndex), toIndex + 1);
if (itemsToAdd.isNotEmpty) {
selectedFiles.selectAll(itemsToAdd);
HapticFeedback.selectionClick();
}
- // Remove items to the left of start if we were previously there
if (lastToIndex < fromIndex) {
final itemsToRemove = getRange(lastToIndex, fromIndex);
if (itemsToRemove.isNotEmpty) {
@@ -131,7 +107,6 @@ class SwipeToSelectHelper {
}
}
} else if (toIndex < lastToIndex) {
- // Contracting from right
final itemsToRemove = getRange(toIndex + 1, lastToIndex + 1);
if (itemsToRemove.isNotEmpty) {
selectedFiles.unSelectAll(itemsToRemove);
@@ -140,17 +115,13 @@ class SwipeToSelectHelper {
}
}
} else {
- // Removing mode: maintain continuous unselection from fromIndex to toIndex
if (toIndex <= fromIndex) {
- // Moving left of starting point
if (toIndex < lastToIndex) {
- // Extending leftward
final itemsToRemove = getRange(toIndex, min(fromIndex, lastToIndex));
if (itemsToRemove.isNotEmpty) {
selectedFiles.unSelectAll(itemsToRemove);
HapticFeedback.selectionClick();
}
- // Add items back to the right of start if we were previously there
if (fromIndex < lastToIndex) {
final itemsToAdd = getRange(fromIndex + 1, lastToIndex + 1);
if (itemsToAdd.isNotEmpty) {
@@ -159,7 +130,6 @@ class SwipeToSelectHelper {
}
}
} else if (lastToIndex < toIndex) {
- // Contracting from left
final itemsToAdd = getRange(lastToIndex, toIndex);
if (itemsToAdd.isNotEmpty) {
selectedFiles.selectAll(itemsToAdd);
@@ -167,9 +137,7 @@ class SwipeToSelectHelper {
}
}
} else if (fromIndex < toIndex) {
- // Moving right of starting point
if (lastToIndex < toIndex) {
- // Extending rightward
final itemsToRemove = getRange(
max(fromIndex, lastToIndex),
toIndex + 1,
@@ -178,7 +146,6 @@ class SwipeToSelectHelper {
selectedFiles.unSelectAll(itemsToRemove);
HapticFeedback.selectionClick();
}
- // Add items back to the left of start if we were previously there
if (lastToIndex < fromIndex) {
final itemsToAdd = getRange(lastToIndex, fromIndex);
if (itemsToAdd.isNotEmpty) {
@@ -187,7 +154,6 @@ class SwipeToSelectHelper {
}
}
} else if (toIndex < lastToIndex) {
- // Contracting from right
final itemsToAdd = getRange(toIndex + 1, lastToIndex + 1);
if (itemsToAdd.isNotEmpty) {
selectedFiles.selectAll(itemsToAdd);
@@ -198,20 +164,16 @@ class SwipeToSelectHelper {
}
}
- /// Reset the helper (e.g., when gallery files change)
void reset() {
endSelection();
}
- /// Listener for selection changes
void _onSelectionChanged() {
- // Reset swipe state when all selections are cleared
if (selectedFiles.files.isEmpty && isActive) {
reset();
}
}
- /// Clean up resources
void dispose() {
selectedFiles.removeListener(_onSelectionChanged);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/uncategorized_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/uncategorized_page.dart
index e981ce9541..e996e308b2 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/uncategorized_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/uncategorized_page.dart
@@ -57,7 +57,6 @@ class UnCategorizedPage extends StatelessWidget {
limit: limit,
asc: asc,
);
- // hide ignored files from home page UI
final ignoredIDs =
await IgnoredFilesService.instance.idToIgnoreReasonMap;
result.files.removeWhere(