Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Show merged photos during edit person

Neeraj Guptab586957adc14
diff --git a/mobile/lib/ui/viewer/people/person_clusters_page.dart b/mobile/lib/ui/viewer/people/person_clusters_page.dart
index daf3b17304..32e8dca58a 100644
--- a/mobile/lib/ui/viewer/people/person_clusters_page.dart
+++ b/mobile/lib/ui/viewer/people/person_clusters_page.dart
@@ -1,14 +1,17 @@
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
+import "package:intl/intl.dart";
import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/people_changed_event.dart";
+import "package:photos/l10n/l10n.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/ml/face/person.dart";
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/services/search_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";
+import "package:photos/ui/viewer/gallery/hooks/add_photos_sheet.dart";
import "package:photos/ui/viewer/people/cluster_page.dart";
import "package:photos/ui/viewer/search/result/person_face_widget.dart";
@@ -147,3 +150,129 @@ class _PersonClustersPageState extends State<PersonClustersPage> {
);
}
}
+
+class PersonClustersWidget extends StatefulWidget {
+ final PersonEntity person;
+ final double? height;
+
+ const PersonClustersWidget(
+ this.person, {
+ super.key,
+ this.height,
+ });
+
+ @override
+ State<PersonClustersWidget> createState() => _PersonClustersWidgetState();
+}
+
+class _PersonClustersWidgetState extends State<PersonClustersWidget> {
+ final Logger _logger = Logger("_PersonClustersWidgetState");
+
+ @override
+ Widget build(BuildContext context) {
+ return FutureBuilder<Map<String, List<EnteFile>>>(
+ future: SearchService.instance
+ .getClusterFilesForPersonID(widget.person.remoteID),
+ builder: (context, snapshot) {
+ if (snapshot.hasData) {
+ final clusters = snapshot.data!;
+ final List<String> keys = clusters.keys.toList();
+ // Sort the clusters by the number of files in each cluster, largest first
+ keys.sort(
+ (b, a) => clusters[a]!.length.compareTo(clusters[b]!.length),
+ );
+
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ // Determine number of columns based on available width
+ // Minimum column width of 150, maximum of 250
+ double columnWidth =
+ MediaQuery.of(context).size.width > 600 ? 250 : 150;
+ final int crossAxisCount =
+ (constraints.maxWidth / columnWidth).floor().clamp(2, 5);
+
+ // Calculate expected height based on number of rows
+ final int rowCount = (keys.length / crossAxisCount).ceil();
+ // Thumbnail height + text height + spacing
+ final double expectedHeight =
+ widget.height ?? (rowCount * (110 + 30 + 8));
+
+ return SizedBox(
+ height: expectedHeight,
+ child: GridView.builder(
+ physics:
+ const NeverScrollableScrollPhysics(), // Disable scrolling
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
+ crossAxisCount: crossAxisCount,
+ childAspectRatio:
+ 1, // Adjust this to control height vs width
+ crossAxisSpacing: 8,
+ mainAxisSpacing: 8,
+ ),
+ itemCount: keys.length,
+ itemBuilder: (context, index) {
+ final String clusterID = keys[index];
+ final List<EnteFile> files = clusters[clusterID]!;
+
+ return GestureDetector(
+ onTap: () {
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => ClusterPage(
+ files,
+ personID: widget.person,
+ clusterID: clusterID,
+ showNamingBanner: false,
+ ),
+ ),
+ );
+ },
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ SizedBox(
+ width: 100,
+ height: 100,
+ child: ClipPath(
+ clipper: ShapeBorderClipper(
+ shape: ContinuousRectangleBorder(
+ borderRadius: BorderRadius.circular(75),
+ ),
+ ),
+ child: files.isNotEmpty
+ ? PersonFaceWidget(
+ files.first,
+ clusterID: clusterID,
+ )
+ : const NoThumbnailWidget(
+ addBorder: false,
+ ),
+ ),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ context.l10n.memoryCount(
+ files.length,
+ NumberFormat().format(files.length),
+ ),
+ style: getEnteTextTheme(context).small,
+ textAlign: TextAlign.center,
+ ),
+ ],
+ ),
+ );
+ },
+ ),
+ );
+ },
+ );
+ } else if (snapshot.hasError) {
+ _logger.warning("Failed to get cluster", snapshot.error);
+ return const Center(child: Text("Error"));
+ } else {
+ return const Center(child: CircularProgressIndicator());
+ }
+ },
+ );
+ }
+}
diff --git a/mobile/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/lib/ui/viewer/people/save_or_edit_person.dart
index a25c1a6aa0..ef46ff3f67 100644
--- a/mobile/lib/ui/viewer/people/save_or_edit_person.dart
+++ b/mobile/lib/ui/viewer/people/save_or_edit_person.dart
@@ -22,6 +22,7 @@ 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_clusters_page.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";
@@ -82,162 +83,192 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
),
),
),
- body: SingleChildScrollView(
- padding: const EdgeInsets.only(bottom: 16.0, left: 16.0, right: 16.0),
+ body: SafeArea(
child: Column(
children: [
- const SizedBox(height: 48),
- 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,
+ Expanded(
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.only(
+ bottom: 32.0,
+ left: 16.0,
+ right: 16.0,
+ ),
+ child: Column(
+ children: [
+ const SizedBox(height: 48),
+ 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,
+ ),
),
- 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);
- },
- ),
- ),
+ ),
+ const SizedBox(height: 36),
+ TextFormField(
+ onChanged: (value) {
+ if (_debounce?.isActive ?? false) _debounce?.cancel();
+ _debounce =
+ Timer(const Duration(milliseconds: 300), () {
+ setState(() {
+ _inputName = value;
+ });
+ });
+ },
+ initialValue: _inputName,
+ decoration: InputDecoration(
+ focusedBorder: OutlineInputBorder(
+ borderRadius:
+ const BorderRadius.all(Radius.circular(8.0)),
+ borderSide: BorderSide(
+ color: getEnteColorScheme(context).strokeMuted,
),
- ],
- );
- } else {
- return const SizedBox.shrink();
- }
- },
- ),
- if (widget.person == null)
- SizedBox(
- height: 110,
- width: 110,
- child: ClipPath(
- clipper: ShapeBorderClipper(
- shape: ContinuousRectangleBorder(
- borderRadius: BorderRadius.circular(80),
+ ),
+ fillColor: getEnteColorScheme(context).fillFaint,
+ filled: true,
+ hintText: context.l10n.enterName,
+ hintStyle: getEnteTextTheme(context).bodyFaint,
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 14,
+ ),
+ border: UnderlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ ),
),
- ),
- child: widget.file != null
- ? PersonFaceWidget(
- widget.file!,
- clusterID: widget.clusterID,
- )
- : const NoThumbnailWidget(
- addBorder: false,
+ const SizedBox(height: 16),
+ DatePickerField(
+ 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: !changed,
+ onTap: () async {
+ if (widget.isEditing) {
+ await updatePerson(context);
+ } else {
+ await addNewPerson(
+ context,
+ text: _inputName,
+ clusterID: widget.clusterID!,
+ );
+ }
+ },
+ ),
+ const SizedBox(height: 32),
+ if (!widget.isEditing) _getPersonItems(),
+ if (widget.isEditing)
+ Align(
+ alignment: Alignment.centerLeft,
+ child: Text(
+ "Merged photos",
+ style: getEnteTextTheme(context).body,
),
+ ),
+ if (widget.isEditing)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 12.0, top: 24.0),
+ child: PersonClustersWidget(widget.person!),
+ ),
+ ],
),
),
- const SizedBox(height: 36),
- TextFormField(
- onChanged: (value) {
- if (_debounce?.isActive ?? false) _debounce?.cancel();
- _debounce = Timer(const Duration(milliseconds: 300), () {
- setState(() {
- _inputName = value;
- });
- });
- },
- initialValue: _inputName,
- decoration: InputDecoration(
- focusedBorder: OutlineInputBorder(
- borderRadius: const BorderRadius.all(Radius.circular(8.0)),
- borderSide: BorderSide(
- color: getEnteColorScheme(context).strokeMuted,
- ),
- ),
- fillColor: getEnteColorScheme(context).fillFaint,
- filled: true,
- hintText: context.l10n.enterName,
- hintStyle: getEnteTextTheme(context).bodyFaint,
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 14,
- ),
- border: UnderlineInputBorder(
- borderSide: BorderSide.none,
- borderRadius: BorderRadius.circular(8),
- ),
- ),
- ),
- const SizedBox(height: 16),
- DatePickerField(
- 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: !changed,
- onTap: () async {
- if (widget.isEditing) {
- await updatePerson(context);
- } else {
- await addNewPerson(
- context,
- text: _inputName,
- clusterID: widget.clusterID!,
- );
- }
- },
),
- const SizedBox(height: 32),
- if (!widget.isEditing) _getPersonItems(),
],
),
),