π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Support for editing person birthdate and cover
Neeraj Gupta5f60db24ead0
diff --git a/mobile/lib/generated/intl/messages_en.dart b/mobile/lib/generated/intl/messages_en.dartindex 370a855bdb..29cbb1ba4e 100644--- a/mobile/lib/generated/intl/messages_en.dart+++ b/mobile/lib/generated/intl/messages_en.dart@@ -696,6 +696,7 @@ class MessageLookup extends MessageLookupByLibrary {"editLocation": MessageLookupByLibrary.simpleMessage("Edit location"),"editLocationTagTitle":MessageLookupByLibrary.simpleMessage("Edit location"),+ "editPerson": MessageLookupByLibrary.simpleMessage("Edit person"),"editsSaved": MessageLookupByLibrary.simpleMessage("Edits saved"),"editsToLocationWillOnlyBeSeenWithinEnte":MessageLookupByLibrary.simpleMessage(diff --git a/mobile/lib/generated/l10n.dart b/mobile/lib/generated/l10n.dartindex 99d63d56bf..e90b662bfb 100644--- a/mobile/lib/generated/l10n.dart+++ b/mobile/lib/generated/l10n.dart@@ -9026,6 +9026,16 @@ class S {);}+ /// `Edit person`+ String get editPerson {+ return Intl.message(+ 'Edit person',+ name: 'editPerson',+ desc: '',+ args: [],+ );+ }+/// `Or merge with existing`String get orMergeWithExistingPerson {return Intl.message(diff --git a/mobile/lib/l10n/intl_en.arb b/mobile/lib/l10n/intl_en.arbindex 4c1cc42249..71ced0a99f 100644--- a/mobile/lib/l10n/intl_en.arb+++ b/mobile/lib/l10n/intl_en.arb@@ -1266,6 +1266,7 @@"enterPersonName": "Enter person name","enterName": "Enter name","savePerson": "Save person",+ "editPerson": "Edit person","orMergeWithExistingPerson" : "Or merge with existing","enterDateOfBirth": "Birthday (optional)","birthday": "Birthday",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 98d385142f..18bc07a38e 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@@ -306,7 +306,7 @@ class PersonService {return changed;}- Future<void> updateAvatar(PersonEntity p, EnteFile file) async {+ Future<PersonEntity> updateAvatar(PersonEntity p, EnteFile file) async {final Face? face = await MLDataDB.instance.getCoverFaceForPerson(recentFileID: file.uploadedFileID!,personID: p.remoteID,@@ -322,6 +322,7 @@ class PersonService {data: person.data.copyWith(avatarFaceId: face.faceID),);await _updatePerson(updatedPerson);+ return updatedPerson;}Future<PersonEntity> updateAttributes(diff --git a/mobile/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart b/mobile/lib/ui/viewer/gallery/hooks/pick_person_avatar.dartnew file mode 100644index 0000000000..582399c7e4--- /dev/null+++ b/mobile/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart@@ -0,0 +1,194 @@+import "dart:math";++import "package:flutter/material.dart";+import "package:modal_bottom_sheet/modal_bottom_sheet.dart";+import "package:photos/generated/l10n.dart";+import "package:photos/models/file/file.dart";+import "package:photos/models/file_load_result.dart";+import "package:photos/models/ml/face/person.dart";+import "package:photos/models/selected_files.dart";+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/search_service.dart";+import "package:photos/theme/colors.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/components/bottom_of_title_bar_widget.dart";+import "package:photos/ui/components/buttons/button_widget.dart";+import "package:photos/ui/components/models/button_type.dart";+import "package:photos/ui/components/title_bar_title_widget.dart";+import "package:photos/ui/viewer/gallery/gallery.dart";+import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";++Future<dynamic?> showPersonAvatarPhotoSheet(+ BuildContext context,+ PersonEntity person,+) async {+ return await showBarModalBottomSheet(+ context: context,+ builder: (context) {+ return PickPersonCoverPhotoWidget(person);+ },+ shape: const RoundedRectangleBorder(+ side: BorderSide(width: 0),+ borderRadius: BorderRadius.vertical(+ top: Radius.circular(5),+ ),+ ),+ topControl: const SizedBox.shrink(),+ backgroundColor: getEnteColorScheme(context).backgroundElevated,+ barrierColor: backdropFaintDark,+ enableDrag: false,+ );+}++class PickPersonCoverPhotoWidget extends StatelessWidget {+ final PersonEntity personEntity;++ const PickPersonCoverPhotoWidget(+ this.personEntity, {+ super.key,+ });++ Future<FileLoadResult> loadPersonFiles() async {+ final result = await SearchService.instance+ .getClusterFilesForPersonID(personEntity.remoteID);++ final List<EnteFile> resultFiles = [];+ for (final e in result.entries) {+ resultFiles.addAll(e.value);+ }+ final List<EnteFile> sortedFiles = List<EnteFile>.from(resultFiles);+ sortedFiles.sort((a, b) => b.creationTime!.compareTo(a.creationTime!));++ return FileLoadResult(sortedFiles, false);+ }++ @override+ Widget build(BuildContext context) {+ final ValueNotifier<bool> isFileSelected = ValueNotifier(false);+ final selectedFiles = SelectedFiles();+ selectedFiles.addListener(() {+ isFileSelected.value = selectedFiles.files.isNotEmpty;+ });++ return Padding(+ padding: const EdgeInsets.all(0),+ child: Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ ConstrainedBox(+ constraints: BoxConstraints(+ maxWidth: min(428, MediaQuery.of(context).size.width),+ ),+ child: Padding(+ padding: const EdgeInsets.fromLTRB(0, 32, 0, 8),+ child: Column(+ mainAxisSize: MainAxisSize.max,+ children: [+ Expanded(+ child: Column(+ children: [+ BottomOfTitleBarWidget(+ title: const TitleBarTitleWidget(+ title: "Select cover photo",+ ),+ caption: personEntity.data.name,+ showCloseButton: true,+ ),+ Expanded(+ child: GalleryFilesState(+ child: Gallery(+ asyncLoader: (+ creationStartTime,+ creationEndTime, {+ limit,+ asc,+ }) async {+ final FileLoadResult result =+ await loadPersonFiles();++ return result;+ },+ // reloadEvent: Bus.instance+ // .on<CollectionUpdatedEvent>()+ // .where(+ // (event) =>+ // event.collectionID == collection.id,+ // ),+ tagPrefix: "pick_center_point_gallery",+ selectedFiles: selectedFiles,+ limitSelectionToOne: true,+ showSelectAllByDefault: false,+ ),+ ),+ ),+ ],+ ),+ ),+ SafeArea(+ child: Container(+ //inner stroke of 1pt + 15 pts of top padding = 16 pts+ padding: const EdgeInsets.fromLTRB(16, 15, 16, 8),+ decoration: BoxDecoration(+ border: Border(+ top: BorderSide(+ color: getEnteColorScheme(context).strokeFaint,+ ),+ ),+ ),+ child: Column(+ children: [+ ValueListenableBuilder(+ valueListenable: isFileSelected,+ builder: (context, bool value, _) {+ return AnimatedSwitcher(+ duration: const Duration(milliseconds: 300),+ switchInCurve: Curves.easeInOutExpo,+ switchOutCurve: Curves.easeInOutExpo,+ child: ButtonWidget(+ key: ValueKey(value),+ isDisabled: !value,+ buttonType: ButtonType.neutral,+ labelText: S.of(context).useSelectedPhoto,+ onTap: () async {+ final selectedFile =+ selectedFiles.files.first;+ final result = await PersonService.instance+ .updateAvatar(+ personEntity,+ selectedFile,+ );+ Navigator.pop(context, result);+ },+ ),+ );+ },+ ),+ const SizedBox(height: 8),+ ButtonWidget(+ buttonType: ButtonType.secondary,+ buttonAction: ButtonAction.cancel,+ labelText: S.of(context).cancel,+ // labelText: collection.hasCover+ // ? S.of(context).resetToDefault+ // : S.of(context).cancel,+ icon: null,+ // icon: collection.hasCover+ // ? Icons.restore_outlined+ // : null,+ onTap: () async {+ Navigator.of(context).pop();+ },+ ),+ ],+ ),+ ),+ ),+ ],+ ),+ ),+ ),+ ],+ ),+ );+ }+}diff --git a/mobile/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/lib/ui/viewer/people/save_or_edit_person.dartindex 90c461529c..a25c1a6aa0 100644--- a/mobile/lib/ui/viewer/people/save_or_edit_person.dart+++ b/mobile/lib/ui/viewer/people/save_or_edit_person.dart@@ -6,6 +6,7 @@ import "package:flutter/material.dart";import "package:logging/logging.dart";import "package:photos/core/event_bus.dart";import "package:photos/db/ml/db.dart";+import "package:photos/ente_theme_data.dart";import "package:photos/events/people_changed_event.dart";import "package:photos/generated/l10n.dart";import "package:photos/l10n/l10n.dart";@@ -20,6 +21,7 @@ import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/components/buttons/button_widget.dart";import "package:photos/ui/components/models/button_type.dart";import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";+import "package:photos/ui/viewer/gallery/hooks/pick_person_avatar.dart";import "package:photos/ui/viewer/people/person_row_item.dart";import "package:photos/ui/viewer/search/result/person_face_widget.dart";import "package:photos/utils/dialog_util.dart";@@ -74,7 +76,9 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {title: Align(alignment: Alignment.centerLeft,child: Text(- context.l10n.savePerson,+ widget.isEditing+ ? context.l10n.editPerson+ : context.l10n.savePerson,),),),@@ -83,25 +87,92 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {child: Column(children: [const SizedBox(height: 48),- SizedBox(- height: 110,- width: 110,- child: ClipPath(- clipper: ShapeBorderClipper(- shape: ContinuousRectangleBorder(- borderRadius: BorderRadius.circular(80),+ if (widget.person != null)+ FutureBuilder<(String, EnteFile)>(+ future: _getRecentFileWithClusterID(widget.person!),+ builder: (context, snapshot) {+ if (snapshot.hasData) {+ final String personClusterID = snapshot.data!.$1;+ final personFile = snapshot.data!.$2;+ return Stack(+ children: [+ SizedBox(+ height: 110,+ width: 110,+ child: ClipPath(+ clipper: ShapeBorderClipper(+ shape: ContinuousRectangleBorder(+ borderRadius: BorderRadius.circular(80),+ ),+ ),+ child: snapshot.hasData+ ? PersonFaceWidget(+ personFile,+ clusterID: personClusterID,+ personId: widget.person!.remoteID,+ )+ : const NoThumbnailWidget(+ addBorder: false,+ ),+ ),+ ),+ if (widget.person != null)+ Positioned(+ right: 0,+ bottom: 0,+ child: Container(+ width: 28,+ height: 28,+ decoration: BoxDecoration(+ borderRadius: BorderRadius.circular(8.0),+ boxShadow: Theme.of(context)+ .colorScheme+ .enteTheme+ .shadowMenu,+ color: getEnteColorScheme(context)+ .backgroundElevated2,+ ),+ child: IconButton(+ icon: const Icon(Icons.edit),+ iconSize: 16, // specify the size of the icon+ onPressed: () async {+ await showPersonAvatarPhotoSheet(+ context,+ widget.person!,+ );+ // if (person != null) {+ Navigator.pop(context);+ },+ ),+ ),+ ),+ ],+ );+ } else {+ return const SizedBox.shrink();+ }+ },+ ),+ if (widget.person == null)+ SizedBox(+ height: 110,+ width: 110,+ child: ClipPath(+ clipper: ShapeBorderClipper(+ shape: ContinuousRectangleBorder(+ borderRadius: BorderRadius.circular(80),+ ),),+ child: widget.file != null+ ? PersonFaceWidget(+ widget.file!,+ clusterID: widget.clusterID,+ )+ : const NoThumbnailWidget(+ addBorder: false,+ ),),- child: widget.file != null- ? PersonFaceWidget(- widget.file!,- clusterID: widget.clusterID,- )- : const NoThumbnailWidget(- addBorder: false,- ),),- ),const SizedBox(height: 36),TextFormField(onChanged: (value) {@@ -355,4 +426,20 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {}return personAndFileID;}++ Future<(String, EnteFile)> _getRecentFileWithClusterID(+ PersonEntity person) async {+ final clustersToFiles =+ await SearchService.instance.getClusterFilesForPersonID(+ person.remoteID,+ );+ final files = clustersToFiles.values.expand((e) => e).toList();+ if (files.isEmpty) {+ debugPrint(+ "Person ${kDebugMode ? person.data.name : person.remoteID} has no files",+ );+ return ("", EnteFile());+ }+ return (person.remoteID, files.first);+ }}