Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] use faces only for memlane card cover

Priyanshu Dangare4e0dfbd620c6
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.dart
index bc20677656..514fe0f466 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,18 +988,28 @@ class MemoryLaneService {
);
}
- Future<Uint8List?> getNewestFaceCrop(
+ Future<({Uint8List oldest, Uint8List newest})?> getOldestAndNewestFaceCrops(
MemoryLanePersonTimeline timeline,
) async {
- final newest = timeline.entries.last;
- 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];
+ if (timeline.entries.isEmpty) return null;
+ final entries = [timeline.entries.first, timeline.entries.last];
+ final files = await getTimelineFiles(
+ entries.map((entry) => entry.fileId).toList(),
+ );
+ final crops = <Uint8List>[];
+ for (final entry in entries) {
+ final file = files[entry.fileId];
+ if (file == null) return null;
+ final faces = await _mlDataDB.getFacesForGivenFileID(entry.fileId);
+ final face = faces?.firstWhereOrNull((f) => f.faceID == entry.faceId);
+ if (face == null) return null;
+ final crop = (await getCachedFaceCrops(file, [
+ face,
+ ], useTempCache: false))?[entry.faceId];
+ if (crop == null) return null;
+ crops.add(crop);
+ }
+ return (oldest: crops.first, newest: crops.last);
}
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.dart
index b19278c080..31b3f028f7 100644
--- a/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/memories_strip.dart
@@ -19,7 +19,6 @@ 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/models/ml/face/person.dart";
@@ -68,7 +67,7 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {
int _fetchMemoriesGeneration = 0;
String? _lastWarmSignature;
MemoryLanePersonTimeline? _memoryLane;
- EnteFile? _oldestMemoryLaneFile;
+ Uint8List? _oldestMemoryLaneFace;
Uint8List? _newestMemoryLaneFace;
PersonEntity? _memoryLanePerson;
final _videoPrefetcher = MemoryVideoPrefetcher();
@@ -234,14 +233,14 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {
) {
final memoryLane = _memoryLane;
final memoryLanePerson = _memoryLanePerson;
- final oldestMemoryLaneFile = _oldestMemoryLaneFile;
+ final oldestMemoryLaneFace = _oldestMemoryLaneFace;
final newestMemoryLaneFace = _newestMemoryLaneFace;
final hasMemoryLane =
flagService.internalUser &&
MemoryLaneService.instance.isFeatureEnabled &&
memoryLane != null &&
(memoryLane.isCluster || memoryLanePerson != null) &&
- oldestMemoryLaneFile != null &&
+ oldestMemoryLaneFace != null &&
newestMemoryLaneFace != null;
final hasContent = memories.isNotEmpty || memoryLane != null;
final cardBuilders = <MemoryCardWrapper Function(VoidCallback onTap)>[
@@ -250,7 +249,7 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {
id: "memoryLane_${memoryLane.personId}",
widget: () => MemoryLaneCardWidget(
id: memoryLane.personId,
- oldestFile: oldestMemoryLaneFile,
+ oldestFace: oldestMemoryLaneFace,
face: newestMemoryLaneFace,
personName: memoryLanePerson?.data.name ?? "",
size: Size(_cardWidth, cardHeight),
@@ -395,33 +394,25 @@ class _MemoriesStripWidgetState extends State<MemoriesStripWidget> {
if (timeline == null) {
return;
}
- final newestFaceCrop = await MemoryLaneService.instance.getNewestFaceCrop(
- timeline,
- );
- final oldestEntry = timeline.entries.first;
- final oldestFile = (await MemoryLaneService.instance.getTimelineFiles([
- oldestEntry.fileId,
- ]))[oldestEntry.fileId];
+ final faceCrops = await MemoryLaneService.instance
+ .getOldestAndNewestFaceCrops(timeline);
PersonEntity? person;
if (!timeline.isCluster) {
person = await PersonService.instance.getPerson(timeline.personId);
}
- if (!mounted ||
- newestFaceCrop == null ||
- oldestFile == null ||
- !hasGrantedMLConsent) {
+ if (!mounted || faceCrops == null || !hasGrantedMLConsent) {
return;
}
_memoryLane = timeline;
- _oldestMemoryLaneFile = oldestFile;
- _newestMemoryLaneFace = newestFaceCrop;
+ _oldestMemoryLaneFace = faceCrops.oldest;
+ _newestMemoryLaneFace = faceCrops.newest;
_memoryLanePerson = person;
}
void _hideMemoryLane() {
setState(() {
_memoryLane = null;
- _oldestMemoryLaneFile = null;
+ _oldestMemoryLaneFace = null;
_newestMemoryLaneFace = null;
_memoryLanePerson = 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.dart
index 2c45ea49a0..67c9137bf3 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
@@ -3,14 +3,11 @@ 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/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 String id;
- final EnteFile oldestFile;
+ final Uint8List oldestFace;
final Uint8List face;
final String personName;
final Size size;
@@ -18,7 +15,7 @@ class MemoryLaneCardWidget extends StatelessWidget {
const MemoryLaneCardWidget({
required this.id,
- required this.oldestFile,
+ required this.oldestFace,
required this.face,
required this.personName,
required this.size,
@@ -75,11 +72,10 @@ class MemoryLaneCardWidget extends StatelessWidget {
stops: [0.53663, 0.89955],
),
),
- child: ThumbnailWidget(
- oldestFile,
- rawThumbnail: true,
- shouldShowSyncStatus: false,
- thumbnailSize: thumbnailLargeSize,
+ child: Image.memory(
+ oldestFace,
+ fit: BoxFit.cover,
+ gaplessPlayback: true,
),
),
),