π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Redesign save or merge cluster banner
laurenspriema16f8fad7908
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dartindex 380b6fb655..af0f9d9eb9 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hierarchical_search_gallery.dart@@ -13,15 +13,18 @@ import "package:photos/models/ml/face/person.dart";import "package:photos/models/search/hierarchical/face_filter.dart";import "package:photos/models/search/hierarchical/hierarchical_search_filter.dart";import "package:photos/models/selected_files.dart";+import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/viewer/gallery/gallery.dart";import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";import "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dart";import "package:photos/ui/viewer/gallery/state/search_filter_data_provider.dart";import "package:photos/ui/viewer/people/add_person_action_sheet.dart";-import "package:photos/ui/viewer/people/people_banner.dart";+import "package:photos/ui/viewer/people/merge_clusters_to_person_sheet.dart";import "package:photos/ui/viewer/people/people_page.dart";import "package:photos/ui/viewer/people/person_face_widget.dart";+import "package:photos/ui/viewer/people/save_person_banner.dart";import "package:photos/utils/hierarchical_search_util.dart";class HierarchicalSearchGallery extends StatefulWidget {@@ -46,6 +49,7 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {int _filteredFilesVersion = 0;final _isLoading = ValueNotifier<bool>(true);FaceFilter? _firstUnnamedAppliedFaceFilter;+ String? _dismissedClusterId;@overridevoid initState() {@@ -120,6 +124,72 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {_filteredFilesVersion++;}+ Future<void> _handleSavePerson() async {+ final clusterId = _firstUnnamedAppliedFaceFilter?.clusterId;+ if (clusterId == null || clusterId.isEmpty) {+ return;+ }+ final result = await showAssignPersonAction(+ context,+ clusterID: clusterId,+ );+ if (!mounted) {+ return;+ }+ Navigator.of(context).pop();+ if (result != null) {+ final person = result is (PersonEntity, EnteFile) ? result.$1 : result;+ // ignore: unawaited_futures+ routeToPage(+ context,+ PeoplePage(+ person: person,+ searchResult: null,+ ),+ );+ }+ }++ Future<void> _handleMergePerson() async {+ final clusterId = _firstUnnamedAppliedFaceFilter?.clusterId;+ if (clusterId == null || clusterId.isEmpty) {+ return;+ }+ final selection = await showMergeClustersToPersonPage(+ context,+ seedClusterId: clusterId,+ );+ if (!mounted) {+ return;+ }+ if (selection == null || selection.personId.isEmpty) {+ return;+ }+ var person = selection.person;+ person ??= await PersonService.instance.getPerson(selection.personId);+ if (person == null) {+ return;+ }+ if (selection.person == null || selection.seedClusterId != clusterId) {+ await ClusterFeedbackService.instance.addClusterToExistingPerson(+ person: person,+ clusterID: clusterId,+ );+ }+ if (!mounted) {+ return;+ }+ Navigator.of(context).pop();+ // ignore: unawaited_futures+ routeToPage(+ context,+ PeoplePage(+ person: person,+ searchResult: null,+ ),+ );+ }+@overridevoid dispose() {_filesUpdatedEvent?.cancel();@@ -167,37 +237,37 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {EventType.hide,},selectedFiles: widget.selectedFiles,- header: _firstUnnamedAppliedFaceFilter != null- ? PeopleBanner(- type: PeopleBannerType.addName,+ header: _firstUnnamedAppliedFaceFilter != null &&+ _firstUnnamedAppliedFaceFilter!.clusterId !=+ _dismissedClusterId+ ? SavePersonBanner(faceWidget: PersonFaceWidget(clusterID:_firstUnnamedAppliedFaceFilter!.clusterId,),- actionIcon: Icons.add_outlined,text: AppLocalizations.of(context).savePerson,subText: AppLocalizations.of(context).findThemQuickly,- onTap: () async {- final result = await showAssignPersonAction(- context,- clusterID:- _firstUnnamedAppliedFaceFilter!.clusterId!,- );- Navigator.of(context).pop();- if (result != null) {- final person = result is (PersonEntity, EnteFile)- ? result.$1- : result;- // ignore: unawaited_futures- routeToPage(- context,- PeoplePage(- person: person,- searchResult: null,- ),- );+ primaryActionLabel: AppLocalizations.of(context).save,+ secondaryActionLabel:+ AppLocalizations.of(context).merge,+ onPrimaryTap: _handleSavePerson,+ onSecondaryTap: _handleMergePerson,+ onDismissed: () {+ final clusterId =+ _firstUnnamedAppliedFaceFilter?.clusterId;+ if (clusterId == null || clusterId.isEmpty) {+ return;+ }+ if (!mounted) {+ return;}+ setState(() {+ _dismissedClusterId = clusterId;+ });},+ dismissibleKey: ValueKey(+ "save-person-banner-${_firstUnnamedAppliedFaceFilter!.clusterId}",+ ),): null,),diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dartindex 38eefce0b9..25d01934e4 100644--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart@@ -2,31 +2,33 @@ import "dart:async";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/foundation.dart";-import 'package:flutter/material.dart';-import 'package:photos/core/event_bus.dart';-import 'package:photos/events/files_updated_event.dart';-import 'package:photos/events/local_photos_updated_event.dart';+import "package:flutter/material.dart";+import "package:photos/core/event_bus.dart";+import "package:photos/events/files_updated_event.dart";+import "package:photos/events/local_photos_updated_event.dart";import "package:photos/events/people_changed_event.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/gallery_type.dart';+import "package:photos/models/file/file.dart";+import "package:photos/models/file_load_result.dart";+import "package:photos/models/gallery_type.dart";import "package:photos/models/ml/face/person.dart";-import 'package:photos/models/selected_files.dart';+import "package:photos/models/selected_files.dart";import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";import "package:photos/services/machine_learning/ml_result.dart";import "package:photos/ui/notification/toast.dart";-import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart';-import 'package:photos/ui/viewer/gallery/gallery.dart';+import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";+import "package:photos/ui/viewer/gallery/gallery.dart";import "package:photos/ui/viewer/gallery/state/boundary_reporter_mixin.dart";import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";import "package:photos/ui/viewer/gallery/state/selection_state.dart";import "package:photos/ui/viewer/people/add_person_action_sheet.dart";import "package:photos/ui/viewer/people/cluster_app_bar.dart";-import "package:photos/ui/viewer/people/people_banner.dart";+import "package:photos/ui/viewer/people/merge_clusters_to_person_sheet.dart";import "package:photos/ui/viewer/people/people_page.dart";import "package:photos/ui/viewer/people/person_face_widget.dart";+import "package:photos/ui/viewer/people/save_person_banner.dart";import "package:photos/ui/viewer/search/result/search_result_page.dart";class ClusterPage extends StatefulWidget {@@ -61,6 +63,7 @@ class _ClusterPageState extends State<ClusterPage> {late final List<EnteFile> files;late final StreamSubscription<LocalPhotosUpdatedEvent> _filesUpdatedEvent;late final StreamSubscription<PeopleChangedEvent> _peopleChangedEvent;+ bool _isNamingBannerDismissed = false;@overridevoid initState() {@@ -116,6 +119,68 @@ class _ClusterPageState extends State<ClusterPage> {super.dispose();}+ Future<void> _handleSavePerson() async {+ if (widget.personID == null) {+ final result = await showAssignPersonAction(+ context,+ clusterID: widget.clusterID,+ file: files.isEmpty ? null : files.first,+ );+ if (!mounted) {+ return;+ }+ if (result != null) {+ Navigator.pop(context);+ final person = result is (PersonEntity, EnteFile) ? result.$1 : result;+ routeToPage(+ context,+ PeoplePage(+ person: person,+ searchResult: null,+ ),+ ).ignore();+ }+ } else {+ showShortToast(context, "No personID or clusterID");+ }+ }++ Future<void> _handleMergePerson() async {+ final selection = await showMergeClustersToPersonPage(+ context,+ seedClusterId: widget.clusterID,+ );+ if (!mounted) {+ return;+ }+ if (selection == null || selection.personId.isEmpty) {+ return;+ }+ var person = selection.person;+ person ??= await PersonService.instance.getPerson(selection.personId);+ if (person == null) {+ return;+ }+ if (selection.person == null ||+ selection.seedClusterId != widget.clusterID) {+ await ClusterFeedbackService.instance.addClusterToExistingPerson(+ person: person,+ clusterID: widget.clusterID,+ );+ }+ if (!mounted) {+ return;+ }+ Navigator.pop(context);+ routeToPage(+ context,+ PeoplePage(+ person: person,+ searchResult: null,+ ),+ ).ignore();+ }+@overrideWidget build(BuildContext context) {final gallery = Gallery(@@ -146,38 +211,30 @@ class _ClusterPageState extends State<ClusterPage> {selectedFiles: _selectedFiles,enableFileGrouping: widget.enableGrouping,initialFiles: files,- header: widget.showNamingBanner && files.isNotEmpty- ? PeopleBanner(- type: PeopleBannerType.addName,+ header: widget.showNamingBanner &&+ files.isNotEmpty &&+ !_isNamingBannerDismissed+ ? SavePersonBanner(faceWidget: PersonFaceWidget(clusterID: widget.clusterID,),- actionIcon: Icons.add_outlined,text: AppLocalizations.of(context).savePerson,subText: AppLocalizations.of(context).findThemQuickly,- onTap: () async {- if (widget.personID == null) {- final result = await showAssignPersonAction(- context,- clusterID: widget.clusterID,- file: files.isEmpty ? null : files.first,- );- if (result != null) {- Navigator.pop(context);- final person =- result is (PersonEntity, EnteFile) ? result.$1 : result;- routeToPage(- context,- PeoplePage(- person: person,- searchResult: null,- ),- ).ignore();- }- } else {- showShortToast(context, "No personID or clusterID");+ primaryActionLabel: AppLocalizations.of(context).save,+ secondaryActionLabel: AppLocalizations.of(context).merge,+ onPrimaryTap: _handleSavePerson,+ onSecondaryTap: _handleMergePerson,+ onDismissed: () {+ if (!mounted) {+ return;}+ setState(() {+ _isNamingBannerDismissed = true;+ });},+ dismissibleKey: ValueKey(+ "save-person-banner-${widget.clusterID}",+ ),): null,);diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_banner.dart b/mobile/apps/photos/lib/ui/viewer/people/people_banner.dartdeleted file mode 100644index ad385e92f4..0000000000--- a/mobile/apps/photos/lib/ui/viewer/people/people_banner.dart+++ /dev/null@@ -1,141 +0,0 @@-import "package:flutter/material.dart";-import "package:photos/theme/ente_theme.dart";-import "package:photos/ui/components/buttons/icon_button_widget.dart";-import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";-import "package:photos/ui/viewer/people/person_face_widget.dart";--enum PeopleBannerType {- addName,- suggestion,-}--class PeopleBanner extends StatelessWidget {- final PeopleBannerType type;- final IconData? startIcon;- final PersonFaceWidget? faceWidget;- final IconData actionIcon;- final String text;- final String? subText;- final GestureTapCallback onTap;-- const PeopleBanner({- super.key,- required this.type,- this.startIcon,- this.faceWidget,- required this.actionIcon,- required this.text,- required this.onTap,- this.subText,- });-- @override- Widget build(BuildContext context) {- final colorScheme = getEnteColorScheme(context);- final textTheme = getEnteTextTheme(context);- Color backgroundColor = colorScheme.backgroundElevated2;- final TextStyle mainTextStyle = textTheme.bodyBold;- final TextStyle subTextStyle = textTheme.miniMuted;- late final Widget startWidget;- late final bool roundedActionIcon;- switch (type) {- case PeopleBannerType.suggestion:- assert(startIcon != null);- startWidget = Padding(- padding:- const EdgeInsets.only(top: 10, bottom: 10, left: 6, right: 4),- child: Icon(- startIcon!,- size: 40,- color: colorScheme.primary500,- ),- );- roundedActionIcon = true;- break;- case PeopleBannerType.addName:- assert(faceWidget != null);- backgroundColor = colorScheme.backgroundElevated;- startWidget = Padding(- padding: const EdgeInsets.all(4.0),- child: SizedBox(- width: 56,- height: 56,- child: FaceThumbnailSquircleClip(- child: faceWidget!,- ),- ),- );- roundedActionIcon = false;- }-- final Widget banner = Center(- child: GestureDetector(- onTap: onTap,- child: Padding(- padding: const EdgeInsets.all(4),- child: Container(- decoration: BoxDecoration(- color: backgroundColor,- border: Border.all(- color: colorScheme.strokeFaint,- width: 1,- ),- borderRadius: const BorderRadius.all(- Radius.circular(5),- ),- ),- child: Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- startWidget,- const SizedBox(width: 12),- Expanded(- child: Column(- mainAxisAlignment: MainAxisAlignment.spaceEvenly,- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- text,- style: mainTextStyle,- textAlign: TextAlign.left,- ),- subText != null- ? const SizedBox(height: 6)- : const SizedBox.shrink(),- subText != null- ? Text(- subText!,- style: subTextStyle,- )- : const SizedBox.shrink(),- ],- ),- ),- const SizedBox(width: 12),- IconButtonWidget(- icon: actionIcon,- iconButtonType: IconButtonType.primary,- iconColor: colorScheme.strokeBase,- defaultColor: colorScheme.fillFaint,- pressedColor: colorScheme.fillMuted,- roundedIcon: roundedActionIcon,- onTap: onTap,- ),- const SizedBox(width: 6),- ],- ),- ),- ),- ),- );-- if (type == PeopleBannerType.suggestion) {- return SafeArea(- top: false,- child: RepaintBoundary(child: banner),- );- } else {- return RepaintBoundary(child: banner);- }- }-}diff --git a/mobile/apps/photos/lib/ui/viewer/people/save_person_banner.dart b/mobile/apps/photos/lib/ui/viewer/people/save_person_banner.dartnew file mode 100644index 0000000000..e21d8da956--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/people/save_person_banner.dart@@ -0,0 +1,228 @@+import "package:flutter/material.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";+import "package:photos/ui/viewer/people/person_face_widget.dart";++class SavePersonBanner extends StatelessWidget {+ final PersonFaceWidget? faceWidget;+ final String text;+ final String? subText;+ final String? primaryActionLabel;+ final String? secondaryActionLabel;+ final GestureTapCallback? onPrimaryTap;+ final GestureTapCallback? onSecondaryTap;+ final VoidCallback? onDismissed;+ final Key? dismissibleKey;++ const SavePersonBanner({+ super.key,+ this.faceWidget,+ required this.text,+ this.subText,+ this.primaryActionLabel,+ this.secondaryActionLabel,+ this.onPrimaryTap,+ this.onSecondaryTap,+ this.onDismissed,+ this.dismissibleKey,+ }) : assert(+ faceWidget != null &&+ primaryActionLabel != null &&+ secondaryActionLabel != null &&+ onPrimaryTap != null &&+ onSecondaryTap != null,+ ),+ assert(onDismissed == null || dismissibleKey != null);++ @override+ Widget build(BuildContext context) {+ return _buildBanner(context);+ }++ Widget _buildBanner(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);+ final captionColor = colorScheme.textBase.withValues(alpha: 0.8);+ final buttonTextStyle = textTheme.smallBold.copyWith(+ height: 20 / 14,+ );+ const double faceSize = 52;+ const double closeButtonSize = 24;+ final bool showDismiss = onDismissed != null;+ final double closeButtonInset = showDismiss ? closeButtonSize + 8 : 0;++ final banner = RepaintBoundary(+ child: Padding(+ padding: const EdgeInsets.fromLTRB(6, 8, 6, 6),+ child: Container(+ decoration: BoxDecoration(+ color: colorScheme.backgroundElevated2,+ borderRadius: BorderRadius.circular(20),+ ),+ padding: const EdgeInsets.all(12),+ child: Stack(+ children: [+ Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Padding(+ padding: EdgeInsets.only(right: closeButtonInset),+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.center,+ children: [+ SizedBox(+ width: faceSize,+ height: faceSize,+ child: FaceThumbnailSquircleClip(+ child: faceWidget!,+ ),+ ),+ const SizedBox(width: 12),+ Expanded(+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ text,+ style: textTheme.body,+ ),+ if (subText != null) ...[+ const SizedBox(height: 4),+ Text(+ subText!,+ style: textTheme.mini.copyWith(+ color: captionColor,+ ),+ ),+ ],+ ],+ ),+ ),+ ],+ ),+ ),+ const SizedBox(height: 20),+ Row(+ children: [+ Expanded(+ child: _SavePersonBannerActionButton(+ label: primaryActionLabel!,+ backgroundColor: const Color(0xFF08C225),+ textStyle: buttonTextStyle.copyWith(+ color: Colors.white,+ ),+ onTap: onPrimaryTap,+ ),+ ),+ const SizedBox(width: 6),+ Expanded(+ child: _SavePersonBannerActionButton(+ label: secondaryActionLabel!,+ backgroundColor: colorScheme.fillFaint,+ textStyle: buttonTextStyle.copyWith(+ color: colorScheme.textBase,+ ),+ onTap: onSecondaryTap,+ ),+ ),+ ],+ ),+ ],+ ),+ if (showDismiss)+ Positioned(+ top: 0,+ right: 0,+ child: _SavePersonBannerCloseButton(+ size: closeButtonSize,+ onTap: onDismissed,+ ),+ ),+ ],+ ),+ ),+ ),+ );++ if (!showDismiss) {+ return banner;+ }++ return Dismissible(+ key: dismissibleKey!,+ direction: DismissDirection.horizontal,+ onDismissed: (_) => onDismissed?.call(),+ child: banner,+ );+ }+}++class _SavePersonBannerActionButton extends StatelessWidget {+ final String label;+ final Color backgroundColor;+ final TextStyle textStyle;+ final GestureTapCallback? onTap;++ const _SavePersonBannerActionButton({+ required this.label,+ required this.backgroundColor,+ required this.textStyle,+ this.onTap,+ });++ @override+ Widget build(BuildContext context) {+ final borderRadius = BorderRadius.circular(14);+ return SizedBox(+ height: 48,+ child: Material(+ color: backgroundColor,+ borderRadius: borderRadius,+ child: InkWell(+ borderRadius: borderRadius,+ onTap: onTap,+ child: Center(+ child: Text(+ label,+ style: textStyle,+ ),+ ),+ ),+ ),+ );+ }+}++class _SavePersonBannerCloseButton extends StatelessWidget {+ final double size;+ final VoidCallback? onTap;++ const _SavePersonBannerCloseButton({+ required this.size,+ this.onTap,+ });++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final borderRadius = BorderRadius.circular(size / 2);+ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Container(+ width: size,+ height: size,+ decoration: BoxDecoration(+ color: colorScheme.fillFaint,+ borderRadius: borderRadius,+ ),+ child: const Icon(+ Icons.close,+ size: 14,+ color: Colors.black,+ ),+ ),+ );+ }+}