π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add jump to date feature (WIP)
ashilknbdb55670036b
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dartindex dc8566444f..29fe965964 100644--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart@@ -31,7 +31,6 @@ class GalleryGroups {final bool sortOrderAsc;final double widthAvailable;final double groupHeaderExtent;- final EnteFile? fileToJumpScrollTo;GalleryGroups({required this.allFiles,required this.groupType,@@ -44,7 +43,6 @@ class GalleryGroups {required this.groupHeaderExtent,required this.showSelectAll,this.limitSelectionToOne = false,- this.fileToJumpScrollTo,this.showGallerySettingsCTA = false,}) {init();diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dartindex dfd08ef53e..b6e4d7f96f 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart@@ -28,10 +28,12 @@ import "package:photos/ui/common/popup_item.dart";import 'package:photos/ui/notification/toast.dart';import "package:photos/ui/viewer/file_details/favorite_widget.dart";import "package:photos/ui/viewer/file_details/upload_icon_widget.dart";+import 'package:photos/ui/viewer/gallery/jump_to_date_gallery.dart';import 'package:photos/utils/dialog_util.dart';import "package:photos/utils/file_download_util.dart";import 'package:photos/utils/file_util.dart';import "package:photos/utils/magic_util.dart";+import 'package:photos/utils/navigation_util.dart';class FileAppBar extends StatefulWidget {final EnteFile file;@@ -230,6 +232,14 @@ class FileAppBarState extends State<FileAppBar> {iconColor: Theme.of(context).iconTheme.color,),);+ items.add(+ EntePopupMenuItem(+ "Jump to Date",+ value: 11,+ icon: Icons.calendar_today,+ iconColor: Theme.of(context).iconTheme.color,+ ),+ );}if ((widget.file.fileType == FileType.image ||widget.file.fileType == FileType.livePhoto) &&@@ -374,6 +384,11 @@ class FileAppBarState extends State<FileAppBar> {await _handleVideoStream('recreate');} else if (value == 10) {await _handleAddToAlbum();+ } else if (value == 11) {+ await routeToPage(+ context,+ JumpToDateGallery(fileToJumpTo: widget.file),+ );}},),diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex e0d338104b..c7ad952267 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -91,6 +91,10 @@ class Gallery extends StatefulWidget {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({required this.asyncLoader,required this.tagPrefix,@@ -119,6 +123,7 @@ class Gallery extends StatefulWidget {this.galleryType,this.disableVerticalPaddingForScrollbar = false,this.showGallerySettingsCTA = false,+ this.fileToJumpTo,super.key,});@@ -135,6 +140,8 @@ class GalleryState extends State<Gallery> {late Logger _logger;bool _hasLoadedFiles = false;+ bool _allFilesLoaded = false;+ bool _completedJumpToDate = false;StreamSubscription<FilesUpdatedEvent>? _reloadEventSubscription;StreamSubscription<TabDoubleTapEvent>? _tabDoubleTapEvent;final _forceReloadEventSubscriptions = <StreamSubscription<Event>>[];@@ -242,12 +249,11 @@ class GalleryState extends State<Gallery> {_loadFiles(limit: kInitialLoadLimit).then((result) async {_setFilesAndReload(result.files);if (result.hasMore) {- // _setScrollController(allFilesLoaded: false);final result = await _loadFiles();_setFilesAndReload(result.files);- // _setScrollController(allFilesLoaded: true);+ _allFilesLoaded = true;} else {- // _setScrollController(allFilesLoaded: true);+ _allFilesLoaded = true;}});@@ -565,6 +571,30 @@ class GalleryState extends State<Gallery> {}});+ // Jump to date logic+ if (widget.fileToJumpTo != null &&+ !_completedJumpToDate &&+ _allFilesLoaded &&+ groupHeaderExtent != null) {+ WidgetsBinding.instance.addPostFrameCallback((_) {+ if (mounted) {+ final offset = galleryGroups+ .getOffsetOfGroupContainingFile(widget.fileToJumpTo!);+ if (offset != null) {+ _logger.info("Jumping to date at offset: $offset");+ _scrollController.jumpTo(offset);+ setState(() {+ _completedJumpToDate = true;+ });+ } else {+ _logger.warning(+ "Could not find offset for file to jump to: ${widget.fileToJumpTo!.tag}",+ );+ }+ }+ });+ }+final widthAvailable = MediaQuery.sizeOf(context).width;final shouldEnableSwipeSelection = widget.limitSelectionToOne == false;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.dartnew file mode 100644index 0000000000..5bf82e3995--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/gallery/jump_to_date_gallery.dart@@ -0,0 +1,143 @@+import "dart:async";++import 'package:flutter/material.dart';+import 'package:photos/core/event_bus.dart';+import 'package:photos/events/files_updated_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';+import 'package:photos/services/search_service.dart';+import 'package:photos/ui/common/loading_widget.dart';+import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart';+import 'package:photos/ui/viewer/gallery/gallery.dart';+import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';+import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";+import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";+import "package:photos/ui/viewer/gallery/state/selection_state.dart";++class JumpToDateGallery extends StatefulWidget {+ final EnteFile fileToJumpTo;+ final String tagPrefix;++ static const GalleryType appBarType = GalleryType.searchResults;+ static const GalleryType overlayType = GalleryType.searchResults;++ const JumpToDateGallery({+ required this.fileToJumpTo,+ this.tagPrefix = "jump_to_date",+ super.key,+ });++ @override+ State<JumpToDateGallery> createState() => _JumpToDateGalleryState();+}++class _JumpToDateGalleryState extends State<JumpToDateGallery> {+ final _selectedFiles = SelectedFiles();+ late final List<EnteFile> files;+ late final StreamSubscription<LocalPhotosUpdatedEvent> _filesUpdatedEvent;+ bool _isLoadingFiles = true;++ @override+ void initState() {+ super.initState();+ files = [];+ _filesUpdatedEvent =+ Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {+ if (event.type == EventType.deletedFromDevice ||+ event.type == EventType.deletedFromEverywhere ||+ event.type == EventType.deletedFromRemote ||+ event.type == EventType.hide) {+ for (var updatedFile in event.updatedFiles) {+ files.remove(updatedFile);+ }+ setState(() {});+ }+ });++ // Load files asynchronously+ _loadFiles();+ }++ Future<void> _loadFiles() async {+ final allFiles =+ await SearchService.instance.getAllFilesForHierarchicalSearch();+ setState(() {+ files.clear();+ files.addAll(allFiles);+ _isLoadingFiles = false;+ });+ }++ @override+ void dispose() {+ _filesUpdatedEvent.cancel();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ return GalleryBoundariesProvider(+ child: GalleryFilesState(+ child: Scaffold(+ appBar: PreferredSize(+ preferredSize: const Size.fromHeight(90.0),+ child: GalleryAppBarWidget(+ JumpToDateGallery.appBarType,+ "Jump to Date",+ _selectedFiles,+ ),+ ),+ body: _isLoadingFiles+ ? const EnteLoadingWidget()+ : SelectionState(+ selectedFiles: _selectedFiles,+ child: Stack(+ alignment: Alignment.bottomCenter,+ children: [+ Gallery(+ asyncLoader: (+ creationStartTime,+ creationEndTime, {+ limit,+ asc,+ }) {+ final result = files+ .where(+ (file) =>+ file.creationTime! >= creationStartTime &&+ file.creationTime! <= creationEndTime,+ )+ .toList();+ return Future.value(+ FileLoadResult(+ result,+ result.length < files.length,+ ),+ );+ },+ reloadEvent: Bus.instance.on<LocalPhotosUpdatedEvent>(),+ removalEventTypes: const {+ EventType.deletedFromRemote,+ EventType.deletedFromEverywhere,+ EventType.hide,+ },+ tagPrefix: widget.tagPrefix,+ selectedFiles: _selectedFiles,+ enableFileGrouping: true,+ fileToJumpTo: widget.fileToJumpTo,+ ),+ FileSelectionOverlayBar(+ JumpToDateGallery.overlayType,+ _selectedFiles,+ ),+ ],+ ),+ ),+ ),+ ),+ );+ }+}