Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): person birthday viewing/editing (#20731)

Brandon Wees325d5f7ba9e9
diff --git a/i18n/en.json b/i18n/en.json
index 3c730b35eb..d953f25c8a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -833,7 +833,7 @@
"edit": "Edit",
"edit_album": "Edit album",
"edit_avatar": "Edit avatar",
- "edit_birthday": "Edit Birthday",
+ "edit_birthday": "Edit birthday",
"edit_date": "Edit date",
"edit_date_and_time": "Edit date and time",
"edit_date_and_time_action_prompt": "{count} date and time edited",
@@ -1007,9 +1007,6 @@
"exif_bottom_sheet_location": "LOCATION",
"exif_bottom_sheet_people": "PEOPLE",
"exif_bottom_sheet_person_add_person": "Add name",
- "exif_bottom_sheet_person_age_months": "Age {months} months",
- "exif_bottom_sheet_person_age_year_months": "Age 1 year, {months} months",
- "exif_bottom_sheet_person_age_years": "Age {years}",
"exit_slideshow": "Exit Slideshow",
"expand_all": "Expand all",
"experimental_settings_new_asset_list_subtitle": "Work in progress",
@@ -1448,6 +1445,9 @@
"permission_onboarding_permission_limited": "Permission limited. To let Immich backup and manage your entire gallery collection, grant photo and video permissions in Settings.",
"permission_onboarding_request": "Immich requires permission to view your photos and videos.",
"person": "Person",
+ "person_age_months": "{months} months old",
+ "person_age_year_months": "1 year, {months} months old",
+ "person_age_years": "{years} years old",
"person_birthdate": "Born on {date}",
"person_hidden": "{name}{hidden, select, true { (hidden)} other {}}",
"photo_shared_all_users": "Looks like you shared your photos with all users or you don't have any user to share with.",
diff --git a/mobile/lib/presentation/pages/drift_person.page.dart b/mobile/lib/presentation/pages/drift_person.page.dart
index f3146505ae..ebd4954a51 100644
--- a/mobile/lib/presentation/pages/drift_person.page.dart
+++ b/mobile/lib/presentation/pages/drift_person.page.dart
@@ -64,6 +64,7 @@ class _DriftPersonPageState extends ConsumerState<DriftPersonPage> {
await handleEditBirthday(context);
context.pop();
},
+ birthdayExists: _person.birthDate != null,
);
},
);
diff --git a/mobile/lib/presentation/widgets/people/person_edit_birthday_modal.widget.dart b/mobile/lib/presentation/widgets/people/person_edit_birthday_modal.widget.dart
index 8d05244617..8813224a5f 100644
--- a/mobile/lib/presentation/widgets/people/person_edit_birthday_modal.widget.dart
+++ b/mobile/lib/presentation/widgets/people/person_edit_birthday_modal.widget.dart
@@ -63,7 +63,6 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonBirthdayEdi
height: 300,
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
-
child: ScrollDatePicker(
options: DatePickerOptions(
backgroundColor: context.colorScheme.surfaceContainerHigh,
@@ -72,14 +71,17 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonBirthdayEdi
),
scrollViewOptions: DatePickerScrollViewOptions(
day: ScrollViewDetailOptions(
+ isLoop: false,
margin: const EdgeInsets.all(12),
selectedTextStyle: TextStyle(color: context.primaryColor, fontWeight: FontWeight.bold, fontSize: 16),
),
month: ScrollViewDetailOptions(
+ isLoop: false,
margin: const EdgeInsets.all(12),
selectedTextStyle: TextStyle(color: context.primaryColor, fontWeight: FontWeight.bold, fontSize: 16),
),
year: ScrollViewDetailOptions(
+ isLoop: false,
margin: const EdgeInsets.all(12),
selectedTextStyle: TextStyle(color: context.primaryColor, fontWeight: FontWeight.bold, fontSize: 16),
),
diff --git a/mobile/lib/presentation/widgets/people/person_option_sheet.widget.dart b/mobile/lib/presentation/widgets/people/person_option_sheet.widget.dart
index 6d46b37761..b374d48417 100644
--- a/mobile/lib/presentation/widgets/people/person_option_sheet.widget.dart
+++ b/mobile/lib/presentation/widgets/people/person_option_sheet.widget.dart
@@ -3,10 +3,11 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/translate_extensions.dart';
class PersonOptionSheet extends ConsumerWidget {
- const PersonOptionSheet({super.key, this.onEditName, this.onEditBirthday});
+ const PersonOptionSheet({super.key, this.onEditName, this.onEditBirthday, this.birthdayExists = false});
final VoidCallback? onEditName;
final VoidCallback? onEditBirthday;
+ final bool birthdayExists;
@override
Widget build(BuildContext context, WidgetRef ref) {
@@ -25,7 +26,7 @@ class PersonOptionSheet extends ConsumerWidget {
),
ListTile(
leading: const Icon(Icons.cake),
- title: Text('edit_birthday'.t(context: context), style: textStyle),
+ title: Text((birthdayExists ? 'edit_birthday' : "add_birthday").t(context: context), style: textStyle),
onTap: onEditBirthday,
),
],
diff --git a/mobile/lib/utils/people.utils.dart b/mobile/lib/utils/people.utils.dart
index 1b0a81a8cc..ddd1867269 100644
--- a/mobile/lib/utils/people.utils.dart
+++ b/mobile/lib/utils/people.utils.dart
@@ -9,11 +9,11 @@ String formatAge(DateTime birthDate, DateTime referenceDate) {
int ageInMonths = _calculateAgeInMonths(birthDate, referenceDate);
if (ageInMonths <= 11) {
- return "exif_bottom_sheet_person_age_months".t(args: {'months': ageInMonths.toString()});
+ return "person_age_months".t(args: {'months': ageInMonths.toString()});
} else if (ageInMonths > 12 && ageInMonths <= 23) {
- return "exif_bottom_sheet_person_age_year_months".t(args: {'months': (ageInMonths - 12).toString()});
+ return "person_age_year_months".t(args: {'months': (ageInMonths - 12).toString()});
} else {
- return "exif_bottom_sheet_person_age_years".t(args: {'years': ageInYears.toString()});
+ return "person_age_years".t(args: {'years': ageInYears.toString()});
}
}
diff --git a/mobile/lib/widgets/asset_viewer/detail_panel/people_info.dart b/mobile/lib/widgets/asset_viewer/detail_panel/people_info.dart
index b2aa50493c..b96cbc777d 100644
--- a/mobile/lib/widgets/asset_viewer/detail_panel/people_info.dart
+++ b/mobile/lib/widgets/asset_viewer/detail_panel/people_info.dart
@@ -7,6 +7,7 @@ import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/models/search/search_curated_content.model.dart';
import 'package:immich_mobile/providers/asset_viewer/asset_people.provider.dart';
import 'package:immich_mobile/routing/router.dart';
+import 'package:immich_mobile/utils/people.utils.dart';
import 'package:immich_mobile/widgets/search/curated_people_row.dart';
import 'package:immich_mobile/widgets/search/person_name_edit_form.dart';
@@ -41,7 +42,7 @@ class PeopleInfo extends ConsumerWidget {
id: p.id,
label: p.name,
subtitle: p.birthDate != null && p.birthDate!.isBefore(asset.fileCreatedAt)
- ? _formatAge(p.birthDate!, asset.fileCreatedAt)
+ ? formatAge(p.birthDate!, asset.fileCreatedAt)
: null,
),
)
@@ -87,33 +88,4 @@ class PeopleInfo extends ConsumerWidget {
),
);
}
-
- String _formatAge(DateTime birthDate, DateTime referenceDate) {
- int ageInYears = _calculateAge(birthDate, referenceDate);
- int ageInMonths = _calculateAgeInMonths(birthDate, referenceDate);
-
- if (ageInMonths <= 11) {
- return "exif_bottom_sheet_person_age_months".tr(namedArgs: {'months': ageInMonths.toString()});
- } else if (ageInMonths > 12 && ageInMonths <= 23) {
- return "exif_bottom_sheet_person_age_year_months".tr(namedArgs: {'months': (ageInMonths - 12).toString()});
- } else {
- return "exif_bottom_sheet_person_age_years".tr(namedArgs: {'years': ageInYears.toString()});
- }
- }
-
- int _calculateAge(DateTime birthDate, DateTime referenceDate) {
- int age = referenceDate.year - birthDate.year;
- if (referenceDate.month < birthDate.month ||
- (referenceDate.month == birthDate.month && referenceDate.day < birthDate.day)) {
- age--;
- }
- return age;
- }
-
- int _calculateAgeInMonths(DateTime birthDate, DateTime referenceDate) {
- return (referenceDate.year - birthDate.year) * 12 +
- referenceDate.month -
- birthDate.month -
- (referenceDate.day < birthDate.day ? 1 : 0);
- }
}