Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Preserve album cover Heroes when thumbnails refresh

r4khul4c43e465f581
diff --git a/mobile/apps/photos/lib/ui/collections/album/row_item.dart b/mobile/apps/photos/lib/ui/collections/album/row_item.dart
index 15e27b96a8..e19585b70b 100644
--- a/mobile/apps/photos/lib/ui/collections/album/row_item.dart
+++ b/mobile/apps/photos/lib/ui/collections/album/row_item.dart
@@ -116,15 +116,14 @@ class AlbumRowItemWidget extends StatelessWidget {
externalSelection ??
selectedAlbums?.isAlbumSelected(c) ??
false;
- final String heroTag = tagPrefix + thumbnail.tag;
final thumbnailWidget = ThumbnailWidget(
thumbnail,
shouldShowFavoriteIcon: false,
shouldShowSyncStatus: false,
- key: Key(heroTag),
+ key: Key(tagPrefix + thumbnail.tag),
);
return Hero(
- tag: heroTag,
+ tag: tagPrefix,
transitionOnUserGestures: true,
child: ClipSmoothRect(
radius: SmoothBorderRadius(
@@ -341,6 +340,7 @@ class AlbumRowItemWidget extends StatelessWidget {
CollectionPage(
CollectionWithThumbnail(c, thumbnail),
tagPrefix: tagPrefix,
+ coverHeroTag: tagPrefix,
hasVerifiedLock: hasVerifiedLock,
),
forceCustomPageRoute: true,
diff --git a/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart b/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart
index 399b29c7dc..e00d5268d6 100644
--- a/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart
+++ b/mobile/apps/photos/lib/ui/collections/flex_grid_view.dart
@@ -179,6 +179,7 @@ class _CollectionsFlexiGridViewWidgetState
context,
CollectionPage(
tagPrefix: tagPrefix,
+ coverHeroTag: tagPrefix,
CollectionWithThumbnail(c, thumbnail),
hasVerifiedLock: hasVerifiedLock,
),
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 61be1bbeb7..e57c359fcd 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
@@ -37,12 +37,14 @@ import "package:photos/utils/magic_util.dart";
class CollectionPage extends StatefulWidget {
final CollectionWithThumbnail c;
final String tagPrefix;
+ final String? coverHeroTag;
final bool? hasVerifiedLock;
final EnteFile? fileToJumpTo;
const CollectionPage(
this.c, {
this.tagPrefix = "collection",
+ this.coverHeroTag,
this.hasVerifiedLock = false,
this.fileToJumpTo,
super.key,
@@ -79,7 +81,9 @@ class _CollectionPageState extends State<CollectionPage> {
widget.c.thumbnail ??
CollectionsService.instance.getCoverCache(collection);
_defaultCover = _cover;
- _coverHeroTag = _cover == null ? null : widget.tagPrefix + _cover!.tag;
+ _coverHeroTag =
+ widget.coverHeroTag ??
+ (_cover == null ? null : widget.tagPrefix + _cover!.tag);
if (collection.hasCover) {
unawaited(_loadCover());
}
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.dart
index 49113e1b16..217cba5505 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
@@ -5,6 +5,7 @@ import "package:dio/dio.dart";
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_test/flutter_test.dart";
import "package:package_info_plus/package_info_plus.dart";
import "package:path_provider_platform_interface/path_provider_platform_interface.dart";
@@ -71,8 +72,15 @@ void main() {
});
setUp(() async {
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(
+ const MethodChannel("dev.fluttercommunity.plus/connectivity_status"),
+ (_) async => null,
+ );
await FilesDB.instance.clearTable();
await IgnoredFilesService.instance.reset();
+ Bus.instance.fire(CollectionUpdatedEvent(1, [], "test_reset"));
+ await Future<void>.delayed(Duration.zero);
});
tearDownAll(() async {
@@ -213,144 +221,149 @@ void main() {
},
);
- for (final platform in [TargetPlatform.iOS, TargetPlatform.android]) {
- testWidgets(
- "animates the album thumbnail into the header on ${platform.name}",
- (tester) async {
- final collection = _collection();
- final oldest = _file(1);
- final newest = _file(2);
- ThumbnailInMemoryLruCache.clearCache(newest);
- ThumbnailInMemoryLruCache.put(
+ testWidgets(
+ "animates the thumbnail into the header through reversal and cover changes",
+ (tester) async {
+ late StateSetter refreshAlbums;
+ final collection = _collection();
+ final oldest = _file(1);
+ final newest = _file(2);
+ ThumbnailInMemoryLruCache.clearCache(newest);
+ ThumbnailInMemoryLruCache.put(
+ newest,
+ base64Decode(_onePixelPng),
+ thumbnailSmallSize,
+ );
+ await tester.runAsync(() async {
+ await FilesDB.instance.insertMultiple([oldest, newest]);
+ expect(await CollectionsService.instance.getCover(collection), newest);
+ await cachedThumbnailPath(
newest,
- base64Decode(_onePixelPng),
- thumbnailSmallSize,
- );
- await tester.runAsync(() async {
- await FilesDB.instance.insertMultiple([oldest, newest]);
- expect(
- await CollectionsService.instance.getCover(collection),
- newest,
- );
- await cachedThumbnailPath(
- newest,
- ).writeAsBytes(base64Decode(_onePixelPng));
- });
- await tester.pumpWidget(
- MaterialApp(
- theme: lightThemeData.copyWith(platform: platform),
- localizationsDelegates: StringsLocalizations.localizationsDelegates,
- supportedLocales: StringsLocalizations.supportedLocales,
- home: Scaffold(
- body: Align(
- alignment: Alignment.topLeft,
- child: AlbumRowItemWidget(collection, 100),
- ),
- ),
+ ).writeAsBytes(base64Decode(_onePixelPng));
+ });
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData.copyWith(platform: TargetPlatform.iOS),
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: StatefulBuilder(
+ builder: (context, setState) {
+ refreshAlbums = setState;
+ return Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: AlbumRowItemWidget(collection, 100),
+ ),
+ );
+ },
),
- );
- await tester.pumpAndSettle();
- final heroTag = "collection_1${newest.tag}";
- expect(
- tester.widgetList<Hero>(find.byType(Hero)).map((hero) => hero.tag),
- contains(heroTag),
- );
+ ),
+ );
+ await tester.pumpAndSettle();
+ const heroTag = "collection_1";
+ expect(
+ tester.widgetList<Hero>(find.byType(Hero)).map((hero) => hero.tag),
+ contains(heroTag),
+ );
- await tester.tap(
- find.byWidgetPredicate(
- (widget) => widget is Hero && widget.tag == heroTag,
- ),
- );
- await tester.pump();
- await tester.pump(const Duration(milliseconds: 75));
- final route = ModalRoute.of(
- tester.element(find.byType(CollectionPage)),
- )!;
- expect(route, isA<PageRouteBuilder>());
- expect(route.transitionDuration, const Duration(milliseconds: 200));
- expect(
- route.reverseTransitionDuration,
- const Duration(milliseconds: 300),
- );
- final pageFade = find
- .ancestor(
- of: find.byType(CollectionPage),
- matching: find.byType(FadeTransition),
- )
- .first;
- final opacity = tester.widget<FadeTransition>(pageFade).opacity.value;
- expect(opacity, inExclusiveRange(0, 1));
- final flightClip = find.ancestor(
- of: find.byType(RawImage),
- matching: find.byType(ClipSmoothRect),
- );
- final radius = tester
- .widget<ClipSmoothRect>(flightClip)
- .radius
- .topLeft
- .x;
- expect(radius, inExclusiveRange(0, 20));
- Navigator.of(tester.element(find.byType(CollectionPage))).pop();
- await tester.pump();
- await tester.pump(const Duration(milliseconds: 30));
- expect(
- tester.widget<FadeTransition>(pageFade).opacity.value,
- lessThan(opacity),
- );
- expect(
- tester.widget<ClipSmoothRect>(flightClip).radius.topLeft.x,
- greaterThan(radius),
- );
- await tester.pumpAndSettle();
- expect(tester.takeException(), isNull);
- await tester.tap(
- find.byWidgetPredicate(
- (widget) => widget is Hero && widget.tag == heroTag,
- ),
- );
- await tester.pumpAndSettle();
- await _expectCover(tester, newest, count: 2);
- expect(
- find.descendant(
- of: find.byType(AlbumCoverAppBar),
- matching: find.byType(Image),
- ),
- findsOneWidget,
- );
- final headerHero = find.descendant(
+ await tester.tap(
+ find.byWidgetPredicate(
+ (widget) => widget is Hero && widget.tag == heroTag,
+ ),
+ );
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 75));
+ final route = ModalRoute.of(tester.element(find.byType(CollectionPage)))!;
+ expect(route, isA<PageRouteBuilder>());
+ final pageFade = find
+ .ancestor(
+ of: find.byType(CollectionPage),
+ matching: find.byType(FadeTransition),
+ )
+ .first;
+ final opacity = tester.widget<FadeTransition>(pageFade).opacity.value;
+ expect(opacity, inExclusiveRange(0, 1));
+ final flightClip = find.ancestor(
+ of: find.byType(RawImage),
+ matching: find.byType(ClipSmoothRect),
+ );
+ final radius = tester.widget<ClipSmoothRect>(flightClip).radius.topLeft.x;
+ expect(radius, inExclusiveRange(0, 20));
+ Navigator.of(tester.element(find.byType(CollectionPage))).pop();
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 30));
+ expect(
+ tester.widget<FadeTransition>(pageFade).opacity.value,
+ lessThan(opacity),
+ );
+ expect(
+ tester.widget<ClipSmoothRect>(flightClip).radius.topLeft.x,
+ greaterThan(radius),
+ );
+ await tester.pumpAndSettle();
+ expect(tester.takeException(), isNull);
+ await tester.tap(
+ find.byWidgetPredicate(
+ (widget) => widget is Hero && widget.tag == heroTag,
+ ),
+ );
+ await tester.pumpAndSettle();
+ await _expectCover(tester, newest, count: 2);
+ expect(
+ find.descendant(
of: find.byType(AlbumCoverAppBar),
- matching: find.byType(Hero),
- );
- expect(tester.widget<Hero>(headerHero).tag, heroTag);
- final tags = tester
- .widgetList<Hero>(
- find.descendant(
- of: find.byType(CollectionPage),
- matching: find.byType(Hero),
- ),
- )
- .map((hero) => hero.tag)
- .toList();
- expect(tags.toSet().length, tags.length);
+ matching: find.byType(Image),
+ ),
+ findsOneWidget,
+ );
+ final headerHero = find.descendant(
+ of: find.byType(AlbumCoverAppBar),
+ matching: find.byType(Hero),
+ );
+ expect(tester.widget<Hero>(headerHero).tag, heroTag);
+ final tags = tester
+ .widgetList<Hero>(
+ find.descendant(
+ of: find.byType(CollectionPage),
+ matching: find.byType(Hero),
+ ),
+ )
+ .map((hero) => hero.tag)
+ .toList();
+ expect(tags.toSet().length, tags.length);
- collection.pubMagicMetadata = CollectionPubMagicMetadata(asc: true);
- Bus.instance.fire(
- CollectionMetaEvent(
- collection.id,
- CollectionMetaEventType.sortChanged,
- ),
- );
- await _expectCover(tester, oldest, count: 2);
- expect(tester.widget<Hero>(headerHero).tag, heroTag);
+ collection.pubMagicMetadata = CollectionPubMagicMetadata(asc: true);
+ Bus.instance.fire(
+ CollectionMetaEvent(collection.id, CollectionMetaEventType.sortChanged),
+ );
+ await _expectCover(tester, oldest, count: 2);
+ expect(tester.widget<Hero>(headerHero).tag, heroTag);
+ Bus.instance.fire(
+ CollectionUpdatedEvent(collection.id, [], "cover_change"),
+ );
+ await tester.pump();
+ await tester.runAsync(() async {
+ expect(await CollectionsService.instance.getCover(collection), oldest);
+ });
+ refreshAlbums(() {});
+ await _expectCover(tester, oldest, count: 2);
+ final albumHero = find.descendant(
+ of: find.byType(AlbumRowItemWidget, skipOffstage: false),
+ matching: find.byWidgetPredicate(
+ (widget) => widget is Hero && widget.child is ClipSmoothRect,
+ skipOffstage: false,
+ ),
+ skipOffstage: false,
+ );
+ expect(tester.widget<Hero>(albumHero).tag, heroTag);
- Navigator.of(tester.element(find.byType(CollectionPage))).pop();
- await tester.pumpAndSettle();
- expect(find.byType(AlbumRowItemWidget), findsOneWidget);
- expect(tester.takeException(), isNull);
- await _disposeAlbum(tester);
- },
- );
- }
+ Navigator.of(tester.element(find.byType(CollectionPage))).pop();
+ await tester.pumpAndSettle();
+ expect(find.byType(AlbumRowItemWidget), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ await _disposeAlbum(tester);
+ },
+ );
}
Collection _collection() => Collection(