π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Migrate people selection to the shared sheet
r4khul729b439cc01e
diff --git a/mobile/apps/photos/changes/unified-selection-sheets.md b/mobile/apps/photos/changes/unified-selection-sheets.mdindex 8465f872c2..8c67c3d514 100644--- a/mobile/apps/photos/changes/unified-selection-sheets.md+++ b/mobile/apps/photos/changes/unified-selection-sheets.md@@ -1 +1 @@-- Refreshed album selection with the shared expandable sheet and consistent action labels.+- Unified album and people selection sheets with photo selection and consistent action labels.diff --git a/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_action_bar_widget.dart b/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_action_bar_widget.dartindex 303e2a642b..622937bc1b 100644--- a/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_action_bar_widget.dart+++ b/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_action_bar_widget.dart@@ -1,82 +1,31 @@-import "package:ente_components/ente_components.dart" as components;+import "package:ente_components/ente_components.dart";import "package:ente_strings/ente_strings.dart";import "package:flutter/material.dart";+import "package:hugeicons/hugeicons.dart";import "package:photos/models/selected_people.dart";+import "package:photos/ui/components/bottom_action_bar/action_bar_widget.dart";-class PeopleActionBarWidget extends StatefulWidget {- final SelectedPeople? selectedPeople;+class PeopleActionBarWidget extends StatelessWidget {+ const PeopleActionBarWidget({+ required this.selectedPeople,+ this.onCancel,+ super.key,+ });+ final SelectedPeople selectedPeople;final VoidCallback? onCancel;- const PeopleActionBarWidget({super.key, this.selectedPeople, this.onCancel});@override- State<PeopleActionBarWidget> createState() => _PeopleActionBarWidgetState();-}--class _PeopleActionBarWidgetState extends State<PeopleActionBarWidget> {- final ValueNotifier<int> _selectedPeopleNotifier = ValueNotifier(0);-- @override- void initState() {- super.initState();- widget.selectedPeople?.addListener(_selectedPeopleListener);- }-- @override- void dispose() {- widget.selectedPeople?.removeListener(_selectedPeopleListener);- _selectedPeopleNotifier.dispose();- super.dispose();- }-- @override- Widget build(BuildContext context) {- final colors = components.ComponentTheme.colorsOf(context);- final miniStyle = components.TextStyles.mini.copyWith(- color: colors.textBase,- );- return SizedBox(- child: Padding(- padding: const EdgeInsets.fromLTRB(20, 8, 20, 8),- child: Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Flexible(- flex: 1,- child: ValueListenableBuilder(- valueListenable: _selectedPeopleNotifier,- builder: (context, value, child) {- final count = widget.selectedPeople?.personIds.length ?? 0;- return Text(- context.strings.selectedPhotos(count: count),- style: miniStyle,- );- },- ),- ),- Flexible(- flex: 1,- child: Padding(- padding: const EdgeInsets.symmetric(vertical: 12),- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () {- widget.onCancel?.call();- },- child: Align(- alignment: Alignment.centerRight,- child: Text(context.strings.cancel, style: miniStyle),- ),- ),- ),- ),- ],- ),+ Widget build(BuildContext context) => ListenableBuilder(+ listenable: selectedPeople,+ builder: (context, _) => SelectionControlChip(+ label: selectedPeople.personIds.length.toString(),+ semanticLabel:+ "${context.strings.cancel}, ${context.strings.selectedCount(count: selectedPeople.personIds.length)}",+ icon: const HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: IconSizes.small,),- );- }-- void _selectedPeopleListener() {- _selectedPeopleNotifier.value =- widget.selectedPeople?.personIds.length ?? 0;- }+ onTap: onCancel,+ ),+ );}diff --git a/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_bottom_action_bar_widget.dart b/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_bottom_action_bar_widget.dartindex 594aa15d34..68b1762923 100644--- a/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_bottom_action_bar_widget.dart+++ b/mobile/apps/photos/lib/ui/components/bottom_action_bar/people_bottom_action_bar_widget.dart@@ -1,7 +1,5 @@import "package:ente_components/ente_components.dart" as components;-import "package:ente_ui/components/divider_widget.dart";import "package:flutter/material.dart";-import "package:photos/core/constants.dart";import "package:photos/models/selected_people.dart";import "package:photos/ui/components/bottom_action_bar/people_action_bar_widget.dart";import "package:photos/ui/viewer/actions/people_selection_action_widget.dart";@@ -10,49 +8,36 @@ class PeopleBottomActionBarWidget extends StatelessWidget {final SelectedPeople selectedPeople;final VoidCallback? onCancel;final Color? backgroundColor;+ final ScrollController? backgroundScrollController;const PeopleBottomActionBarWidget(this.selectedPeople, {super.key,this.backgroundColor,this.onCancel,+ this.backgroundScrollController,});@overrideWidget build(BuildContext context) {- final bottomPadding = MediaQuery.paddingOf(context).bottom;- final widthOfScreen = MediaQuery.sizeOf(context).width;- final colors = components.ComponentTheme.colorsOf(context);- final double leftRightPadding = widthOfScreen > restrictedMaxWidth- ? (widthOfScreen - restrictedMaxWidth) / 2- : 0;- return Container(- decoration: BoxDecoration(- color: backgroundColor ?? colors.backgroundBase,- border: Border(top: BorderSide(color: colors.strokeDark)),- borderRadius: const BorderRadius.only(- topLeft: Radius.circular(20),- topRight: Radius.circular(20),+ return PeopleSelectionActionWidget(+ selectedPeople,+ backgroundColor: backgroundColor,+ backgroundScrollController: backgroundScrollController,+ selectionControls: Padding(+ padding: const EdgeInsets.symmetric(horizontal: components.Spacing.sm),+ child: Row(+ mainAxisAlignment: MainAxisAlignment.end,+ children: [+ Flexible(+ child: PeopleActionBarWidget(+ selectedPeople: selectedPeople,+ onCancel: onCancel,+ ),+ ),+ ],),),- padding: EdgeInsets.only(- top: 4,- bottom: bottomPadding,- right: leftRightPadding,- left: leftRightPadding,- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- const SizedBox(height: 8),- PeopleSelectionActionWidget(selectedPeople),- const DividerWidget(dividerType: DividerType.bottomBar),- PeopleActionBarWidget(- selectedPeople: selectedPeople,- onCancel: onCancel,- ),- ],- ),);}}diff --git a/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_button_widget.dart b/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_button_widget.dartdeleted file mode 100644index 614b85cc67..0000000000--- a/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_button_widget.dart+++ /dev/null@@ -1,166 +0,0 @@-import "package:ente_components/ente_components.dart" as components;-import "package:flutter/material.dart";-import "package:hugeicons/hugeicons.dart";--class SelectionActionButton extends StatelessWidget {- final String labelText;- final List<List<dynamic>>? hugeIcon;- final Widget? iconWidget;- final VoidCallback? onTap;- final bool shouldShow;- final bool isCritical;-- const SelectionActionButton({- required this.labelText,- required this.onTap,- this.hugeIcon,- this.iconWidget,- this.shouldShow = true,- this.isCritical = false,- super.key,- });-- @override- Widget build(BuildContext context) {- assert(hugeIcon != null || iconWidget != null);- return AnimatedSize(- duration: const Duration(milliseconds: 350),- curve: Curves.easeInOutCirc,- child: AnimatedSwitcher(- duration: const Duration(milliseconds: 300),- child: shouldShow- ? _Body(- labelText: labelText,- hugeIcon: hugeIcon,- onTap: onTap,- iconWidget: iconWidget,- isCritical: isCritical,- )- : const SizedBox(height: 60),- ),- );- }-}--class _Body extends StatefulWidget {- final String labelText;- final List<List<dynamic>>? hugeIcon;- final Widget? iconWidget;- final VoidCallback? onTap;- final bool isCritical;- const _Body({- required this.labelText,- required this.onTap,- required this.isCritical,- this.hugeIcon,- this.iconWidget,- });-- @override- State<_Body> createState() => __BodyState();-}--class __BodyState extends State<_Body> {- static const minWidth = 64.0;- static const iconSize = 22.0;- late double widthOfButton;- Color? backgroundColor;-- @override- Widget build(BuildContext context) {- widthOfButton = getWidthOfButton();- final colors = components.ComponentTheme.colorsOf(context);- final foregroundColor = widget.isCritical- ? colors.warning- : colors.textBase;- final labelStyle = components.TextStyles.mini.copyWith(- color: foregroundColor,- );- return GestureDetector(- onTap: widget.onTap,- onTapDown: (details) {- setState(() {- backgroundColor = colors.fillDark;- });- },- onTapUp: (details) {- setState(() {- backgroundColor = null;- });- },- onTapCancel: () {- setState(() {- backgroundColor = null;- });- },- child: Container(- decoration: BoxDecoration(- borderRadius: BorderRadius.circular(16),- color: backgroundColor,- ),- child: Padding(- padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),- child: SizedBox(- width: widthOfButton,- child: Column(- mainAxisAlignment: MainAxisAlignment.center,- mainAxisSize: MainAxisSize.min,- children: [- if (widget.hugeIcon != null)- HugeIcon(- icon: widget.hugeIcon!,- size: iconSize,- color: foregroundColor,- )- else- IconTheme(- data: IconThemeData(size: iconSize, color: foregroundColor),- child: widget.iconWidget!,- ),- const SizedBox(height: 4),- Text(- widget.labelText,- textAlign: TextAlign.center,- // Keep this style in sync with computeWidthOfWord.- style: labelStyle,- ),- ],- ),- ),- ),- ),- );- }-- double getWidthOfButton() {- final widthOfWidestWord = getWidthOfWidestWord(widget.labelText);- if (widthOfWidestWord > minWidth) return widthOfWidestWord;- return minWidth;- }-- double getWidthOfWidestWord(String labelText) {- final words = labelText.split(RegExp(r'\s+'));- if (words.isEmpty) return 0.0;-- double maxWidth = 0.0;- for (String word in words) {- final width = computeWidthOfWord(word, components.TextStyles.mini);- if (width > maxWidth) {- maxWidth = width;- }- }- return maxWidth;- }-- //Todo: this doesn't give the correct width of the word, make it right- double computeWidthOfWord(String text, TextStyle style) {- final textPainter = TextPainter(- text: TextSpan(text: text, style: style),- maxLines: 1,- textDirection: TextDirection.ltr,- textScaler: MediaQuery.textScalerOf(context),- )..layout();- // Add 8 points because TextPainter under-measures this label.- return textPainter.size.width + 8;- }-}diff --git a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dartindex 0d167c8605..b8645fece1 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart@@ -1,3 +1,4 @@+import "package:ente_components/theme/theme.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:ente_strings/ente_strings.dart";import "package:flutter/material.dart";@@ -12,9 +13,8 @@ import "package:photos/services/machine_learning/face_ml/face_filtering/face_filimport "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/search_service.dart";-import "package:photos/theme/ente_theme.dart";import "package:photos/ui/collections/collection_action_sheet.dart";-import "package:photos/ui/components/bottom_action_bar/selection_action_button_widget.dart";+import "package:photos/ui/components/bottom_action_bar/selection_action_sheet.dart";import "package:photos/ui/components/buttons/button_widget.dart";import "package:photos/ui/viewer/people/merge_clusters_to_person_sheet.dart";import "package:photos/ui/viewer/people/person_cluster_suggestion.dart";@@ -24,7 +24,17 @@ import "package:photos/utils/dialog_util.dart";class PeopleSelectionActionWidget extends StatefulWidget {final SelectedPeople selectedPeople;- const PeopleSelectionActionWidget(this.selectedPeople, {super.key});+ final Widget selectionControls;+ final Color? backgroundColor;+ final ScrollController? backgroundScrollController;++ const PeopleSelectionActionWidget(+ this.selectedPeople, {+ required this.selectionControls,+ this.backgroundColor,+ this.backgroundScrollController,+ super.key,+ });@overrideState<PeopleSelectionActionWidget> createState() =>@@ -96,14 +106,21 @@ class _PeopleSelectionActionWidgetStatereturn const SizedBox.shrink();}+ final controls = SafeArea(+ top: false,+ child: ConstrainedBox(+ constraints: const BoxConstraints(maxWidth: 640),+ child: widget.selectionControls,+ ),+ );return FutureBuilder<Map<String, PersonEntity>>(future: personEntitiesMapFuture,builder: (context, snapshot) {if (!snapshot.hasData) {- return const SizedBox.shrink();+ return controls;}final personMap = snapshot.data!;- final List<SelectionActionButton> items = [];+ final List<SelectionSheetAction> items = [];final selectedPersonIds = _getSelectedPersonIds(personMap);final selectedClusterIds = _getSelectedClusterIds();final onlyOnePerson =@@ -185,11 +202,11 @@ class _PeopleSelectionActionWidgetStateshowAutoAddAction;if (!hasVisibleAction) {- return const SizedBox.shrink();+ return controls;}items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.edit,hugeIcon: HugeIcons.strokeRoundedPencilEdit01,onTap: _onEditPerson,@@ -197,7 +214,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.review,hugeIcon: HugeIcons.strokeRoundedSearch01,onTap: _onReviewSuggestion,@@ -205,7 +222,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.ignore,hugeIcon: HugeIcons.strokeRoundedImageNotFound01,onTap: _onIgnore,@@ -213,7 +230,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.merge,hugeIcon: HugeIcons.strokeRoundedGitMerge,onTap: _onMerge,@@ -221,7 +238,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.reset,hugeIcon: HugeIcons.strokeRoundedRemove01,onTap: _onResetPerson,@@ -229,7 +246,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.showPerson,hugeIcon: HugeIcons.strokeRoundedView,onTap: _onShowPerson,@@ -237,7 +254,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.pin,hugeIcon: HugeIcons.strokeRoundedPin,onTap: () => _updatePinState(true),@@ -245,7 +262,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.unpin,hugeIcon: HugeIcons.strokeRoundedPinOff,onTap: () => _updatePinState(false),@@ -253,7 +270,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.hideFromMemories,hugeIcon: HugeIcons.strokeRoundedViewOffSlash,onTap: () => _updateHideFromMemoriesState(true),@@ -261,7 +278,7 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.showInMemories,hugeIcon: HugeIcons.strokeRoundedView,onTap: () => _updateHideFromMemoriesState(false),@@ -269,45 +286,24 @@ class _PeopleSelectionActionWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.autoAddToAlbum,iconWidget: Image.asset("assets/auto-add-people.png",width: 22,height: 22,- color: EnteTheme.isDark(context) ? Colors.white : Colors.black,+ color: context.componentColors.textBase,),onTap: _autoAddToAlbum,shouldShow: showAutoAddAction,),);- return MediaQuery(- data: MediaQuery.of(context).removePadding(removeBottom: true),- child: SafeArea(- child: Scrollbar(- radius: const Radius.circular(1),- thickness: 2,- thumbVisibility: true,- child: SingleChildScrollView(- physics: const BouncingScrollPhysics(- decelerationRate: ScrollDecelerationRate.fast,- ),- scrollDirection: Axis.horizontal,- child: Container(- padding: const EdgeInsets.only(bottom: 24),- child: Row(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- const SizedBox(width: 4),- ...items,- const SizedBox(width: 4),- ],- ),- ),- ),- ),- ),+ return SelectionActionSheet(+ actions: items,+ selectionControls: widget.selectionControls,+ backgroundColor: widget.backgroundColor,+ backgroundScrollController: widget.backgroundScrollController,);},);diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dartindex 036d85e846..5545749a23 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart@@ -28,6 +28,7 @@ import "package:photos/ui/components/collection_share_badge.dart";import "package:photos/ui/viewer/actions/select_all_status_icon.dart";import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";import "package:photos/ui/viewer/file/thumbnail_widget.dart";+import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";import "package:photos/ui/viewer/people/person_face_widget.dart";import "package:photos/ui/viewer/people/person_gallery_suggestion.dart";@@ -46,6 +47,13 @@ class PeopleSectionAllPage extends StatefulWidget {class _PeopleSectionAllPageState extends State<PeopleSectionAllPage> {final _selectedPeople = SelectedPeople();+ final _scrollController = ScrollController();++ @override+ void dispose() {+ _scrollController.dispose();+ super.dispose();+ }@overrideWidget build(BuildContext context) {@@ -55,20 +63,47 @@ class _PeopleSectionAllPageState extends State<PeopleSectionAllPage> {final hasSelection = _selectedPeople.personIds.isNotEmpty;return Scaffold(- body: PeopleSectionAllSelectionWrapper(- selectedPeople: _selectedPeople,- showSearchBar: true,- startInSearchMode: widget.startInSearchMode,- includeEmptyPersons: true,+ body: GalleryBoundariesProvider(+ child: Builder(+ builder: (context) => Stack(+ alignment: Alignment.bottomCenter,+ children: [+ ValueListenableBuilder<double?>(+ valueListenable: GalleryBoundariesProvider.of(+ context,+ )!.selectionSheetMinHeightNotifier,+ builder: (context, height, _) => Padding(+ padding: EdgeInsets.only(+ bottom: hasSelection+ ? height ??+ (MediaQuery.textScalerOf(context).scale(+ TextStyles.body.fontSize!,+ ) *+ TextStyles.body.height! ++ Spacing.md * 2)+ .clamp(44.0, double.infinity) ++ MediaQuery.paddingOf(context).bottom+ : 0,+ ),+ child: PeopleSectionAllSelectionWrapper(+ selectedPeople: _selectedPeople,+ showSearchBar: true,+ startInSearchMode: widget.startInSearchMode,+ includeEmptyPersons: true,+ scrollController: _scrollController,+ ),+ ),+ ),+ if (hasSelection)+ PeopleBottomActionBarWidget(+ _selectedPeople,+ backgroundScrollController: _scrollController,+ onCancel: _selectedPeople.clearAll,+ ),+ ],+ ),+ ),),- bottomNavigationBar: hasSelection- ? PeopleBottomActionBarWidget(- _selectedPeople,- onCancel: () {- _selectedPeople.clearAll();- },- )- : null,);},);@@ -80,6 +115,7 @@ class PeopleSectionAllSelectionWrapper extends StatefulWidget {final bool showSearchBar;final bool startInSearchMode;final bool includeEmptyPersons;+ final ScrollController? scrollController;const PeopleSectionAllSelectionWrapper({super.key,@@ -87,6 +123,7 @@ class PeopleSectionAllSelectionWrapper extends StatefulWidget {this.showSearchBar = false,this.startInSearchMode = false,this.includeEmptyPersons = false,+ this.scrollController,});@override@@ -103,6 +140,7 @@ class _PeopleSectionAllSelectionWrapperStateshowSearchBar: widget.showSearchBar,startInSearchMode: widget.startInSearchMode,includeEmptyPersons: widget.includeEmptyPersons,+ scrollController: widget.scrollController,);}}@@ -321,6 +359,7 @@ class PeopleSectionAllWidget extends StatefulWidget {this.showSearchBar = false,this.startInSearchMode = false,this.includeEmptyPersons = false,+ this.scrollController,});final SelectedPeople? selectedPeople;@@ -328,6 +367,7 @@ class PeopleSectionAllWidget extends StatefulWidget {final bool showSearchBar;final bool startInSearchMode;final bool includeEmptyPersons;+ final ScrollController? scrollController;@overrideState<PeopleSectionAllWidget> createState() => _PeopleSectionAllWidgetState();@@ -859,10 +899,14 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {Widget _buildScrollBody(List<Widget> slivers) {if (!widget.showSearchBar) {- return CustomScrollView(slivers: slivers);+ return CustomScrollView(+ controller: widget.scrollController,+ slivers: slivers,+ );}return AppBarComponent(+ controller: widget.scrollController,title: SectionType.face.sectionTitle(context),physics: const BouncingScrollPhysics(),titleBuilder: _buildTitle,