Skip to content

armgit / ente

Public Imported from GitHub
0

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

Resolve merge conflicts for cherry-picking jump to date wip

ashilkna8cc1ab4f0aa
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart b/mobile/apps/photos/lib/models/gallery/gallery_sections.dart
index 32ad4f03d8..c161935eb5 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_sections.dart
@@ -29,6 +29,7 @@ class GalleryGroups {
final bool sortOrderAsc;
final double widthAvailable;
final double groupHeaderExtent;
+ final EnteFile? fileToJumpScrollTo;
GalleryGroups({
required this.allFiles,
required this.groupType,
@@ -41,6 +42,7 @@ class GalleryGroups {
required this.groupHeaderExtent,
required this.showSelectAll,
this.limitSelectionToOne = false,
+ this.fileToJumpScrollTo,
}) {
init();
if (!groupType.showGroupHeader()) {
@@ -59,7 +61,9 @@ class GalleryGroups {
final List<String> _groupIds = [];
final Map<String, List<EnteFile>> _groupIdToFilesMap = {};
- final Map<String, GroupType> _groupIdToGroupDataMap = {};
+ final Map<String,
+ ({GroupType groupType, int startCreationTime, int endCreationTime})>
+ _groupIdToGroupDataMap = {};
final Map<double, String> _scrollOffsetToGroupIdMap = {};
final Map<String, double> _groupIdToScrollOffsetMap = {};
final List<double> _groupScrollOffsets = [];
@@ -69,7 +73,9 @@ class GalleryGroups {
List<String> get groupIDs => _groupIds;
Map<String, List<EnteFile>> get groupIDToFilesMap => _groupIdToFilesMap;
- Map<String, GroupType> get groupIdToGroupDataMap => _groupIdToGroupDataMap;
+ Map<String,
+ ({GroupType groupType, int startCreationTime, int endCreationTime})>
+ get groupIdToGroupDataMap => _groupIdToGroupDataMap;
Map<double, String> get scrollOffsetToGroupIdMap => _scrollOffsetToGroupIdMap;
Map<String, double> get groupIdToScrollOffsetMap => _groupIdToScrollOffsetMap;
List<FixedExtentSectionLayout> get groupLayouts => _groupLayouts;
@@ -77,10 +83,87 @@ class GalleryGroups {
List<({String groupID, String title})> get scrollbarDivisions =>
_scrollbarDivisions;
+ /// Scrolls the gallery to the group containing the specified file based on its creation time.
+ /// Uses binary search to efficiently find the appropriate group.
+ double? getOffsetOfFile(EnteFile file) {
+ final creationTime = file.creationTime;
+ if (creationTime == null) {
+ _logger.warning('Cannot scroll to file with null creation time');
+ return null;
+ }
+
+ final groupId = _findGroupForCreationTime(creationTime);
+ if (groupId == null) {
+ _logger.warning(
+ 'jumpToFile No group found for creation time: $creationTime',
+ );
+ return null;
+ }
+
+ final scrollOffset = _groupIdToScrollOffsetMap[groupId];
+ if (scrollOffset == null) {
+ _logger.warning('No scroll offset found for group: $groupId');
+ return null;
+ }
+
+ return scrollOffset;
+
+ // scrollController.animateTo(
+ // scrollOffset,
+ // duration: const Duration(milliseconds: 300),
+ // curve: Curves.easeOutExpo,
+ // );
+
+ // scrollController.jumpTo(
+ // scrollOffset,
+ // );
+ }
+
+ /// Uses binary search to find the group ID that contains the given creation time.
+ String? _findGroupForCreationTime(int creationTime) {
+ if (_groupIds.isEmpty) {
+ _logger.warning(
+ 'empty group IDs list, cannot find group for creation time: $creationTime',
+ );
+ return null;
+ }
+ int left = 0;
+ int right = _groupIds.length - 1;
+
+ while (left <= right) {
+ final mid = (left + right) ~/ 2;
+ final groupId = _groupIds[mid];
+ final groupData = _groupIdToGroupDataMap[groupId];
+
+ if (groupData == null) {
+ _logger.warning('No group data found for group: $groupId');
+ return null;
+ }
+
+ final startTime = groupData.startCreationTime;
+ final endTime = groupData.endCreationTime;
+
+ if (creationTime <= startTime && creationTime >= endTime) {
+ // Found the group containing this creation time
+ return groupId;
+ } else if (creationTime > startTime) {
+ right = mid - 1;
+ } else {
+ left = mid + 1;
+ }
+ }
+
+ _logger.warning(
+ '_findGroupForCreationTime No group found for creation time: $creationTime',
+ );
+ return null;
+ }
+
void init() {
crossAxisCount = localSettings.getPhotoGridSize();
_buildGroups();
_groupLayouts = _computeGroupLayouts();
+
assert(groupIDs.length == _groupIdToFilesMap.length);
assert(groupIDs.length == _groupIdToGroupDataMap.length);
assert(
@@ -129,6 +212,7 @@ class GalleryGroups {
if (showGroupHeader) {
return GroupHeaderWidget(
title: _groupIdToGroupDataMap[groupID]!
+ .groupType
.getTitle(context, groupIDToFilesMap[groupID]!.first),
gridSize: crossAxisCount,
filesInGroup: groupIDToFilesMap[groupID]!,
@@ -268,7 +352,11 @@ class GalleryGroups {
final uuid = _uuid.v1();
_groupIds.add(uuid);
_groupIdToFilesMap[uuid] = groupFiles;
- _groupIdToGroupDataMap[uuid] = groupType;
+ _groupIdToGroupDataMap[uuid] = (
+ groupType: groupType,
+ startCreationTime: groupFiles.first.creationTime!,
+ endCreationTime: groupFiles.last.creationTime!
+ );
// For scrollbar divisions
if (groupType.timeGrouping()) {
diff --git a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
index 0c9887fa39..016d590c10 100644
--- a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
@@ -9,6 +9,7 @@ import 'package:photos/events/files_updated_event.dart';
import 'package:photos/events/force_reload_home_gallery_event.dart';
import "package:photos/events/hide_shared_items_from_home_gallery_event.dart";
import 'package:photos/events/local_photos_updated_event.dart';
+import "package:photos/models/file/file.dart";
import 'package:photos/models/file_load_result.dart';
import 'package:photos/models/gallery_type.dart';
import 'package:photos/models/selected_files.dart';
@@ -16,6 +17,7 @@ import "package:photos/service_locator.dart";
import 'package:photos/services/collections_service.dart';
import "package:photos/services/filter/db_filters.dart";
import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart';
+import "package:photos/ui/viewer/gallery/component/group/type.dart";
import 'package:photos/ui/viewer/gallery/gallery.dart';
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
import "package:photos/ui/viewer/gallery/state/selection_state.dart";
@@ -25,11 +27,15 @@ class HomeGalleryWidget extends StatefulWidget {
final Widget? header;
final Widget? footer;
final SelectedFiles selectedFiles;
+ final GroupType? groupType;
+ final EnteFile? fileToJumpScrollTo;
const HomeGalleryWidget({
super.key,
this.header,
this.footer,
+ this.groupType,
+ this.fileToJumpScrollTo,
required this.selectedFiles,
});
@@ -129,6 +135,8 @@ class _HomeGalleryWidgetState extends State<HomeGalleryWidget> {
reloadDebounceTime: const Duration(seconds: 2),
reloadDebounceExecutionInterval: const Duration(seconds: 5),
galleryType: GalleryType.homepage,
+ groupType: widget.groupType,
+ fileToJumpScrollTo: widget.fileToJumpScrollTo,
);
return GalleryFilesState(
child: SelectionState(
diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
index 0fa74931a8..b1f4b82105 100644
--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
@@ -21,6 +21,7 @@ import "package:photos/ui/home/memories/memory_progress_indicator.dart";
import "package:photos/ui/viewer/file/file_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/ui/viewer/file_details/favorite_widget.dart";
+import "package:photos/ui/viewer/gallery/jump_to_date_gallery.dart";
import "package:photos/utils/file_util.dart";
import "package:photos/utils/share_util.dart";
@@ -351,19 +352,27 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
Row(
children: [
child!,
- Text(
- SmartMemoriesService.getDateFormatted(
- creationTime: inheritedData
- .memories[value].file.creationTime!,
- context: context,
+ GestureDetector(
+ onTap: () {
+ JumpToDateGallery.jumpToDate(
+ inheritedData.memories[value].file,
+ context,
+ );
+ },
+ child: Text(
+ SmartMemoriesService.getDateFormatted(
+ creationTime: inheritedData
+ .memories[value].file.creationTime!,
+ context: context,
+ ),
+ style: Theme.of(context)
+ .textTheme
+ .titleMedium!
+ .copyWith(
+ fontSize: 14,
+ color: Colors.white,
+ ),
),
- style: Theme.of(context)
- .textTheme
- .titleMedium!
- .copyWith(
- fontSize: 14,
- color: Colors.white,
- ),
),
],
),
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index eb61106173..d4f695a771 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -81,6 +81,7 @@ class Gallery extends StatefulWidget {
final GroupType? groupType;
final bool disablePinnedGroupHeader;
final bool disableVerticalPaddingForScrollbar;
+ final EnteFile? fileToJumpScrollTo;
const Gallery({
required this.asyncLoader,
@@ -108,6 +109,7 @@ class Gallery extends StatefulWidget {
this.disablePinnedGroupHeader = false,
this.galleryType,
this.disableVerticalPaddingForScrollbar = false,
+ this.fileToJumpScrollTo,
super.key,
});
@@ -130,7 +132,7 @@ class GalleryState extends State<Gallery> {
late String _logTag;
bool _sortOrderAsc = false;
List<EnteFile> _allGalleryFiles = [];
- final _scrollController = ScrollController();
+ ScrollController? _scrollController;
final _headerKey = GlobalKey();
final _headerHeightNotifier = ValueNotifier<double?>(null);
final miscUtil = MiscUtil();
@@ -196,8 +198,8 @@ class GalleryState extends State<Gallery> {
Bus.instance.on<TabDoubleTapEvent>().listen((event) async {
// todo: Assign ID to Gallery and fire generic event with ID &
// target index/date
- if (mounted && event.selectedIndex == 0) {
- await _scrollController.animateTo(
+ if (mounted && event.selectedIndex == 0 && _scrollController != null) {
+ await _scrollController!.animateTo(
0,
duration: const Duration(milliseconds: 250),
curve: Curves.easeOutExpo,
@@ -224,14 +226,14 @@ class GalleryState extends State<Gallery> {
_onFilesLoaded(widget.initialFiles!);
}
+ // First load
_loadFiles(limit: kInitialLoadLimit).then((result) async {
_setFilesAndReload(result.files);
- // if hasmore, let load complete and then set scrollcontroller
- // else set scrollcontroller.
if (result.hasMore) {
- final result = await _loadFiles();
- _setFilesAndReload(result.files);
+ await _loadFiles();
}
+ _setScrollController(allFilesLoaded: !result.hasMore);
+ setState(() {});
});
if (_groupType.showGroupHeader()) {
@@ -306,6 +308,22 @@ 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 =
+ ScrollController(initialScrollOffset: fileOffset ?? 0);
+ } else {
+ _scrollController = ScrollController();
+ }
+ }
+
void _selectedFilesListener() {
final bottomInset = MediaQuery.paddingOf(context).bottom;
final extra = widget.galleryType == GalleryType.homepage ? 76.0 : 0.0;
@@ -470,7 +488,7 @@ class GalleryState extends State<Gallery> {
subscription.cancel();
}
_debouncer.cancelDebounceTimer();
- _scrollController.dispose();
+ _scrollController?.dispose();
scrollBarInUseNotifier.dispose();
_headerHeightNotifier.dispose();
widget.selectedFiles?.removeListener(_selectedFilesListener);
@@ -560,72 +578,75 @@ class GalleryState extends State<Gallery> {
widget.footer ?? const SizedBox.shrink(),
],
)
- : CustomScrollBar(
- scrollController: _scrollController,
- galleryGroups: galleryGroups,
- inUseNotifier: scrollBarInUseNotifier,
- heighOfViewport: MediaQuery.sizeOf(context).height,
- topPadding: widget.disableVerticalPaddingForScrollbar
- ? 0.0
- : groupHeaderExtent!,
- bottomPadding: widget.disableVerticalPaddingForScrollbar
- ? ValueNotifier(0.0)
- : scrollbarBottomPaddingNotifier,
- child: NotificationListener<SizeChangedLayoutNotification>(
- onNotification: (notification) {
- final renderBox = _headerKey.currentContext
- ?.findRenderObject() as RenderBox?;
- if (renderBox != null) {
- _headerHeightNotifier.value = renderBox.size.height;
- } else {
- _logger.info(
- "Header render box is null, cannot get height",
- );
- }
-
- return true;
- },
- child: Stack(
- clipBehavior: Clip.none,
- children: [
- CustomScrollView(
- physics: widget.disableScroll
- ? const NeverScrollableScrollPhysics()
- : const ExponentialBouncingScrollPhysics(),
- controller: _scrollController,
- slivers: [
- SliverToBoxAdapter(
- child: SizeChangedLayoutNotifier(
- child: SizedBox(
- key: _headerKey,
- child: widget.header ?? const SizedBox.shrink(),
+ : _scrollController != null
+ ? CustomScrollBar(
+ scrollController: _scrollController!,
+ galleryGroups: galleryGroups,
+ inUseNotifier: scrollBarInUseNotifier,
+ heighOfViewport: MediaQuery.sizeOf(context).height,
+ topPadding: widget.disableVerticalPaddingForScrollbar
+ ? 0.0
+ : groupHeaderExtent!,
+ bottomPadding: widget.disableVerticalPaddingForScrollbar
+ ? ValueNotifier(0.0)
+ : scrollbarBottomPaddingNotifier,
+ child: NotificationListener<SizeChangedLayoutNotification>(
+ onNotification: (notification) {
+ final renderBox = _headerKey.currentContext
+ ?.findRenderObject() as RenderBox?;
+ if (renderBox != null) {
+ _headerHeightNotifier.value = renderBox.size.height;
+ } else {
+ _logger.info(
+ "Header render box is null, cannot get height",
+ );
+ }
+
+ return true;
+ },
+ child: Stack(
+ clipBehavior: Clip.none,
+ children: [
+ CustomScrollView(
+ physics: widget.disableScroll
+ ? const NeverScrollableScrollPhysics()
+ : const ExponentialBouncingScrollPhysics(),
+ controller: _scrollController,
+ slivers: [
+ SliverToBoxAdapter(
+ child: SizeChangedLayoutNotifier(
+ child: SizedBox(
+ key: _headerKey,
+ child:
+ widget.header ?? const SizedBox.shrink(),
+ ),
+ ),
),
- ),
- ),
- SectionedListSliver(
- sectionLayouts: galleryGroups.groupLayouts,
- ),
- SliverToBoxAdapter(
- child: widget.footer,
+ SectionedListSliver(
+ sectionLayouts: galleryGroups.groupLayouts,
+ ),
+ SliverToBoxAdapter(
+ child: widget.footer,
+ ),
+ ],
),
+ galleryGroups.groupType.showGroupHeader() &&
+ !widget.disablePinnedGroupHeader
+ ? PinnedGroupHeader(
+ scrollController: _scrollController!,
+ galleryGroups: galleryGroups,
+ headerHeightNotifier: _headerHeightNotifier,
+ selectedFiles: widget.selectedFiles,
+ showSelectAll: widget.showSelectAll &&
+ !widget.limitSelectionToOne,
+ scrollbarInUseNotifier: scrollBarInUseNotifier,
+ )
+ : const SizedBox.shrink(),
],
),
- galleryGroups.groupType.showGroupHeader() &&
- !widget.disablePinnedGroupHeader
- ? PinnedGroupHeader(
- scrollController: _scrollController,
- galleryGroups: galleryGroups,
- headerHeightNotifier: _headerHeightNotifier,
- selectedFiles: widget.selectedFiles,
- showSelectAll: widget.showSelectAll &&
- !widget.limitSelectionToOne,
- scrollbarInUseNotifier: scrollBarInUseNotifier,
- )
- : const SizedBox.shrink(),
- ],
- ),
- ),
- ),
+ ),
+ )
+ : const SizedBox.shrink(),
);
}
@@ -865,8 +886,8 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader> {
child: ColoredBox(
color: getEnteColorScheme(context).backgroundBase,
child: GroupHeaderWidget(
- title: widget
- .galleryGroups.groupIdToGroupDataMap[currentGroupId!]!
+ title: widget.galleryGroups
+ .groupIdToGroupDataMap[currentGroupId!]!.groupType
.getTitle(
context,
widget.galleryGroups.groupIDToFilesMap[currentGroupId]!
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
new file mode 100644
index 0000000000..c8478d1303
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/jump_to_date_gallery.dart
@@ -0,0 +1,30 @@
+import "package:flutter/material.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/selected_files.dart";
+import "package:photos/ui/home/home_gallery_widget.dart";
+import "package:photos/ui/viewer/gallery/component/group/type.dart";
+import "package:photos/utils/navigation_util.dart";
+
+class JumpToDateGallery extends StatelessWidget {
+ final EnteFile file;
+ const JumpToDateGallery({super.key, required this.file});
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: SafeArea(
+ bottom: false,
+ child: HomeGalleryWidget(
+ selectedFiles: SelectedFiles(),
+ groupType: GroupType.day,
+ fileToJumpScrollTo: file,
+ ),
+ ),
+ appBar: AppBar(),
+ );
+ }
+
+ static jumpToDate(EnteFile file, BuildContext context) {
+ routeToPage(context, JumpToDateGallery(file: file));
+ }
+}