π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Cache album capture dates across selection
r4khul79a1f757baf0
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dartindex 9b3bcda232..516f5f32df 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart@@ -82,6 +82,7 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {@overridevoid didPopNext() {+ GalleryFilesState.maybeOf(context)?.invalidateCaptureDateRange();setState(() => _isCovered = false);}@@ -129,9 +130,7 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {content: Column(mainAxisSize: MainAxisSize.min,children: [- _CoverCaption(- GalleryFilesState.maybeOf(context)?.galleryFilesOrNull,- ),+ _CoverCaption(GalleryFilesState.maybeOf(context)?.captureDateRange),Semantics(header: true,child: Text(@@ -524,30 +523,18 @@ class _CoverDissolvePainter extends CustomPainter {}class _CoverCaption extends StatelessWidget {- const _CoverCaption(this.files);+ const _CoverCaption(this.dateRange);- final List<EnteFile>? files;+ final ({int oldest, int newest})? dateRange;@overrideWidget build(BuildContext context) {- final files = this.files;- if (files == null) {- return const SizedBox.shrink();- }- int? oldestFileTime;- int? newestFileTime;- for (final file in files) {- final creationTime = file.creationTime;- if (creationTime != null && creationTime != 0) {- oldestFileTime = math.min(oldestFileTime ?? creationTime, creationTime);- newestFileTime = math.max(newestFileTime ?? creationTime, creationTime);- }- }- if (oldestFileTime == null || newestFileTime == null) {+ final dateRange = this.dateRange;+ if (dateRange == null) {return const SizedBox.shrink();}- final start = DateTime.fromMicrosecondsSinceEpoch(oldestFileTime);- final end = DateTime.fromMicrosecondsSinceEpoch(newestFileTime);+ final start = DateTime.fromMicrosecondsSinceEpoch(dateRange.oldest);+ final end = DateTime.fromMicrosecondsSinceEpoch(dateRange.newest);final locale = Localizations.localeOf(context).toString();final dayPattern = locale == "en"? "d MMM y"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.dartindex 02758c2ed1..4bd4a0d608 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@@ -7,13 +7,36 @@ class GalleryFilesState extends InheritedWidget {// Keep the same file objects used by galleryGroups so mutations stay in sync.List<EnteFile>? _galleryFiles;+ ({int oldest, int newest})? _captureDateRange;+ bool _hasComputedDateRange = false;set setGalleryFiles(List<EnteFile> galleryFiles) {_galleryFiles = galleryFiles;+ invalidateCaptureDateRange();}void removeFile(EnteFile file) {_galleryFiles!.remove(file);+ invalidateCaptureDateRange();+ }++ void invalidateCaptureDateRange() => _hasComputedDateRange = false;++ ({int oldest, int newest})? get captureDateRange {+ if (_hasComputedDateRange) return _captureDateRange;+ int? oldest;+ int? newest;+ for (final file in _galleryFiles ?? const <EnteFile>[]) {+ final time = file.creationTime;+ if (time == null || time == 0) continue;+ if (oldest == null || time < oldest) oldest = time;+ if (newest == null || time > newest) newest = time;+ }+ _captureDateRange = oldest == null || newest == null+ ? null+ : (oldest: oldest, newest: newest);+ _hasComputedDateRange = true;+ return _captureDateRange;}List<EnteFile>? get galleryFilesOrNull => _galleryFiles;diff --git a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dartindex 733fded579..c9b254a715 100644--- a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart+++ b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart@@ -7,6 +7,7 @@ import "package:ente_strings/ente_strings.dart";import "package:figma_squircle/figma_squircle.dart";import "package:flutter/material.dart";import "package:flutter/services.dart";+import "package:flutter_secure_storage/flutter_secure_storage.dart";import "package:flutter_test/flutter_test.dart";import "package:package_info_plus/package_info_plus.dart";import "package:path_provider_platform_interface/path_provider_platform_interface.dart";@@ -23,10 +24,13 @@ import "package:photos/models/collection/collection.dart";import "package:photos/models/collection/collection_items.dart";import "package:photos/models/file/file.dart";import "package:photos/models/file/file_type.dart";+import "package:photos/models/gallery_type.dart";import "package:photos/models/ignored_file.dart";import "package:photos/models/metadata/collection_magic.dart";+import "package:photos/models/selected_files.dart";import "package:photos/module/download/thumbnail.dart";import "package:photos/service_locator.dart";+import "package:photos/services/app_navigation_service.dart";import "package:photos/services/collections_service.dart";import "package:photos/services/favorites_service.dart";import "package:photos/services/ignored_files_service.dart";@@ -50,11 +54,20 @@ void main() {tempDir = await Directory.systemTemp.createTemp("collection_page_cover_");previousPathProvider = PathProviderPlatform.instance;PathProviderPlatform.instance = _FakePathProvider(tempDir.path);- SharedPreferences.setMockInitialValues({});+ FlutterSecureStorage.setMockInitialValues({});+ SharedPreferences.setMockInitialValues({"remote_flags": "{}"});final preferences = await SharedPreferences.getInstance();+ final dio = Dio()+ ..interceptors.add(+ InterceptorsWrapper(+ onRequest: (options, handler) => handler.resolve(+ Response(requestOptions: options, data: <String, dynamic>{}),+ ),+ ),+ );ServiceLocator.instance.init(preferences,- Dio(),+ dio,Dio(),Dio(),PackageInfo(@@ -68,6 +81,8 @@ void main() {await Configuration.instance.init(preferences);} catch (_) {}await Configuration.instance.setUserID(1);+ await Configuration.instance.setKey(base64Encode(List.filled(32, 0)));+ await Configuration.instance.setToken("test-token");await CollectionsService.instance.init(preferences);await FavoritesService.instance.initFav();expect(flagService.internalUser, isTrue);@@ -260,6 +275,67 @@ void main() {},);+ testWidgets(+ "reuses capture dates across selection and refreshes date edits",+ (tester) async {+ final files = [_CountingFile(_file(1)), _CountingFile(_file(3))];+ final selectedFiles = SelectedFiles();+ final cover = _file(99);+ late StateSetter refresh;+ final galleryFiles = GalleryFilesState(+ child: StatefulBuilder(+ builder: (context, setState) {+ refresh = setState;+ final appBar = GalleryAppBarWidget.sliverConfig(+ GalleryType.ownedCollection,+ "Album",+ selectedFiles,+ collection: _collection(),+ cover: cover,+ );+ return Scaffold(+ body: CustomScrollView(slivers: [appBar.buildSliver(context)]),+ );+ },+ ),+ )..setGalleryFiles = files;+ await tester.pumpWidget(+ MaterialApp(+ theme: lightThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ navigatorObservers: [AppNavigationService.instance.routeObserver],+ home: galleryFiles,+ ),+ );+ await tester.pumpAndSettle();+ expect(find.text("1β3 JAN 2026"), findsOneWidget);+ final reads = files.map((file) => file.creationTimeReads).toList();+ for (final file in [files.first, files.last, files.first, files.last]) {+ selectedFiles.toggleSelection(file);+ await tester.pumpAndSettle();+ expect(files.map((file) => file.creationTimeReads), reads);+ }+ files.setAll(0, files.reversed.toList());+ files.last.creationTime = DateTime(2026, 1, 5).microsecondsSinceEpoch;+ galleryFiles.setGalleryFiles = files;+ refresh(() {});+ await tester.pumpAndSettle();+ expect(find.text("3β5 JAN 2026"), findsOneWidget);+ final navigator = tester.state<NavigatorState>(find.byType(Navigator));+ navigator+ .push(MaterialPageRoute<void>(builder: (_) => const Scaffold()))+ .ignore();+ await tester.pumpAndSettle();+ files.last.creationTime = DateTime(2026, 1, 7).microsecondsSinceEpoch;+ navigator.pop();+ await tester.pumpAndSettle();+ expect(find.text("3β7 JAN 2026"), findsOneWidget);+ await _disposeAlbum(tester);+ selectedFiles.dispose();+ },+ );+testWidgets("animates the thumbnail into the header through reversal and cover changes",(tester) async {@@ -486,6 +562,18 @@ Future<void> _disposeAlbum(WidgetTester tester) async {await tester.pump(const Duration(seconds: 1));}+class _CountingFile extends EnteFile {+ _CountingFile(super.file) : super.from();++ int creationTimeReads = 0;++ @override+ int? get creationTime {+ creationTimeReads++;+ return super.creationTime;+ }+}+class _FakePathProvider extends PathProviderPlatform {_FakePathProvider(this.path);