Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] add memory lane option to cluster pages

Priyanshu Dangaref500c0651bde
diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
index 3e0cce10c6..9a18808380 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
@@ -36,11 +36,19 @@ class ClusterAppBar extends StatefulWidget {
GalleryType type,
String? title,
SelectedFiles selectedFiles,
- String clusterID,
- ) {
+ String clusterID, {
+ bool memoryLaneReady = false,
+ Future<void> Function()? onMemoryLaneTap,
+ }) {
return GalleryAppBarConfig(
- sliverBuilder: (_) =>
- ClusterAppBar._(type, title, selectedFiles, clusterID),
+ sliverBuilder: (_) => ClusterAppBar._(
+ type,
+ title,
+ selectedFiles,
+ clusterID,
+ memoryLaneReady,
+ onMemoryLaneTap,
+ ),
geometryBuilder: (context) => SliverAppBarComponent.resolveGeometry(
context,
expandedHeight: _sliverExpandedHeight,
@@ -53,12 +61,16 @@ class ClusterAppBar extends StatefulWidget {
final String? title;
final SelectedFiles selectedFiles;
final String clusterID;
+ final bool memoryLaneReady;
+ final Future<void> Function()? onMemoryLaneTap;
const ClusterAppBar._(
this.type,
this.title,
this.selectedFiles,
this.clusterID,
+ this.memoryLaneReady,
+ this.onMemoryLaneTap,
);
@override
@@ -70,6 +82,7 @@ enum ClusterPopupAction {
breakupCluster,
breakupClusterDebug,
ignore,
+ memoryLane,
}
class _AppBarWidgetState extends State<ClusterAppBar> {
@@ -128,40 +141,51 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
List<Widget> _getDefaultActions(BuildContext context) {
final iconColor = getEnteColorScheme(context).contentLight;
+ final hasAccount = Configuration.instance.hasConfiguredAccount();
final List<Widget> actions = <Widget>[];
- if (widget.selectedFiles.files.isNotEmpty ||
- isLocalGalleryMode ||
- !Configuration.instance.hasConfiguredAccount()) {
+ if (widget.selectedFiles.files.isNotEmpty) {
return actions;
}
final List<EntePopupMenuOption<ClusterPopupAction>> items = [
- EntePopupMenuOption(
- value: ClusterPopupAction.ignore,
- label: context.strings.ignorePerson,
- leadingWidget: galleryAppBarMenuIcon(
- HugeIcons.strokeRoundedUserBlock01,
- iconColor,
+ if (widget.memoryLaneReady && widget.onMemoryLaneTap != null)
+ EntePopupMenuOption(
+ value: ClusterPopupAction.memoryLane,
+ label: context.strings.facesTimelineAppBarTitle,
+ leadingWidget: galleryAppBarMenuIcon(
+ HugeIcons.strokeRoundedSparkles,
+ iconColor,
+ ),
),
- ),
- EntePopupMenuOption(
- value: ClusterPopupAction.breakupCluster,
- label: context.strings.mixedGrouping,
- leadingWidget: galleryAppBarMenuIcon(
- HugeIcons.strokeRoundedUserMultiple,
- iconColor,
+ if (!isLocalGalleryMode && hasAccount) ...[
+ EntePopupMenuOption(
+ value: ClusterPopupAction.ignore,
+ label: context.strings.ignorePerson,
+ leadingWidget: galleryAppBarMenuIcon(
+ HugeIcons.strokeRoundedUserBlock01,
+ iconColor,
+ ),
),
- ),
- if (kDebugMode)
EntePopupMenuOption(
- value: ClusterPopupAction.breakupClusterDebug,
- label: "Debug mixed grouping",
+ value: ClusterPopupAction.breakupCluster,
+ label: context.strings.mixedGrouping,
leadingWidget: galleryAppBarMenuIcon(
- HugeIcons.strokeRoundedAiBrain01,
+ HugeIcons.strokeRoundedUserMultiple,
iconColor,
),
),
+ if (kDebugMode)
+ EntePopupMenuOption(
+ value: ClusterPopupAction.breakupClusterDebug,
+ label: "Debug mixed grouping",
+ leadingWidget: galleryAppBarMenuIcon(
+ HugeIcons.strokeRoundedAiBrain01,
+ iconColor,
+ ),
+ ),
+ ],
];
+ if (items.isEmpty) return actions;
actions.add(
galleryAppBarPopupMenuAction<ClusterPopupAction>(
@@ -175,6 +199,8 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
await _onIgnoredClusterClicked(context);
} else if (value == ClusterPopupAction.breakupClusterDebug) {
await _breakUpClusterDebug(context);
+ } else if (value == ClusterPopupAction.memoryLane) {
+ await widget.onMemoryLaneTap?.call();
}
},
),
diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
index 33cd54c3e1..f9a7384fc5 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
@@ -18,6 +18,7 @@ import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart" show isLocalGalleryMode;
import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";
import "package:photos/services/machine_learning/ml_result.dart";
+import "package:photos/services/memory_lane/memory_lane_service.dart";
import "package:photos/ui/components/banners/name_face_banner.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";
@@ -27,6 +28,7 @@ import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.da
import "package:photos/ui/viewer/gallery/state/selection_state.dart";
import "package:photos/ui/viewer/people/add_person_action_sheet.dart";
import "package:photos/ui/viewer/people/cluster_app_bar.dart";
+import "package:photos/ui/viewer/people/memory_lane_page.dart";
import "package:photos/ui/viewer/people/people_page.dart";
import "package:photos/ui/viewer/people/person_face_widget.dart";
import "package:photos/ui/viewer/people/save_person_banner.dart";
@@ -67,6 +69,8 @@ class _ClusterPageState extends State<ClusterPage> {
late final StreamSubscription<LocalPhotosUpdatedEvent> _filesUpdatedEvent;
late final StreamSubscription<PeopleChangedEvent> _peopleChangedEvent;
late final StreamSubscription<AppModeChangedEvent> _appModeChangedEvent;
+ late final ValueNotifier<Set<String>> _timelineNotifier;
+ late final VoidCallback _timelineListener;
bool get _localGalleryUiMode =>
isLocalGalleryMode && !Configuration.instance.hasConfiguredAccount();
@@ -110,6 +114,17 @@ class _ClusterPageState extends State<ClusterPage> {
setState(() {});
}
});
+ _timelineNotifier = MemoryLaneService.instance.readyPersonIds;
+ _timelineListener = () {
+ if (mounted) setState(() {});
+ };
+ _timelineNotifier.addListener(_timelineListener);
+ unawaited(
+ MemoryLaneService.instance.ensureTimelineReachability(
+ widget.clusterID,
+ isCluster: true,
+ ),
+ );
kDebugMode
? ClusterFeedbackService.instance.debugLogClusterBlurValues(
widget.clusterID,
@@ -123,6 +138,7 @@ class _ClusterPageState extends State<ClusterPage> {
_filesUpdatedEvent.cancel();
_peopleChangedEvent.cancel();
_appModeChangedEvent.cancel();
+ _timelineNotifier.removeListener(_timelineListener);
if (ClusterFeedbackService.lastViewedClusterID == widget.clusterID) {
ClusterFeedbackService.resetLastViewedClusterID();
}
@@ -155,6 +171,19 @@ class _ClusterPageState extends State<ClusterPage> {
}
}
+ Future<void> _openMemoryLanePage() async {
+ if (MemoryLaneService.instance.hasReadyTimelineSync(
+ widget.clusterID,
+ isCluster: true,
+ )) {
+ await routeToPage(
+ context,
+ MemoryLanePage.cluster(clusterID: widget.clusterID),
+ );
+ }
+ if (mounted) setState(() {});
+ }
+
@override
Widget build(BuildContext context) {
final appBar = ClusterAppBar.sliverConfig(
@@ -162,6 +191,11 @@ class _ClusterPageState extends State<ClusterPage> {
"${files.length} memories${widget.appendTitle}",
_selectedFiles,
widget.clusterID,
+ memoryLaneReady: MemoryLaneService.instance.hasReadyTimelineSync(
+ widget.clusterID,
+ isCluster: true,
+ ),
+ onMemoryLaneTap: _openMemoryLanePage,
);
final gallery = Gallery(
appBar: appBar,
diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart
index ad7a3135f6..e7f751a386 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page.dart
@@ -28,9 +28,16 @@ import "package:photos/utils/face_crop_util.dart";
import "package:photos/utils/share_util.dart";
class MemoryLanePage extends StatefulWidget {
- final PersonEntity person;
+ final PersonEntity? person;
+ final String? clusterID;
- const MemoryLanePage({required this.person, super.key});
+ const MemoryLanePage({required this.person, super.key}) : clusterID = null;
+
+ const MemoryLanePage.cluster({required this.clusterID, super.key})
+ : person = null;
+
+ String get timelineId => person?.remoteID ?? clusterID ?? "";
+ bool get isCluster => clusterID != null;
@override
State<MemoryLanePage> createState() => _MemoryLanePageState();
@@ -81,6 +88,8 @@ class _MemoryLanePageState extends State<MemoryLanePage>
static const int _frameBuildConcurrency = 6;
final Logger _logger = Logger("MemoryLanePage");
+ MLDataDB get _mlDataDB =>
+ isLocalGalleryMode ? MLDataDB.localGalleryInstance : MLDataDB.instance;
late final AnimationController _cardTransitionController;
double _stackProgress = 0;
late final ValueNotifier<double> _stackProgressNotifier;
@@ -110,6 +119,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
_CaptionType _currentCaptionType = _CaptionType.yearsAgo;
int _maxCaptionDigits = 1;
bool get _showShareAction =>
+ !widget.isCluster &&
MemoryLaneService.instance.isFeatureEnabled &&
flagService.enableMemoryShareLink &&
!isLocalGalleryMode;
@@ -150,9 +160,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
}
Future<void> _loadFrames() async {
- _hasMarkedTimelineSeen = localSettings.hasSeenMemoryLane(
- widget.person.remoteID,
- );
+ _hasMarkedTimelineSeen = localSettings.hasSeenMemoryLane(widget.timelineId);
_playTimer?.cancel();
if (mounted) {
setState(() {
@@ -161,7 +169,8 @@ class _MemoryLanePageState extends State<MemoryLanePage>
}
try {
final timeline = await MemoryLaneService.instance.getTimeline(
- widget.person.remoteID,
+ widget.timelineId,
+ isCluster: widget.isCluster,
);
if (!mounted) {
return;
@@ -218,7 +227,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
.map((entry) => entry.fileId)
.toSet()
.toList();
- final filesById = await FilesDB.instance.getFileIDToFileFromIDs(
+ final filesById = await MemoryLaneService.instance.getTimelineFiles(
uniqueFileIds,
);
final Map<int, Future<List<Face>?>> facesFutures = {};
@@ -273,7 +282,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
return;
}
_hasMarkedTimelineSeen = true;
- unawaited(localSettings.markMemoryLaneSeen(widget.person.remoteID));
+ unawaited(localSettings.markMemoryLaneSeen(widget.timelineId));
}
void _handleFrameLoaded(_TimelineFrame frame, int loadedCount) {
@@ -348,7 +357,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
final entry = entries[index];
final facesFuture = facesFutures.putIfAbsent(
entry.fileId,
- () => MLDataDB.instance.getFacesForGivenFileID(entry.fileId),
+ () => _mlDataDB.getFacesForGivenFileID(entry.fileId),
);
_buildFrame(
entry,
@@ -389,7 +398,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
if (facesFuture != null) {
faces = await facesFuture;
} else {
- faces = await MLDataDB.instance.getFacesForGivenFileID(entry.fileId);
+ faces = await _mlDataDB.getFacesForGivenFileID(entry.fileId);
}
final Face? face = faces?.firstWhereOrNull(
(element) => element.faceID == entry.faceId,
@@ -437,12 +446,12 @@ class _MemoryLanePageState extends State<MemoryLanePage>
final creationDate = DateTime.fromMicrosecondsSinceEpoch(
entry.creationTimeMicros,
);
- final captionType = widget.person.data.birthDate != null
+ final birthDateString = widget.person?.data.birthDate;
+ final captionType = birthDateString != null
? _CaptionType.age
: _CaptionType.yearsAgo;
int captionValue;
- if (captionType == _CaptionType.age) {
- final birthDateString = widget.person.data.birthDate!;
+ if (birthDateString != null) {
final birthDate = DateTime.tryParse(birthDateString);
if (birthDate == null) {
captionValue = wholeYearsBetween(creationDate, DateTime.now());
@@ -506,7 +515,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
void _logPlaybackStart(int frameCount) {
if (_loggedPlaybackStart) return;
_logger.info(
- "playback_start person=${widget.person.remoteID} frames=$frameCount",
+ "playback_start person=${widget.timelineId} frames=$frameCount",
);
_loggedPlaybackStart = true;
}
@@ -928,7 +937,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
String fullText;
if (captionType == _CaptionType.age) {
fullText = l10n.facesTimelineCaptionYearsOld(
- name: widget.person.data.name,
+ name: widget.person?.data.name ?? "",
count: currentRounded,
);
} else {
@@ -936,7 +945,7 @@ class _MemoryLanePageState extends State<MemoryLanePage>
if (fullText.contains("#")) {
fullText = fullText.replaceAll("#", formattedCurrent);
}
- final String name = widget.person.data.name;
+ final String name = widget.person?.data.name ?? "";
if (name.isNotEmpty) {
fullText = "$name $fullText";
}
@@ -1120,12 +1129,14 @@ class _MemoryLanePageState extends State<MemoryLanePage>
Future<(String, int)?> _getOrCreateMemoryLaneLinkData(
BuildContext context,
) async {
+ final person = widget.person;
+ if (person == null) return null;
final l10n = context.strings;
final dialog = createProgressDialog(context, l10n.creatingLink);
await dialog.show();
try {
final timeline = await MemoryLaneService.instance.getTimeline(
- widget.person.remoteID,
+ person.remoteID,
);
if (timeline == null ||
!timeline.isEligible ||
@@ -1140,9 +1151,9 @@ class _MemoryLanePageState extends State<MemoryLanePage>
.getOrCreateMemoryLaneLink(
entries: timeline.entries,
title: l10n.facesTimelineAppBarTitle,
- personId: widget.person.remoteID,
- personName: widget.person.data.name,
- birthDate: widget.person.data.birthDate,
+ personId: person.remoteID,
+ personName: person.data.name,
+ birthDate: person.data.birthDate,
);
await dialog.hide();
return shareLinkData;