π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] polish memory lane card
Priyanshu Dangarefd825e82640e
diff --git a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dartindex 20eb305013..97fa57e4af 100644--- a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart+++ b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart@@ -988,34 +988,18 @@ class MemoryLaneService {);}- Future<(Uint8List, Uint8List)?> getOldestAndNewestFaceCrops(+ Future<Uint8List?> getNewestFaceCrop(MemoryLanePersonTimeline timeline,) async {- Future<Uint8List?> getCrop(MemoryLaneEntry entry, EnteFile file) async {- final faces = await _mlDataDB.getFacesForGivenFileID(entry.fileId);- final face = faces?.firstWhereOrNull((f) => f.faceID == entry.faceId);- if (face == null) return null;- return (await getCachedFaceCrops(- file,- [face],- useFullFile: true,- useTempCache: false,- ))?[entry.faceId];- }-- final oldest = timeline.entries.first;final newest = timeline.entries.last;- final filesById = await getTimelineFiles([oldest.fileId, newest.fileId]);- final oldestFile = filesById[oldest.fileId];- final newestFile = filesById[newest.fileId];- if (oldestFile == null || newestFile == null) return null;-- final (oldestCrop, newestCrop) = await (- getCrop(oldest, oldestFile),- getCrop(newest, newestFile),- ).wait;- if (oldestCrop == null || newestCrop == null) return null;- return (oldestCrop, newestCrop);+ final newestFile = (await getTimelineFiles([newest.fileId]))[newest.fileId];+ if (newestFile == null) return null;+ final faces = await _mlDataDB.getFacesForGivenFileID(newest.fileId);+ final face = faces?.firstWhereOrNull((f) => f.faceID == newest.faceId);+ if (face == null) return null;+ return (await getCachedFaceCrops(newestFile, [+ face,+ ], useTempCache: false))?[newest.faceId];}Future<void> _scheduleTimelinesForMemoriesStrip(diff --git a/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart b/mobile/apps/photos/lib/ui/home/memories/memories_strip.dartindex 383c39b120..717e24286f 100644--- a/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart+++ b/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart@@ -3,18 +3,23 @@ import "dart:math";import "dart:typed_data";import "package:collection/collection.dart";+import "package:ente_pure_utils/ente_pure_utils.dart";import 'package:flutter/material.dart';import "package:flutter_animate/flutter_animate.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/event.dart";+import "package:photos/events/files_updated_event.dart";+import "package:photos/events/local_photos_updated_event.dart";import "package:photos/events/memories_changed_event.dart";import "package:photos/events/memories_setting_changed.dart";import "package:photos/events/memory_seen_event.dart";import "package:photos/events/ml_consent_changed_event.dart";+import "package:photos/events/people_changed_event.dart";+import "package:photos/models/file/file.dart";import "package:photos/models/memories/smart_memory.dart";import "package:photos/models/memory_lane/memory_lane_models.dart";import "package:photos/service_locator.dart";-import "package:photos/services/memory_lane/memory_lane_cache_service.dart";+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";import "package:photos/services/memory_lane/memory_lane_service.dart";import "package:photos/ui/home/memories/crafting_memories_card.dart";import 'package:photos/ui/home/memories/memory_card.dart';@@ -22,6 +27,7 @@ import "package:photos/ui/home/memories/memory_card_constants.dart";import "package:photos/ui/home/memories/memory_cover_util.dart";import "package:photos/ui/home/memories/memory_lane_card.dart";import "package:photos/ui/home/memories/memory_video_prefetcher.dart";+import "package:photos/ui/viewer/people/memory_lane_page.dart";class MemoryCardWrapper {final String id;@@ -42,6 +48,9 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {late StreamSubscription<MemoriesChangedEvent> _memoriesChangedSubscription;late StreamSubscription<MemorySeenEvent> _memorySeenSubscription;late StreamSubscription<MLConsentChangedEvent> _mlConsentChangedSubscription;+ late StreamSubscription<PeopleChangedEvent> _peopleChangedSubscription;+ late StreamSubscription<LocalPhotosUpdatedEvent>+ _localPhotosUpdatedSubscription;late double _cardWidth;// Delay cover warming past startup; generations invalidate stale work.@@ -50,13 +59,14 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {int _fetchMemoriesGeneration = 0;String? _lastWarmSignature;MemoryLanePersonTimeline? _memoryLane;- Uint8List? _oldestMemoryLaneFace;+ EnteFile? _oldestMemoryLaneFile;Uint8List? _newestMemoryLaneFace;+ String? _memoryLanePersonName;final _videoPrefetcher = MemoryVideoPrefetcher();final _scrollController = ScrollController();bool _shouldShowCraftingMemories = false;late Future<void> _shouldShowCraftingMemoriesLoaded;- late Future<void> _memoryLaneLoaded;+ late final Future<void> _memoryLaneLoaded;late List<SmartMemory> _initialMemories;late Future<List<SmartMemory>> _memories;@@ -83,6 +93,12 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {_mlConsentChangedSubscription = Bus.instance.on<MLConsentChangedEvent>().listen(_onMLConsentChanged);+ _peopleChangedSubscription = Bus.instance.on<PeopleChangedEvent>().listen(+ _onPeopleChanged,+ );+ _localPhotosUpdatedSubscription = Bus.instance+ .on<LocalPhotosUpdatedEvent>()+ .listen(_onLocalPhotosUpdated);_memoryLaneLoaded = _loadScheduledMemoryLane();MemoryLaneService.instance.readyPersonIds.addListener(_onMemoryLaneReadyTimelinesChanged,@@ -95,6 +111,8 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {_memoriesChangedSubscription.cancel();_memorySeenSubscription.cancel();_mlConsentChangedSubscription.cancel();+ _peopleChangedSubscription.cancel();+ _localPhotosUpdatedSubscription.cancel();_warmTimer?.cancel();_videoPrefetcher.dispose();_scrollController.dispose();@@ -198,7 +216,7 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {double cardHeight,) {final memoryLane = _memoryLane;- final oldestMemoryLaneFace = _oldestMemoryLaneFace;+ final oldestMemoryLaneFile = _oldestMemoryLaneFile;final newestMemoryLaneFace = _newestMemoryLaneFace;final hasContent = memories.isNotEmpty || memoryLane != null;return [@@ -221,14 +239,16 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {if (flagService.internalUser &&MemoryLaneService.instance.isFeatureEnabled &&memoryLane != null &&- oldestMemoryLaneFace != null &&+ oldestMemoryLaneFile != null &&newestMemoryLaneFace != null)MemoryCardWrapper(id: "memoryLane_${memoryLane.personId}",widget: () => MemoryLaneCardWidget(- memoryLane,- oldestMemoryLaneFace,- newestMemoryLaneFace,+ oldestFile: oldestMemoryLaneFile,+ face: newestMemoryLaneFace,+ personName: _memoryLanePersonName ?? "",+ size: Size(_cardWidth, cardHeight),+ onTap: () => _openMemoryLanePage(memoryLane),),),...memories.indexed.map(@@ -245,6 +265,21 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {];}+ Future<void> _openMemoryLanePage(MemoryLanePersonTimeline memoryLane) async {+ if (memoryLane.isCluster) {+ await routeToPage(+ context,+ MemoryLanePage.cluster(clusterID: memoryLane.personId),+ );+ } else {+ final person = await PersonService.instance.getPerson(+ memoryLane.personId,+ );+ if (person == null || !mounted) return;+ await routeToPage(context, MemoryLanePage(person: person));+ }+ }+void _fetchMemories(Event? event) {final fetchGeneration = ++_fetchMemoriesGeneration;setState(() {@@ -331,8 +366,7 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {}Future<void> _loadScheduledMemoryLane() async {- if (!flagService.internalUser ||- !MemoryLaneService.instance.isFeatureEnabled) {+ if (!flagService.internalUser) {return;}final timeline = await MemoryLaneService.instance@@ -340,24 +374,75 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {if (timeline == null) {return;}- final faceCrops = await MemoryLaneService.instance- .getOldestAndNewestFaceCrops(timeline);- if (faceCrops == null || !hasGrantedMLConsent) {+ final newestFaceCrop = await MemoryLaneService.instance.getNewestFaceCrop(+ timeline,+ );+ final oldestEntry = timeline.entries.first;+ final oldestFile = (await MemoryLaneService.instance.getTimelineFiles([+ oldestEntry.fileId,+ ]))[oldestEntry.fileId];+ final personName = timeline.isCluster+ ? null+ : (await PersonService.instance.getPerson(+ timeline.personId,+ ))?.data.name;+ if (!mounted ||+ newestFaceCrop == null ||+ oldestFile == null ||+ !hasGrantedMLConsent) {return;}_memoryLane = timeline;- _oldestMemoryLaneFace = faceCrops.$1;- _newestMemoryLaneFace = faceCrops.$2;+ _oldestMemoryLaneFile = oldestFile;+ _newestMemoryLaneFace = newestFaceCrop;+ _memoryLanePersonName = personName;}void _onMLConsentChanged(MLConsentChangedEvent event) {- if (event.enabled || !mounted || _memoryLane == null) {+ if (event.enabled || !mounted) {+ return;+ }+ setState(() {+ _memoryLane = null;+ _oldestMemoryLaneFile = null;+ _newestMemoryLaneFace = null;+ _memoryLanePersonName = null;+ });+ }++ void _onPeopleChanged(PeopleChangedEvent _) {+ if (!mounted || _memoryLane == null) {+ return;+ }+ setState(() {+ _memoryLane = null;+ _oldestMemoryLaneFile = null;+ _newestMemoryLaneFace = null;+ _memoryLanePersonName = null;+ });+ }++ void _onLocalPhotosUpdated(LocalPhotosUpdatedEvent event) {+ if (!mounted ||+ (event.type != EventType.hide &&+ event.type != EventType.deletedFromEverywhere &&+ event.type != EventType.deletedFromRemote)) {+ return;+ }+ final memoryLane = _memoryLane;+ if (memoryLane == null ||+ !memoryLane.entries.any(+ (entry) => event.updatedFiles.any(+ (file) => file.uploadedFileID == entry.fileId,+ ),+ )) {return;}setState(() {_memoryLane = null;- _oldestMemoryLaneFace = null;+ _oldestMemoryLaneFile = null;_newestMemoryLaneFace = null;+ _memoryLanePersonName = null;});}@@ -374,8 +459,9 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {}setState(() {_memoryLane = null;- _oldestMemoryLaneFace = null;+ _oldestMemoryLaneFile = null;_newestMemoryLaneFace = null;+ _memoryLanePersonName = null;});}}diff --git a/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dart b/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dartindex 1586ebf48a..d77985f14c 100644--- a/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dart+++ b/mobile/apps/photos/lib/ui/home/memories/memory_lane_card.dart@@ -1,99 +1,184 @@-import "dart:convert";import "dart:typed_data";+import "package:ente_components/ente_components.dart";+import "package:ente_strings/ente_strings.dart";import "package:flutter/material.dart";-import "package:photos/models/memory_lane/memory_lane_models.dart";+import "package:photos/core/constants.dart";+import "package:photos/models/file/file.dart";import "package:photos/ui/home/memories/memory_card_constants.dart";+import "package:photos/ui/viewer/file/thumbnail_widget.dart";class MemoryLaneCardWidget extends StatelessWidget {- final MemoryLanePersonTimeline timeline;- final Uint8List oldestFace;- final Uint8List newestFace;+ final EnteFile oldestFile;+ final Uint8List face;+ final String personName;+ final Size size;+ final VoidCallback onTap;- const MemoryLaneCardWidget(- this.timeline,- this.oldestFace,- this.newestFace, {+ const MemoryLaneCardWidget({+ required this.oldestFile,+ required this.face,+ required this.personName,+ required this.size,+ required this.onTap,super.key,});@overrideWidget build(BuildContext context) {- final timelineDump = const JsonEncoder.withIndent(- " ",- ).convert(timeline.toJson());+ final name = personName.trim();+ final title = name.isEmpty+ ? context.strings.facesTimelineAppBarTitle+ : context.strings.memoryLaneCardTitle(name: name);return Padding(padding: const EdgeInsets.symmetric(horizontal: kMemoryCardStripGap / 2),- child: Container(- width: 320,- clipBehavior: Clip.antiAlias,- decoration: BoxDecoration(- color: Colors.black,- borderRadius: BorderRadius.circular(kMemoryCardBorderRadius),- ),- child: Column(- children: [- SizedBox(- height: 96,- child: Row(- children: [- Expanded(child: _FaceDebugView("oldest", oldestFace)),- Expanded(child: _FaceDebugView("newest", newestFace)),- ],+ child: GestureDetector(+ onTap: onTap,+ child: SizedBox(+ width: size.width * 1.013513513514,+ height: size.height,+ child: Stack(+ children: [+ Positioned(+ left: 0,+ top: size.height * 0.004651162791,+ width: size.width * 0.270270270270,+ height: size.width * 0.270270270270,+ child: ClipOval(+ child: Image.memory(+ face,+ fit: BoxFit.cover,+ gaplessPlayback: true,+ ),+ ),),- ),- Expanded(- child: SingleChildScrollView(- padding: const EdgeInsets.all(6),+ Positioned(+ left: size.width * 0.013513513514,+ top: 0,+ bottom: 0,+ width: size.width,+ child: ClipPath(+ clipper: const _MemoryLaneBackgroundClipper(),+ clipBehavior: Clip.antiAlias,+ child: Container(+ foregroundDecoration: const BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ colors: [Colors.transparent, Color(0xB8000000)],+ stops: [0.53663, 0.89955],+ ),+ ),+ child: ThumbnailWidget(+ oldestFile,+ rawThumbnail: true,+ shouldShowSyncStatus: false,+ thumbnailSize: thumbnailLargeSize,+ ),+ ),+ ),+ ),+ Positioned(+ left: size.width * 0.094594594595,+ bottom: 16,+ width: size.width * 0.837837837838,child: Text(- timelineDump,- style: const TextStyle(+ title,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: TextStyles.body.copyWith(+ height: 16 / 14,+ fontFamily: TextStyles.outfitFontFamily,color: Colors.white,- fontFamily: "monospace",- fontSize: 8,- height: 1.1,+ fontWeight: FontWeight.w700,),+ textAlign: TextAlign.left,),),- ),- ],+ ],+ ),),),);}}-class _FaceDebugView extends StatelessWidget {- final String label;- final Uint8List bytes;-- const _FaceDebugView(this.label, this.bytes);+class _MemoryLaneBackgroundClipper extends CustomClipper<Path> {+ const _MemoryLaneBackgroundClipper();@override- Widget build(BuildContext context) {- return Stack(- fit: StackFit.expand,- children: [- Image(- image: MemoryImage(bytes),- fit: BoxFit.cover,- gaplessPlayback: true,+ Path getClip(Size size) {+ return Path()+ ..moveTo(size.width * 0.891891891892, 0)+ ..cubicTo(+ size.width * 0.951598344595,+ 0,+ size.width,+ size.height * 0.033318348837,+ size.width,+ size.height * 0.074418604651,+ )+ ..lineTo(size.width, size.height * 0.925581395349)+ ..cubicTo(+ size.width,+ size.height * 0.966681651163,+ size.width * 0.951598344595,+ size.height,+ size.width * 0.891891891892,+ size.height,+ )+ ..lineTo(size.width * 0.108108108108, size.height)+ ..cubicTo(+ size.width * 0.048401655405,+ size.height,+ 0,+ size.height * 0.966681651163,+ 0,+ size.height * 0.925581395349,+ )+ ..lineTo(0, size.height * 0.196098302326)+ ..arcToPoint(+ Offset(size.width * 0.023645925676, size.height * 0.189943265116),+ radius: Radius.elliptical(+ size.width * 0.013513513514,+ size.height * 0.009302325581,),- Align(- alignment: Alignment.bottomLeft,- child: ColoredBox(- color: Colors.black54,- child: Padding(- padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),- child: Text(- label,- style: const TextStyle(color: Colors.white, fontSize: 10),- ),- ),- ),+ )+ ..cubicTo(+ size.width * 0.029714202703,+ size.height * 0.194676893023,+ size.width * 0.073182898649,+ size.height * 0.209302325581,+ size.width * 0.121621621622,+ size.height * 0.209302325581,+ )+ ..cubicTo(+ size.width * 0.211181310811,+ size.height * 0.209302325581,+ size.width * 0.283783783784,+ size.height * 0.159324809302,+ size.width * 0.283783783784,+ size.height * 0.097674418605,+ )+ ..cubicTo(+ size.width * 0.283783783784,+ size.height * 0.055641748837,+ size.width * 0.250030540541,+ size.height * 0.019041051163,+ size.width * 0.245829554054,+ size.height * 0.017436786047,+ )+ ..arcToPoint(+ Offset(size.width * 0.252385060811, 0),+ radius: Radius.elliptical(+ size.width * 0.013513513514,+ size.height * 0.009302325581,),- ],- );+ )+ ..close();}++ @override+ bool shouldReclip(_MemoryLaneBackgroundClipper oldClipper) => false;}diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex c3435d12ee..6a3f07eaad 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -2513,6 +2513,16 @@}}},+ "memoryLaneCardTitle": "{name}βs memory lane",+ "@memoryLaneCardTitle": {+ "description": "Title for the Memory Lane card on the home screen",+ "placeholders": {+ "name": {+ "type": "String",+ "description": "Person's name"+ }+ }+ },"memoryLink": "Memory link","memoryShareLinkDescription": "This link will automatically expire in 7 days.","merchandise": "Merchandise",