π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob]Support for editing name/birthday for person
Neeraj Gupta5590f72b122b
diff --git a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/lib/services/machine_learning/face_ml/person/person_service.dartindex 91c0c8d087..98d385142f 100644--- a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart+++ b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart@@ -324,7 +324,7 @@ class PersonService {await _updatePerson(updatedPerson);}- Future<void> updateAttributes(+ Future<PersonEntity> updateAttributes(String id, {String? name,String? avatarFaceId,@@ -343,6 +343,7 @@ class PersonService {),);await _updatePerson(updatedPerson);+ return updatedPerson;}Future<void> _updatePerson(PersonEntity updatePerson) async {diff --git a/mobile/lib/ui/common/date_input.dart b/mobile/lib/ui/common/date_input.dartindex 0a6a5067ef..41fbccb76a 100644--- a/mobile/lib/ui/common/date_input.dart+++ b/mobile/lib/ui/common/date_input.dart@@ -29,17 +29,21 @@ class _DatePickerFieldState extends State<DatePickerField> {final TextEditingController _controller = TextEditingController();DateTime? _selectedDate;bool _hasError = false;+ bool isUSLocale = false;@overridevoid initState() {super.initState();if (widget.initialValue != null) {_controller.text = widget.initialValue!;- _tryParseDate(widget.initialValue!).ignore();+ _tryParseDate(widget.initialValue!, initialParse: true).ignore();}}- Future<void> _tryParseDate(String value) async {+ Future<void> _tryParseDate(String value, {bool initialParse = false}) async {+ Locale? locale = await getLocale();+ locale ??= const Locale('en', 'US');+ isUSLocale = locale.toString().toLowerCase().contains('us');// If the field is empty and not required, reset error state and clear dateif (value.isEmpty && !widget.isRequired) {setState(() {@@ -56,22 +60,19 @@ class _DatePickerFieldState extends State<DatePickerField> {}try {- Locale? locale = await getLocale();- locale ??= const Locale('en', 'US');// Try parsing different date formatsDateTime? parsed;- final List<String> formats =- (locale.toString().toLowerCase().contains('us'))- ? [- 'MM/dd/yyyy',- 'MM-dd-yyyy',- 'YYYY-MM-dd',- ]- : [- 'dd/MM/yyyy',- 'dd-MM-yyyy',- 'yyyy-dd-MM',- ];+ final List<String> formats = isUSLocale+ ? [+ 'MM/dd/yyyy',+ 'MM-dd-yyyy',+ 'yyyy-MM-dd', // Corrected format+ ]+ : [+ 'dd/MM/yyyy',+ 'dd-MM-yyyy',+ 'yyyy-MM-dd', // Corrected format+ ];for (String format in formats) {try {@@ -98,6 +99,11 @@ class _DatePickerFieldState extends State<DatePickerField> {});if (isValid) {+ if (initialParse) {+ _controller.text = isUSLocale+ ? DateFormat('MM-dd-yyyy').format(parsed)+ : DateFormat('dd-MM-yyyy').format(parsed);+ }widget.onChanged?.call(parsed);}} else {@@ -126,7 +132,9 @@ class _DatePickerFieldState extends State<DatePickerField> {setState(() {_selectedDate = picked;_hasError = false;- _controller.text = DateFormat('MM/dd/yyyy').format(picked);+ _controller.text = isUSLocale+ ? DateFormat('MM-dd-yyyy').format(picked)+ : DateFormat('dd-MM-yyyy').format(picked);});widget.onChanged?.call(picked);}diff --git a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart b/mobile/lib/ui/viewer/people/add_person_action_sheet.dartindex 5fa1cf97ad..314d70e51d 100644--- a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart+++ b/mobile/lib/ui/viewer/people/add_person_action_sheet.dart@@ -2,7 +2,7 @@ import "dart:async";import 'package:flutter/material.dart';import "package:photos/models/file/file.dart";-import "package:photos/ui/viewer/people/save_person.dart";+import "package:photos/ui/viewer/people/save_or_edit_person.dart";import "package:photos/utils/navigation_util.dart";Future<dynamic> showAssignPersonAction(@@ -13,7 +13,7 @@ Future<dynamic> showAssignPersonAction(}) async {return routeToPage(context,- SavePerson(+ SaveOrEditPerson(clusterID,file: file,),diff --git a/mobile/lib/ui/viewer/people/people_app_bar.dart b/mobile/lib/ui/viewer/people/people_app_bar.dartindex cf88e60b59..6a5e4b49de 100644--- a/mobile/lib/ui/viewer/people/people_app_bar.dart+++ b/mobile/lib/ui/viewer/people/people_app_bar.dart@@ -22,6 +22,7 @@ import "package:photos/ui/viewer/hierarchicial_search/recommended_filters_for_apimport "package:photos/ui/viewer/people/add_person_action_sheet.dart";import "package:photos/ui/viewer/people/people_page.dart";import "package:photos/ui/viewer/people/person_cluster_suggestion.dart";+import "package:photos/ui/viewer/people/save_or_edit_person.dart";import "package:photos/utils/dialog_util.dart";import "package:photos/utils/navigation_util.dart";@@ -62,6 +63,7 @@ class _AppBarWidgetState extends State<PeopleAppBar> {final GlobalKey shareButtonKey = GlobalKey();bool isQuickLink = false;late GalleryType galleryType;+ late PersonEntity person;@overridevoid initState() {@@ -75,6 +77,7 @@ class _AppBarWidgetState extends State<PeopleAppBar> {Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {setState(() {});});+ person = widget.person;_appBarTitle = widget.title;galleryType = widget.type;}@@ -143,37 +146,19 @@ class _AppBarWidgetState extends State<PeopleAppBar> {);}- Future<dynamic> _renamePerson(BuildContext context) async {- final result = await showTextInputDialog(+ Future<dynamic> _editPerson(BuildContext context) async {+ final result = await routeToPage(context,- title: S.of(context).rename,- submitButtonLabel: S.of(context).done,- hintText: S.of(context).enterPersonName,- alwaysShowSuccessState: true,- initialValue: widget.person.data.name,- textCapitalization: TextCapitalization.words,- onSubmit: (String text) async {- // indicates user cancelled the rename request- if (text == "" || text == _appBarTitle!) {- return;- }-- try {- await PersonService.instance- .updateAttributes(widget.person.remoteID, name: text);- if (mounted) {- _appBarTitle = text;- setState(() {});- }- Bus.instance.fire(PeopleChangedEvent());- } catch (e, s) {- _logger.severe("Failed to rename album", e, s);- rethrow;- }- },+ SaveOrEditPerson(+ person.data.assigned?.first.id ?? "",+ person: person,+ isEditing: true,+ ),);- if (result is Exception) {- await showGenericErrorDialog(context: context, error: result);+ if (result is PersonEntity) {+ _appBarTitle = result.data.name;+ person = result;+ setState(() {});}}@@ -259,13 +244,12 @@ class _AppBarWidgetState extends State<PeopleAppBar> {unawaited(Navigator.of(context).push(MaterialPageRoute(- builder: (context) =>- PersonReviewClusterSuggestion(widget.person),+ builder: (context) => PersonReviewClusterSuggestion(person),),),);} else if (value == PeoplePopupAction.rename) {- await _renamePerson(context);+ await _editPerson(context);} else if (value == PeoplePopupAction.setCover) {await setCoverPhoto(context);} else if (value == PeoplePopupAction.unignore) {@@ -289,7 +273,7 @@ class _AppBarWidgetState extends State<PeopleAppBar> {firstButtonLabel: S.of(context).yesResetPerson,firstButtonOnTap: () async {try {- await PersonService.instance.deletePerson(widget.person.remoteID);+ await PersonService.instance.deletePerson(person.remoteID);Navigator.of(context).pop();} catch (e, s) {_logger.severe('Resetting person failed', e, s);diff --git a/mobile/lib/ui/viewer/people/save_person.dart b/mobile/lib/ui/viewer/people/save_or_edit_person.dartsimilarity index 82%rename from mobile/lib/ui/viewer/people/save_person.dartrename to mobile/lib/ui/viewer/people/save_or_edit_person.dartindex 5bb5028e81..90c461529c 100644--- a/mobile/lib/ui/viewer/people/save_person.dart+++ b/mobile/lib/ui/viewer/people/save_or_edit_person.dart@@ -25,30 +25,41 @@ import "package:photos/ui/viewer/search/result/person_face_widget.dart";import "package:photos/utils/dialog_util.dart";import "package:photos/utils/toast_util.dart";-class SavePerson extends StatefulWidget {- final String clusterID;+class SaveOrEditPerson extends StatefulWidget {+ final String? clusterID;final EnteFile? file;final bool isEditing;+ final PersonEntity? person;- const SavePerson(+ const SaveOrEditPerson(this.clusterID, {super.key,this.file,+ this.person,this.isEditing = false,- });+ }) : assert(+ !isEditing || person != null, 'Person cannot be null when editing');@override- State<SavePerson> createState() => _SavePersonState();+ State<SaveOrEditPerson> createState() => _SaveOrEditPersonState();}-class _SavePersonState extends State<SavePerson> {+class _SaveOrEditPersonState extends State<SaveOrEditPerson> {bool isKeypadOpen = false;String _inputName = "";+ String? _selectedDate;bool userAlreadyAssigned = false;late final Logger _logger = Logger("_SavePersonState");Timer? _debounce;List<(PersonEntity, EnteFile)> _cachedPersons = [];+ @override+ void initState() {+ super.initState();+ _inputName = widget.person?.data.name ?? "";+ _selectedDate = widget.person?.data.birthDate;+ }+@overridevoid dispose() {_debounce?.cancel();@@ -101,6 +112,7 @@ class _SavePersonState extends State<SavePerson> {});});},+ initialValue: _inputName,decoration: InputDecoration(focusedBorder: OutlineInputBorder(borderRadius: const BorderRadius.all(Radius.circular(8.0)),@@ -127,23 +139,34 @@ class _SavePersonState extends State<SavePerson> {hintText: context.l10n.enterDateOfBirth,firstDate: DateTime(100),lastDate: DateTime.now(),+ initialValue: _selectedDate,isRequired: false,+ onChanged: (date) {+ setState(() {+ // format date to yyyy-MM-dd+ _selectedDate = date?.toIso8601String().split("T").first;+ });+ },),const SizedBox(height: 32),ButtonWidget(buttonType: ButtonType.primary,labelText: context.l10n.save,- isDisabled: _inputName.isEmpty,+ isDisabled: !changed,onTap: () async {- await addNewPerson(- context,- text: _inputName,- clusterID: widget.clusterID,- );+ if (widget.isEditing) {+ await updatePerson(context);+ } else {+ await addNewPerson(+ context,+ text: _inputName,+ clusterID: widget.clusterID!,+ );+ }},),const SizedBox(height: 32),- _getPersonItems(),+ if (!widget.isEditing) _getPersonItems(),],),),@@ -221,7 +244,7 @@ class _SavePersonState extends State<SavePerson> {userAlreadyAssigned = true;await MLDataDB.instance.assignClusterToPerson(personID: person.$1.remoteID,- clusterID: widget.clusterID,+ clusterID: widget.clusterID!,);Bus.instance.fire(PeopleChangedEvent());@@ -285,6 +308,29 @@ class _SavePersonState extends State<SavePerson> {}}+ bool get changed => widget.isEditing+ ? (_inputName.trim() != widget.person!.data.name ||+ _selectedDate != widget.person!.data.birthDate)+ : _inputName.trim().isNotEmpty;++ Future<void> updatePerson(BuildContext context) async {+ try {+ final String name = _inputName.trim();+ final String? birthDate = _selectedDate;+ final personEntity = await PersonService.instance.updateAttributes(+ widget.person!.remoteID,+ name: name,+ birthDate: birthDate,+ );++ Bus.instance.fire(PeopleChangedEvent());+ Navigator.pop(context, personEntity);+ } catch (e) {+ _logger.severe("Error adding updating person", e);+ await showGenericErrorDialog(context: context, error: e);+ }+ }+Future<List<(PersonEntity, EnteFile)>> _getPersonsWithRecentFile({bool excludeHidden = true,}) async {