Skip to content

armgit / ente

Public Imported from GitHub
0

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

Simplify save person banner

Neeraj Gupta6191d31b49b0
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.dart
index 40544c9bb6..e9b18d4498 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,8 +13,6 @@ 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/gallery_app_bar_config.dart";
@@ -22,7 +20,6 @@ import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.da
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/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";
@@ -52,7 +49,6 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
int _filteredFilesVersion = 0;
final _isLoading = ValueNotifier<bool>(true);
FaceFilter? _firstUnnamedAppliedFaceFilter;
- String? _dismissedClusterId;
@override
void initState() {
@@ -152,40 +148,6 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
}
}
- 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));
- }
-
@override
void dispose() {
_filesUpdatedEvent?.cancel();
@@ -232,10 +194,7 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
EventType.hide,
},
selectedFiles: widget.selectedFiles,
- header:
- _firstUnnamedAppliedFaceFilter != null &&
- _firstUnnamedAppliedFaceFilter!.clusterId !=
- _dismissedClusterId
+ header: _firstUnnamedAppliedFaceFilter != null
? SavePersonBanner(
faceWidget: PersonFaceWidget(
clusterID:
@@ -243,28 +202,7 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
),
text: AppLocalizations.of(context).savePerson,
subText: AppLocalizations.of(context).findThemQuickly,
- 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}",
- ),
+ onTap: _handleSavePerson,
)
: null,
),
diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
index 9eba0a1f7c..4a8265a345 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
@@ -17,7 +17,6 @@ import "package:photos/models/ml/face/person.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart" show isLocalGalleryMode;
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/components/banners/name_face_banner.dart";
import "package:photos/ui/notification/toast.dart";
@@ -28,7 +27,6 @@ import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.da
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/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";
@@ -69,7 +67,6 @@ class _ClusterPageState extends State<ClusterPage> {
late final StreamSubscription<LocalPhotosUpdatedEvent> _filesUpdatedEvent;
late final StreamSubscription<PeopleChangedEvent> _peopleChangedEvent;
late final StreamSubscription<AppModeChangedEvent> _appModeChangedEvent;
- bool _isNamingBannerDismissed = false;
bool get _localGalleryUiMode =>
isLocalGalleryMode && !Configuration.instance.hasConfiguredAccount();
@@ -158,42 +155,6 @@ class _ClusterPageState extends State<ClusterPage> {
}
}
- Future<void> _handleMergePerson() async {
- if (_localGalleryUiMode) {
- return;
- }
- 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();
- }
-
@override
Widget build(BuildContext context) {
final appBar = ClusterAppBar.sliverConfig(
@@ -229,30 +190,14 @@ class _ClusterPageState extends State<ClusterPage> {
enableFileGrouping: widget.enableGrouping,
initialFiles: files,
header:
- (_localGalleryUiMode || widget.showNamingBanner) &&
- files.isNotEmpty &&
- !_isNamingBannerDismissed
+ (_localGalleryUiMode || widget.showNamingBanner) && files.isNotEmpty
? _localGalleryUiMode
? const NameFaceBanner()
: SavePersonBanner(
faceWidget: PersonFaceWidget(clusterID: widget.clusterID),
text: AppLocalizations.of(context).savePerson,
subText: AppLocalizations.of(context).findThemQuickly,
- 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}",
- ),
+ onTap: _handleSavePerson,
)
: null,
);
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.dart
index ca5bb05a45..f83297d54b 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/save_person_banner.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/save_person_banner.dart
@@ -1,208 +1,48 @@
import "package:flutter/material.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.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 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;
+ final String subText;
+ final Future<void> Function() onTap;
const SavePersonBanner({
super.key,
- this.faceWidget,
+ required 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);
+ required this.subText,
+ required this.onTap,
+ });
@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,
- ),
- ),
- ],
- ),
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ child: MenuItemWidgetNew(
+ title: text,
+ subText: subText,
+ titleMaxLines: 1,
+ subTextMaxLines: 1,
+ subTextStyle: textTheme.miniMuted,
+ titleToSubTextSpacing: 4,
+ leadingIconSize: 36,
+ leadingIconWidget: SizedBox.square(
+ dimension: 36,
+ child: FaceThumbnailSquircleClip(child: faceWidget),
),
- ),
- );
-
- 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,
+ trailingWidget: SizedBox(
+ width: 48,
+ child: Icon(Icons.chevron_right, color: colorScheme.textBase),
),
- child: const Icon(Icons.close, size: 14, color: Colors.black),
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
+ onTap: onTap,
),
);
}