Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refresh add person picker

AmanRajSinghMourya3eb9f6afc752
diff --git a/mobile/apps/photos/lib/ui/viewer/people/add_files_to_person_page.dart b/mobile/apps/photos/lib/ui/viewer/people/add_files_to_person_page.dart
index 14d3ef9d90..73b2fd85f4 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/add_files_to_person_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/add_files_to_person_page.dart
@@ -1,8 +1,10 @@
import "dart:async";
+import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
import "package:ente_ui/components/loading_widget.dart";
import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/people_sort_order_change_event.dart";
@@ -14,12 +16,9 @@ import "package:photos/services/machine_learning/face_ml/face_filtering/face_fil
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/services/search_service.dart";
import "package:photos/settings/local_settings.dart";
-import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
-import "package:photos/theme/text_style.dart";
-import "package:photos/ui/components/buttons/icon_button_widget.dart";
-import "package:photos/ui/components/searchable_appbar.dart";
import "package:photos/ui/notification/toast.dart";
+import "package:photos/ui/viewer/gallery/gallery_app_bar_actions.dart";
import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";
import "package:photos/ui/viewer/people/person_face_widget.dart";
import "package:photos/utils/dialog_util.dart";
@@ -92,16 +91,20 @@ class AddFilesToPersonPage extends StatefulWidget {
}
class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
+ static const _titleActionSize = 36.0;
+ static const _searchTitleHeight = 52.0;
+ static const _searchTransitionDuration = Duration(milliseconds: 240);
+
late Future<List<GenericSearchResult>> _personsFuture;
String _searchQuery = "";
+ bool _isSearchBarVisible = false;
+ final _searchController = TextEditingController();
+ final _searchFocusNode = FocusNode();
late PeopleSortKey _sortKey;
bool _nameSortAscending = true;
bool _updatedSortAscending = false;
bool _photosSortAscending = false;
- static const double _sortMenuItemHeight = 52;
- static const double _sortMenuCornerRadius = 12;
-
@override
void initState() {
super.initState();
@@ -132,12 +135,29 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
});
}
- void _clearSearchQuery() {
- if (_searchQuery.isNotEmpty) {
- setState(() {
- _searchQuery = "";
- });
- }
+ void _activateSearch() {
+ setState(() => _isSearchBarVisible = true);
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) {
+ _searchFocusNode.requestFocus();
+ }
+ });
+ }
+
+ void _closeSearch() {
+ _searchFocusNode.unfocus();
+ _searchController.clear();
+ setState(() {
+ _isSearchBarVisible = false;
+ _searchQuery = "";
+ });
+ }
+
+ @override
+ void dispose() {
+ _searchController.dispose();
+ _searchFocusNode.dispose();
+ super.dispose();
}
bool _isSortAscending(PeopleSortKey key) {
@@ -165,12 +185,6 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
}
}
- bool _canToggleSortDirection(PeopleSortKey key) {
- return key == PeopleSortKey.name ||
- key == PeopleSortKey.lastUpdated ||
- key == PeopleSortKey.mostPhotos;
- }
-
void _sortFaces(List<GenericSearchResult> faces) {
sortPeopleFaces(
faces,
@@ -194,11 +208,10 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
@override
Widget build(BuildContext context) {
final textTheme = getEnteTextTheme(context);
- final colorScheme = getEnteColorScheme(context);
final smallFontSize = textTheme.small.fontSize!;
final textScaleFactor =
MediaQuery.textScalerOf(context).scale(smallFontSize) / smallFontSize;
- final textHeight = 24 * textScaleFactor;
+ final labelHeight = 28 * textScaleFactor;
const horizontalEdgePadding = 20.0;
const gridPadding = 16.0;
@@ -206,33 +219,13 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
body: FutureBuilder<List<GenericSearchResult>>(
future: _personsFuture,
builder: (context, snapshot) {
- final slivers = <Widget>[
- SearchableAppBar(
- title: Text(context.strings.addPerson),
- onSearch: _updateSearchQuery,
- onSearchClosed: _clearSearchQuery,
- centerTitle: false,
- searchIconPadding: const EdgeInsets.fromLTRB(
- 12,
- 12,
- horizontalEdgePadding,
- 12,
- ),
- actions: [
- Padding(
- padding: const EdgeInsets.only(right: horizontalEdgePadding),
- child: _buildSortMenu(context, textTheme, colorScheme),
- ),
- ],
- ),
- ];
+ final slivers = <Widget>[];
if (snapshot.connectionState == ConnectionState.waiting) {
slivers.add(
const SliverFillRemaining(
child: Center(child: EnteLoadingWidget()),
),
);
- return CustomScrollView(slivers: slivers);
} else if (snapshot.hasError) {
AddFilesToPersonPage._logger.severe(
"Failed to load persons for manual tagging",
@@ -244,220 +237,233 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
child: Center(child: Icon(Icons.error_outline_rounded)),
),
);
- return CustomScrollView(slivers: slivers);
- }
-
- final persons = snapshot.data ?? [];
- final sortedPersons = [...persons];
- _sortFaces(sortedPersons);
- final results = _filterPersons(sortedPersons);
- if (results.isEmpty) {
- slivers.add(
- SliverFillRemaining(
- child: Center(child: Text(context.strings.noResultsFound)),
- ),
- );
- return CustomScrollView(slivers: slivers);
- }
- final screenWidth = MediaQuery.of(context).size.width;
- final estimatedCount = (screenWidth / 100).floor();
- final crossAxisCount = estimatedCount > 0 ? estimatedCount : 1;
- final itemSize =
- (screenWidth -
- ((horizontalEdgePadding * 2) +
- ((crossAxisCount - 1) * gridPadding))) /
- crossAxisCount;
-
- final bottomPadding = MediaQuery.paddingOf(context).bottom;
- slivers.add(
- SliverPadding(
- padding: EdgeInsets.fromLTRB(
- horizontalEdgePadding,
- 16,
- horizontalEdgePadding,
- 16 + bottomPadding,
- ),
- sliver: SliverGrid(
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- mainAxisSpacing: gridPadding,
- crossAxisSpacing: gridPadding,
- crossAxisCount: crossAxisCount,
- childAspectRatio: itemSize / (itemSize + textHeight),
+ } else {
+ final persons = snapshot.data ?? [];
+ final sortedPersons = [...persons];
+ _sortFaces(sortedPersons);
+ final results = _filterPersons(sortedPersons);
+ if (results.isEmpty) {
+ slivers.add(
+ SliverFillRemaining(
+ child: Center(child: Text(context.strings.noResultsFound)),
),
- delegate: SliverChildBuilderDelegate(
- childCount: results.length,
- (context, index) {
- final person = results[index];
- final personId = person.params[kPersonParamID] as String?;
- final personKey = personId != null && personId.isNotEmpty
- ? personId
- : person.name();
- return _ManualPersonGridTile(
- key: ValueKey(personKey),
- result: person,
- size: itemSize,
- labelHeight: textHeight,
- onTap: () => _onPersonSelected(person),
- );
- },
+ );
+ } else {
+ final screenWidth = MediaQuery.of(context).size.width;
+ final estimatedCount = (screenWidth / 100).floor();
+ final crossAxisCount = estimatedCount > 0 ? estimatedCount : 1;
+ final itemSize =
+ (screenWidth -
+ ((horizontalEdgePadding * 2) +
+ ((crossAxisCount - 1) * gridPadding))) /
+ crossAxisCount;
+
+ final bottomPadding = MediaQuery.paddingOf(context).bottom;
+ slivers.add(
+ SliverPadding(
+ padding: EdgeInsets.fromLTRB(
+ horizontalEdgePadding,
+ 16,
+ horizontalEdgePadding,
+ 16 + bottomPadding,
+ ),
+ sliver: SliverGrid(
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
+ mainAxisSpacing: gridPadding,
+ crossAxisSpacing: gridPadding,
+ crossAxisCount: crossAxisCount,
+ childAspectRatio: itemSize / (itemSize + labelHeight),
+ ),
+ delegate: SliverChildBuilderDelegate(
+ childCount: results.length,
+ (context, index) {
+ final person = results[index];
+ final personId =
+ person.params[kPersonParamID] as String?;
+ final personKey =
+ personId != null && personId.isNotEmpty
+ ? personId
+ : person.name();
+ return _ManualPersonGridTile(
+ key: ValueKey(personKey),
+ result: person,
+ size: itemSize,
+ labelHeight: labelHeight,
+ onTap: () => _onPersonSelected(person),
+ );
+ },
+ ),
+ ),
),
- ),
- ),
+ );
+ }
+ }
+
+ return AppBarComponent(
+ title: context.strings.addPerson,
+ physics: const BouncingScrollPhysics(),
+ titleBuilder: _buildTitle,
+ titleBuilderHeight: _searchTitleHeight,
+ slivers: slivers,
);
- return CustomScrollView(slivers: slivers);
},
),
);
}
- Widget _buildSortMenu(
- BuildContext context,
- EnteTextTheme textTheme,
- EnteColorScheme colorScheme,
- ) {
- return Theme(
- data: Theme.of(context).copyWith(
- highlightColor: Colors.transparent,
- splashColor: Colors.transparent,
+ Widget _buildTitle(BuildContext context, HeaderAppBarTitleState state) {
+ return AnimatedSwitcher(
+ duration: _searchTransitionDuration,
+ switchInCurve: Curves.easeOutCubic,
+ switchOutCurve: Curves.easeInCubic,
+ layoutBuilder: (currentChild, previousChildren) => Stack(
+ alignment: Alignment.centerLeft,
+ clipBehavior: Clip.none,
+ children: [...previousChildren, ?currentChild],
),
- child: GestureDetector(
- onTapDown: (TapDownDetails details) async {
- final l10n = context.strings;
- const sortKeys = PeopleSortKey.values;
- final PeopleSortKey? selectedKey = await showMenu<PeopleSortKey>(
- color: colorScheme.backgroundElevated,
- context: context,
- elevation: 0,
- shape: RoundedRectangleBorder(
- side: BorderSide(width: 0.5, color: colorScheme.strokeFaint),
- borderRadius: BorderRadius.circular(_sortMenuCornerRadius),
- ),
- position: RelativeRect.fromLTRB(
- details.globalPosition.dx,
- details.globalPosition.dy,
- details.globalPosition.dx,
- details.globalPosition.dy + 50,
+ transitionBuilder: (child, animation) {
+ final curvedAnimation = CurvedAnimation(
+ parent: animation,
+ curve: Curves.easeOutCubic,
+ reverseCurve: Curves.easeInCubic,
+ );
+ final beginOffset = child.key == const ValueKey("person_search_field")
+ ? const Offset(0.035, 0)
+ : const Offset(-0.035, 0);
+ return FadeTransition(
+ opacity: curvedAnimation,
+ child: SlideTransition(
+ position: Tween<Offset>(
+ begin: beginOffset,
+ end: Offset.zero,
+ ).animate(curvedAnimation),
+ child: child,
+ ),
+ );
+ },
+ child: _isSearchBarVisible
+ ? KeyedSubtree(
+ key: const ValueKey("person_search_field"),
+ child: TextInputComponent(
+ controller: _searchController,
+ focusNode: _searchFocusNode,
+ hintText: context.strings.search,
+ autofocus: true,
+ shouldUnfocusOnClearOrSubmit: true,
+ prefix: HugeIcon(
+ icon: HugeIcons.strokeRoundedSearch01,
+ size: IconSizes.small,
+ color: context.componentColors.textLight,
+ ),
+ suffix: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: IconSizes.small,
+ color: context.componentColors.textLight,
+ ),
+ onSuffixTap: _closeSearch,
+ onChanged: _updateSearchQuery,
+ ),
+ )
+ : KeyedSubtree(
+ key: const ValueKey("person_title_row"),
+ child: SizedBox(
+ height: state.height,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ Expanded(
+ child: Text(
+ state.title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: state.textStyle,
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ SizedBox.square(
+ dimension: _titleActionSize,
+ child: IconButtonComponent(
+ variant: IconButtonComponentVariant.primary,
+ shouldSurfaceExecutionStates: false,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedSearch01,
+ ),
+ onTap: _activateSearch,
+ ),
+ ),
+ const SizedBox(width: Spacing.sm),
+ SizedBox.square(
+ dimension: _titleActionSize,
+ child: galleryAppBarPopupMenuAction<PeopleSortKey>(
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedFilterHorizontal,
+ ),
+ tooltip: context.strings.sort,
+ optionsBuilder: () => PeopleSortKey.values
+ .map(_buildSortMenuOption)
+ .toList(),
+ onSelected: _selectSortKey,
+ ),
+ ),
+ ],
+ ),
+ ),
),
- items: List.generate(sortKeys.length, (index) {
- final key = sortKeys[index];
- return _buildSortMenuItem(
- key,
- index == sortKeys.length - 1,
- textTheme,
- colorScheme,
- l10n,
- );
- }),
- );
- if (!mounted || selectedKey == null) {
- return;
- }
- if (selectedKey == _sortKey &&
- !_canToggleSortDirection(selectedKey)) {
- return;
- }
- setState(() {
- if (selectedKey == _sortKey) {
- _toggleSortDirection(selectedKey);
- } else {
- _sortKey = selectedKey;
- }
- });
- unawaited(_persistSortPreferences());
- },
- child: IconButtonWidget(
- icon: Icons.sort_rounded,
- iconButtonType: IconButtonType.secondary,
- iconColor: colorScheme.textMuted,
- ),
- ),
);
}
- PopupMenuItem<PeopleSortKey> _buildSortMenuItem(
- PeopleSortKey key,
- bool isLast,
- EnteTextTheme textTheme,
- EnteColorScheme colorScheme,
- StringsLocalizations l10n,
- ) {
+ EntePopupMenuOption<PeopleSortKey> _buildSortMenuOption(PeopleSortKey key) {
+ final l10n = context.strings;
+ final isAscending = _isSortAscending(key);
String label;
+ String detail;
switch (key) {
case PeopleSortKey.mostPhotos:
label = l10n.photos;
+ detail = l10n.count;
break;
case PeopleSortKey.name:
label = l10n.name;
+ detail = isAscending ? l10n.sortAToZ : l10n.sortZToA;
break;
case PeopleSortKey.lastUpdated:
label = l10n.updated;
+ detail = isAscending ? l10n.sortOldestFirst : l10n.sortNewestFirst;
break;
}
- String detail;
- switch (key) {
- case PeopleSortKey.mostPhotos:
- detail = l10n.count;
- break;
- case PeopleSortKey.name:
- detail = _isSortAscending(key) ? "A-Z" : "Z-A";
- break;
- case PeopleSortKey.lastUpdated:
- detail = _isSortAscending(key)
- ? l10n.sortOldestFirst
- : l10n.sortNewestFirst;
- break;
- }
-
- final bool isSelected = _sortKey == key;
- final bool isAscending = _isSortAscending(key);
- final IconData directionIcon = key == PeopleSortKey.name
- ? (isAscending ? Icons.arrow_downward : Icons.arrow_upward)
- : (isAscending ? Icons.arrow_upward : Icons.arrow_downward);
-
- return PopupMenuItem<PeopleSortKey>(
+ final isSelected = _sortKey == key;
+ final directionIcon = key == PeopleSortKey.name
+ ? (isAscending
+ ? HugeIcons.strokeRoundedArrowDown02
+ : HugeIcons.strokeRoundedArrowUp02)
+ : (isAscending
+ ? HugeIcons.strokeRoundedArrowUp02
+ : HugeIcons.strokeRoundedArrowDown02);
+ return EntePopupMenuOption(
value: key,
- padding: EdgeInsets.zero,
- height: _sortMenuItemHeight,
- child: Container(
- width: double.infinity,
- height: _sortMenuItemHeight,
- padding: const EdgeInsets.symmetric(horizontal: 16),
- decoration: BoxDecoration(
- border: isLast
- ? null
- : Border(
- bottom: BorderSide(
- width: 0.5,
- color: colorScheme.strokeFaint,
- ),
- ),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- Text(label, style: textTheme.mini),
- if (isSelected) ...[
- const SizedBox(width: 8),
- Container(
- width: 4,
- height: 4,
- decoration: BoxDecoration(
- color: colorScheme.textMuted.withValues(alpha: 0.6),
- shape: BoxShape.circle,
- ),
- ),
- const SizedBox(width: 6),
- Text(detail, style: textTheme.miniMuted),
- const SizedBox(width: 4),
- Icon(directionIcon, size: 16, color: colorScheme.textMuted),
- ],
- ],
- ),
+ label: label,
+ secondaryLabel: isSelected ? detail : null,
+ isActive: isSelected,
+ activeTrailingWidget: HugeIcon(
+ icon: directionIcon,
+ size: 12,
+ strokeWidth: 3,
),
);
}
+ void _selectSortKey(PeopleSortKey selectedKey) {
+ setState(() {
+ if (selectedKey == _sortKey) {
+ _toggleSortDirection(selectedKey);
+ } else {
+ _sortKey = selectedKey;
+ }
+ });
+ unawaited(_persistSortPreferences());
+ }
+
Future<void> _onPersonSelected(GenericSearchResult result) async {
final personId = result.params[kPersonParamID] as String?;
if (personId == null || personId.isEmpty) {
@@ -537,14 +543,17 @@ class _ManualPersonGridTile extends StatelessWidget {
child: _FaceSearchResult(result: result),
),
),
- Padding(
- padding: const EdgeInsets.only(top: 6),
- child: Text(
- result.name(),
- maxLines: 1,
- textAlign: TextAlign.center,
- overflow: TextOverflow.ellipsis,
- style: textStyle,
+ SizedBox(
+ height: labelHeight,
+ child: Padding(
+ padding: const EdgeInsets.only(top: 6),
+ child: Text(
+ result.name(),
+ maxLines: 1,
+ textAlign: TextAlign.center,
+ overflow: TextOverflow.ellipsis,
+ style: textStyle,
+ ),
),
),
],