π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Show relative time in memory lane captions
Priyanshu Dangarede4f36700966
diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dartindex 1755866d1a..5acf0a06bd 100644--- a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_page_v2.dart@@ -352,68 +352,66 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {final file = _files.isEmpty ? null : _files[i];final entry = _entries.isEmpty ? null : _chunkinator!.get(_entries[i]);final creationTime = file?.creationTime;- final birthDate = DateTime.tryParse(- widget.person?.data.birthDate ?? "",- );final creationDate = creationTime == null? null: DateTime.fromMicrosecondsSinceEpoch(creationTime);- int? age;- if (birthDate != null &&- creationDate != null &&- !creationDate.isBefore(birthDate)) {- age = creationDate.year - birthDate.year;- final lastDay = DateTime(- creationDate.year,- birthDate.month + 1,- 0,- ).day;- final anniversary = DateTime(- creationDate.year,- birthDate.month,- birthDate.day.clamp(1, lastDay),- );- if (creationDate.isBefore(anniversary)) age--;- }const captionPlaceholder = "\uFFFC";int? captionValue;String? caption;- if (age != null && name != null && name.isNotEmpty) {- captionValue = age;- caption = context.strings.memoryLaneAgeCaption(- name: name,- count: age,- age: captionPlaceholder,- );- } else if (creationDate != null) {+ if (creationDate != null) {final now = DateTime.now();- final anniversary = DateTime(- now.year,+ final today = DateTime.utc(now.year, now.month, now.day);+ final photoDate = DateTime.utc(+ creationDate.year,creationDate.month,+ creationDate.day,+ );+ var months =+ (now.year - creationDate.year) * 12 ++ now.month -+ creationDate.month;+ final anniversary = DateTime.utc(+ now.year,+ now.month,creationDate.day.clamp(1,- DateTime(now.year, creationDate.month + 1, 0).day,+ DateTime.utc(now.year, now.month + 1, 0).day,),);- captionValue =- (now.year -- creationDate.year -- (now.isBefore(anniversary) ? 1 : 0))- .clamp(0, 1000);- caption = context.strings.facesTimelineCaptionYearsAgo(- count: captionValue,- );- if (caption.contains("#")) {- caption = caption.replaceAll("#", captionPlaceholder);- } else {- caption = caption.replaceFirst(- NumberFormat.decimalPattern(- context.strings.localeName,- ).format(captionValue),- captionPlaceholder,+ if (today.isBefore(anniversary)) months--;+ final days = today.difference(photoDate).inDays;+ if (months >= 12) {+ captionValue = months ~/ 12;+ caption = context.strings.memoryLaneCaptionYearsAgo(+ name: name ?? "",+ count: captionValue,+ number: captionPlaceholder,);+ } else if (months >= 1) {+ captionValue = months;+ caption = context.strings.memoryLaneCaptionMonthsAgo(+ name: name ?? "",+ count: captionValue,+ number: captionPlaceholder,+ );+ } else if (days >= 7) {+ captionValue = days ~/ 7;+ caption = context.strings.memoryLaneCaptionWeeksAgo(+ name: name ?? "",+ count: captionValue,+ number: captionPlaceholder,+ );+ } else if (days >= 1) {+ captionValue = days;+ caption = context.strings.memoryLaneCaptionDaysAgo(+ name: name ?? "",+ count: captionValue,+ number: captionPlaceholder,+ );+ } else {+ caption = context.strings.memoryLaneCaptionToday(name: name ?? "");}- if (name != null && name.isNotEmpty) caption = "$name $caption";+ caption = caption.trim();}final captionParts =caption?.split(captionPlaceholder) ?? const <String>[];@@ -717,7 +715,7 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {mainAxisSize: MainAxisSize.min,mainAxisAlignment: MainAxisAlignment.spaceEvenly,children: [- if (captionValue != null) ...[+ if (caption != null) ...[ConstrainedBox(constraints: const BoxConstraints(minHeight: 48),child: Align(@@ -734,7 +732,7 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {index < captionParts.length;index++) ...[- if (index > 0)+ if (index > 0 && captionValue != null)_MemoryLaneAnimatedDigit(value: captionValue,),diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex ae0d0eb19b..b0ad4aabb0 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -1531,6 +1531,79 @@}}},+ "memoryLaneCaptionYearsAgo": "{name} {count, plural, one{{number} year ago} other{{number} years ago}}",+ "@memoryLaneCaptionYearsAgo": {+ "description": "Memory Lane caption in elapsed years. Always keep the number, including for one.",+ "placeholders": {+ "name": {+ "type": "String"+ },+ "count": {+ "type": "int"+ },+ "number": {+ "type": "String",+ "description": "Placeholder rendered as a separate, larger number; retain in every plural form."+ }+ }+ },+ "memoryLaneCaptionMonthsAgo": "{name} {count, plural, one{{number} month ago} other{{number} months ago}}",+ "@memoryLaneCaptionMonthsAgo": {+ "description": "Memory Lane caption in elapsed months. Always keep the number, including for one.",+ "placeholders": {+ "name": {+ "type": "String"+ },+ "count": {+ "type": "int"+ },+ "number": {+ "type": "String",+ "description": "Placeholder rendered as a separate, larger number; retain in every plural form."+ }+ }+ },+ "memoryLaneCaptionWeeksAgo": "{name} {count, plural, one{{number} week ago} other{{number} weeks ago}}",+ "@memoryLaneCaptionWeeksAgo": {+ "description": "Memory Lane caption in elapsed weeks. Always keep the number, including for one.",+ "placeholders": {+ "name": {+ "type": "String"+ },+ "count": {+ "type": "int"+ },+ "number": {+ "type": "String",+ "description": "Placeholder rendered as a separate, larger number; retain in every plural form."+ }+ }+ },+ "memoryLaneCaptionDaysAgo": "{name} {count, plural, one{{number} day ago} other{{number} days ago}}",+ "@memoryLaneCaptionDaysAgo": {+ "description": "Memory Lane caption in elapsed days. Always keep the number, including for one.",+ "placeholders": {+ "name": {+ "type": "String"+ },+ "count": {+ "type": "int"+ },+ "number": {+ "type": "String",+ "description": "Placeholder rendered as a separate, larger number; retain in every plural form."+ }+ }+ },+ "memoryLaneCaptionToday": "{name} today",+ "@memoryLaneCaptionToday": {+ "description": "Memory Lane caption for a photo taken today, without a number.",+ "placeholders": {+ "name": {+ "type": "String"+ }+ }+ },"facesTimelinePlaybackPause": "Pause","@facesTimelinePlaybackPause": {"description": "Tooltip or semantics label for the pause button"