💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Style memory lane now captions with Gochi Hand
ashil-pilotb7ff4875fe83
diff --git a/mobile/apps/photos/lib/ui/viewer/people/memory_lane_now_caption.dart b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_now_caption.dartnew file mode 100644index 0000000000..ac6dc973c0--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/people/memory_lane_now_caption.dart@@ -0,0 +1,46 @@+import "package:ente_components/theme/text_styles.dart";+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:photos/theme/ente_theme.dart";++class MemoryLaneNowCaption extends StatelessWidget {+ const MemoryLaneNowCaption({required this.name, super.key});++ final String name;++ @override+ Widget build(BuildContext context) {+ const placeholder = "\uFFFC";+ final strings = context.strings;+ final caption = name.isEmpty+ ? placeholder+ : strings.memoryLaneCaptionNow(name: name, now: placeholder);+ final parts = caption.trim().split(placeholder);+ return Text.rich(+ TextSpan(+ children: [+ for (var index = 0; index < parts.length; index++) ...[+ if (index > 0)+ TextSpan(+ text: strings.memoryLaneNow,+ style: TextStyle(+ color: darkTheme.textTheme.h2Bold.color,+ fontFamily: "Gochi Hand",+ package: TextStyles.fontPackage,+ fontFamilyFallback: const [TextStyles.fontFamily],+ fontWeight: FontWeight.w400,+ fontSize: 22,+ ),+ ),+ TextSpan(text: parts[index]),+ ],+ ],+ ),+ style: darkTheme.textTheme.bodyMuted,+ textAlign: TextAlign.center,+ softWrap: false,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ );+ }+}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 992c4681ae..6225bc8570 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@@ -25,6 +25,7 @@ import "package:photos/ui/home/memories/memory_music_session.dart";import "package:photos/ui/home/memories/memory_progress_indicator.dart";import "package:photos/ui/home/memories/memory_viewer_constants.dart";import "package:photos/ui/viewer/gallery/jump_to_date_gallery.dart";+import "package:photos/ui/viewer/people/memory_lane_now_caption.dart";import "package:photos/utils/dialog_util.dart";import "package:photos/utils/face/face_thumbnail_cache.dart";import "package:photos/utils/share_util.dart";@@ -418,7 +419,10 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {number: captionPlaceholder,);} else {- caption = context.strings.memoryLaneCaptionNow(name: name ?? "");+ caption = context.strings.memoryLaneCaptionNow(+ name: name ?? "",+ now: captionPlaceholder,+ );}caption = caption.trim();}@@ -758,35 +762,39 @@ class _MemoryLanePageV2State extends State<MemoryLanePageV2> {constraints: const BoxConstraints(minHeight: 48),child: Align(alignment: Alignment.bottomCenter,- child: Row(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment:- CrossAxisAlignment.baseline,- textBaseline: TextBaseline.alphabetic,- spacing: screenSize.width * 0.02,- children: [- for (- var index = 0;- index < captionParts.length;- index++- ) ...[- if (index > 0 && captionValue != null)- _MemoryLaneAnimatedDigit(- value: captionValue,- ),- Flexible(- child: Text(- captionParts[index],- style: darkTheme.textTheme.bodyMuted,- textAlign: TextAlign.center,- softWrap: false,- maxLines: 1,- overflow: TextOverflow.ellipsis,- ),+ child: captionValue == null+ ? MemoryLaneNowCaption(name: name ?? "")+ : Row(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment:+ CrossAxisAlignment.baseline,+ textBaseline: TextBaseline.alphabetic,+ spacing: screenSize.width * 0.02,+ children: [+ for (+ var index = 0;+ index < captionParts.length;+ index+++ ) ...[+ if (index > 0)+ _MemoryLaneAnimatedDigit(+ value: captionValue,+ ),+ Flexible(+ child: Text(+ captionParts[index],+ style: darkTheme+ .textTheme+ .bodyMuted,+ textAlign: TextAlign.center,+ softWrap: false,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),+ ),+ ],+ ],),- ],- ],- ),),),SizedBox(height: screenSize.height * 0.01),diff --git a/mobile/apps/photos/test/locale_test.dart b/mobile/apps/photos/test/locale_test.dartindex 3997d50f29..5e9676c607 100644--- a/mobile/apps/photos/test/locale_test.dart+++ b/mobile/apps/photos/test/locale_test.dart@@ -6,6 +6,19 @@ import 'package:photos/locale.dart';void main() {setUp(() => autoDetectedLocale = null);+ test("memory lane translations retain the styled now placeholder", () {+ for (final locale in StringsLocalizations.supportedLocales) {+ final strings = lookupStringsLocalizations(locale);+ final caption = strings.memoryLaneCaptionNow(+ name: "Ashil",+ now: "\uFFFC",+ );+ expect(caption.split("\uFFFC"), hasLength(2), reason: "$locale");+ expect(caption, contains("Ashil"), reason: "$locale");+ expect(strings.memoryLaneNow, isNotEmpty, reason: "$locale");+ }+ });+test('normalizes Portuguese variants', () {expect(_resolve(const Locale('pt')), const Locale('pt', 'BR'));expect(_resolve(const Locale('pt', 'BR')), const Locale('pt', 'BR'));diff --git a/mobile/apps/photos/test/ui/viewer/people/memory_lane_now_caption_test.dart b/mobile/apps/photos/test/ui/viewer/people/memory_lane_now_caption_test.dartnew file mode 100644index 0000000000..a33aa7f311--- /dev/null+++ b/mobile/apps/photos/test/ui/viewer/people/memory_lane_now_caption_test.dart@@ -0,0 +1,164 @@+import "package:ente_strings/ente_strings.dart";+import "package:ente_strings/l10n/strings_localizations_en.dart";+import "package:flutter/foundation.dart";+import "package:flutter/material.dart";+import "package:flutter/rendering.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/viewer/people/memory_lane_now_caption.dart";++void main() {+ testWidgets("styles only the localized time word in translated order", (+ tester,+ ) async {+ for (final (locale, name, word, beforeName, separator) in [+ (const Locale("en"), "Snow now", "now", false, " "),+ (const Locale("ar"), "Ashil", "الآن", true, " "),+ (const Locale("ja"), "アシル", "今", true, "の"),+ ]) {+ final strings = _CaptionStrings(+ locale,+ word,+ beforeName: beforeName,+ separator: separator,+ );+ await _pumpCaption(tester, name: name, strings: strings);+ final text = tester.widget<Text>(find.byType(Text));+ final span = text.textSpan! as TextSpan;+ expect(+ span.toPlainText(),+ strings.memoryLaneCaptionNow(name: name, now: word),+ );+ final timeSpan = span.children!.cast<TextSpan>().singleWhere(+ (child) => child.style != null,+ );+ expect(timeSpan.text, word);+ expect(timeSpan.style!.fontFamily, "packages/ente_components/Gochi Hand");+ expect(timeSpan.style!.fontFamilyFallback, [+ "packages/ente_components/Inter",+ ]);+ expect(timeSpan.style!.fontSize, 22);+ expect(timeSpan.style!.fontWeight, FontWeight.w400);+ expect(timeSpan.style!.color, darkTheme.textTheme.h2Bold.color);+ expect(text.style, darkTheme.textTheme.bodyMuted);+ final paragraph = tester.renderObject<RenderParagraph>(+ find.byType(RichText),+ );+ expect(+ paragraph.textDirection,+ locale.languageCode == "ar" ? TextDirection.rtl : TextDirection.ltr,+ );+ expect(tester.takeException(), isNull);+ }+ });++ testWidgets("scales captions and handles empty or long names", (+ tester,+ ) async {+ final english = _CaptionStrings(const Locale("en"), "now");+ final japanese = _CaptionStrings(+ const Locale("ja"),+ "今",+ beforeName: true,+ separator: "の",+ );+ for (final (name, strings) in [+ ("", english),+ ("", japanese),+ ("A very long person's name " * 10, english),+ ]) {+ await _pumpCaption(+ tester,+ name: name,+ strings: strings,+ width: 170,+ textScaler: const TextScaler.linear(2),+ );+ final paragraph = tester.renderObject<RenderParagraph>(+ find.byType(RichText),+ );+ expect(paragraph.textScaler.scale(22), 44);+ expect(+ paragraph.text.toPlainText(),+ name.isEmpty+ ? strings.memoryLaneNow+ : strings.memoryLaneCaptionNow(+ name: name,+ now: strings.memoryLaneNow,+ ),+ );+ expect(paragraph.didExceedMaxLines, name.isNotEmpty);+ expect(paragraph.size.width, lessThanOrEqualTo(170));+ expect(tester.takeException(), isNull);+ }+ });+}++Future<void> _pumpCaption(+ WidgetTester tester, {+ required String name,+ required _CaptionStrings strings,+ double width = 320,+ TextScaler textScaler = TextScaler.noScaling,+}) async {+ await tester.pumpWidget(+ MaterialApp(+ locale: strings.locale,+ supportedLocales: StringsLocalizations.supportedLocales,+ localizationsDelegates: [+ _CaptionStringsDelegate(strings),+ ...StringsLocalizations.localizationsDelegates,+ ],+ home: Scaffold(+ body: MediaQuery(+ data: MediaQueryData(textScaler: textScaler),+ child: Center(+ child: SizedBox(+ width: width,+ child: MemoryLaneNowCaption(name: name),+ ),+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+}++class _CaptionStringsDelegate+ extends LocalizationsDelegate<StringsLocalizations> {+ const _CaptionStringsDelegate(this.strings);++ final _CaptionStrings strings;++ @override+ bool isSupported(Locale locale) => true;++ @override+ Future<StringsLocalizations> load(Locale locale) =>+ SynchronousFuture(strings);++ @override+ bool shouldReload(_CaptionStringsDelegate old) => old.strings != strings;+}++class _CaptionStrings extends StringsLocalizationsEn {+ _CaptionStrings(+ this.locale,+ this.word, {+ this.beforeName = false,+ this.separator = " ",+ }) : super(locale.toLanguageTag());++ final Locale locale;+ final String word;+ final bool beforeName;+ final String separator;++ @override+ String get memoryLaneNow => word;++ @override+ String memoryLaneCaptionNow({required String name, required String now}) =>+ beforeName ? "$now$separator$name" : "$name$separator$now";+}diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex 14a0c9f49e..b08b65a36b 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -1508,15 +1508,23 @@}}},- "memoryLaneCaptionNow": "{name} now",+ "memoryLaneCaptionNow": "{name} {now}","@memoryLaneCaptionNow": {- "description": "Memory Lane caption for a photo taken less than a year ago, without a number.",+ "description": "Memory Lane caption for a photo taken less than a year ago, without a number. Keep both placeholders in the natural word order for your language.","placeholders": {"name": {"type": "String"+ },+ "now": {+ "type": "String",+ "description": "The localized word for now, rendered in a handwritten style. Keep this placeholder rather than writing the word directly."}}},+ "memoryLaneNow": "now",+ "@memoryLaneNow": {+ "description": "The current moment in a Memory Lane caption, such as Ashil now. This word is styled separately from the person's name."+ },"facesTimelinePlaybackPause": "Pause","@facesTimelinePlaybackPause": {"description": "Tooltip or semantics label for the pause button"