π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add search bar to people list
laurenspriem72f1778e3f20
diff --git a/mobile/apps/photos/lib/ui/components/searchable_appbar.dart b/mobile/apps/photos/lib/ui/components/searchable_appbar.dartindex 405a4d13b7..a5441c4ebb 100644--- a/mobile/apps/photos/lib/ui/components/searchable_appbar.dart+++ b/mobile/apps/photos/lib/ui/components/searchable_appbar.dart@@ -10,6 +10,8 @@ class SearchableAppBar extends StatefulWidget {final String heroTag;final bool autoActivateSearch;final Color? backgroundColor;+ final bool? centerTitle;+ final EdgeInsetsGeometry searchIconPadding;const SearchableAppBar({super.key,@@ -20,6 +22,8 @@ class SearchableAppBar extends StatefulWidget {this.heroTag = "",this.autoActivateSearch = false,this.backgroundColor,+ this.centerTitle,+ this.searchIconPadding = const EdgeInsets.all(12.0),});@override@@ -90,6 +94,7 @@ class _SearchableAppBarState extends State<SearchableAppBar> {surfaceTintColor: Colors.transparent,elevation: 0,automaticallyImplyLeading: !_isSearchActive,+ centerTitle: widget.centerTitle,title: AnimatedSwitcher(duration: const Duration(milliseconds: 200),switchInCurve: Curves.easeOut,@@ -116,7 +121,7 @@ class _SearchableAppBarState extends State<SearchableAppBar> {GestureDetector(onTap: _activateSearch,child: Padding(- padding: const EdgeInsets.all(12.0),+ padding: widget.searchIconPadding,child: SizedBox(height: 18,width: 18,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 412deb91a7..34c3f9b275 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@@ -17,6 +17,7 @@ import "package:photos/services/search_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/components/bottom_action_bar/people_bottom_action_bar_widget.dart";+import "package:photos/ui/components/searchable_appbar.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/people/add_person_action_sheet.dart";@@ -32,8 +33,11 @@ import "package:photos/utils/navigation_util.dart";class PeopleSectionAllPage extends StatefulWidget {const PeopleSectionAllPage({super.key,+ this.startInSearchMode = false,});+ final bool startInSearchMode;+@overrideState<PeopleSectionAllPage> createState() => _PeopleSectionAllPageState();}@@ -49,12 +53,10 @@ class _PeopleSectionAllPageState extends State<PeopleSectionAllPage> {final hasSelection = _selectedPeople.personIds.isNotEmpty;return Scaffold(- appBar: AppBar(- title: Text(SectionType.face.sectionTitle(context)),- centerTitle: false,- ),body: PeopleSectionAllSelectionWrapper(selectedPeople: _selectedPeople,+ showSearchBar: true,+ startInSearchMode: widget.startInSearchMode,),bottomNavigationBar: hasSelection? PeopleBottomActionBarWidget(@@ -72,10 +74,14 @@ class _PeopleSectionAllPageState extends State<PeopleSectionAllPage> {class PeopleSectionAllSelectionWrapper extends StatefulWidget {final SelectedPeople selectedPeople;+ final bool showSearchBar;+ final bool startInSearchMode;const PeopleSectionAllSelectionWrapper({super.key,required this.selectedPeople,+ this.showSearchBar = false,+ this.startInSearchMode = false,});@override@@ -89,6 +95,8 @@ class _PeopleSectionAllSelectionWrapperStateWidget build(BuildContext context) {return PeopleSectionAllWidget(selectedPeople: widget.selectedPeople,+ showSearchBar: widget.showSearchBar,+ startInSearchMode: widget.startInSearchMode,);}}@@ -332,10 +340,14 @@ class PeopleSectionAllWidget extends StatefulWidget {super.key,this.selectedPeople,this.namedOnly = false,+ this.showSearchBar = false,+ this.startInSearchMode = false,});final SelectedPeople? selectedPeople;final bool namedOnly;+ final bool showSearchBar;+ final bool startInSearchMode;@overrideState<PeopleSectionAllWidget> createState() => _PeopleSectionAllWidgetState();@@ -350,8 +362,45 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {bool _isLoaded = false;bool _isInitialLoad = true;bool userDismissedPersonGallerySuggestion = false;+ String _searchQuery = "";++ bool get _isSearching => _searchQuery.trim().isNotEmpty;++ bool get _showMoreLessOption =>+ !_isSearching && !widget.namedOnly && extraFaces.isNotEmpty;++ List<GenericSearchResult> _filterFaces(+ List<GenericSearchResult> faces,+ ) {+ if (!_isSearching) {+ return faces;+ }+ final query = _searchQuery.trim().toLowerCase();+ if (query.isEmpty) {+ return faces;+ }+ return faces.where((face) {+ final personId = face.params[kPersonParamID] as String?;+ if (personId == null || personId.isEmpty) {+ return false;+ }+ return face.name().toLowerCase().contains(query);+ }).toList();+ }++ void _updateSearchQuery(String value) {+ setState(() {+ _searchQuery = value;+ });+ }- bool get _showMoreLessOption => !widget.namedOnly && extraFaces.isNotEmpty;+ void _clearSearchQuery() {+ if (_searchQuery.isNotEmpty) {+ setState(() {+ _searchQuery = "";+ });+ }+ }@overridevoid initState() {@@ -452,17 +501,55 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {return FutureBuilder<List<GenericSearchResult>>(future: sectionData,builder: (context, snapshot) {+ final slivers = <Widget>[+ if (widget.showSearchBar)+ SearchableAppBar(+ title: Text(SectionType.face.sectionTitle(context)),+ autoActivateSearch: widget.startInSearchMode,+ onSearch: _updateSearchQuery,+ onSearchClosed: _clearSearchQuery,+ centerTitle: false,+ searchIconPadding:+ const EdgeInsets.fromLTRB(12, 12, horizontalEdgePadding, 12),+ ),+ ];if (!_isLoaded &&snapshot.connectionState == ConnectionState.waiting &&_isInitialLoad) {- return const Center(child: EnteLoadingWidget());+ slivers.add(+ const SliverFillRemaining(+ child: Center(child: EnteLoadingWidget()),+ ),+ );+ return CustomScrollView(slivers: slivers);} else if (snapshot.hasError) {- return const Center(child: Icon(Icons.error_outline_rounded));- } else if (normalFaces.isEmpty && _isLoaded) {- return Center(- child: Text(AppLocalizations.of(context).noResultsFound + '.'),+ slivers.add(+ const SliverFillRemaining(+ child: Center(child: Icon(Icons.error_outline_rounded)),+ ),);+ return CustomScrollView(slivers: slivers);} else {+ final filteredNormalFaces = _filterFaces(normalFaces);+ final filteredExtraFaces =+ _isSearching ? <GenericSearchResult>[] : extraFaces;+ final showExtraFaces = _showingAllFaces &&+ filteredExtraFaces.isNotEmpty &&+ !_isSearching;+ if (_isLoaded &&+ filteredNormalFaces.isEmpty &&+ (!showExtraFaces || filteredExtraFaces.isEmpty)) {+ slivers.add(+ SliverFillRemaining(+ child: Center(+ child: Text(+ AppLocalizations.of(context).noResultsFound + '.',+ ),+ ),+ ),+ );+ return CustomScrollView(slivers: slivers);+ }final screenWidth = MediaQuery.of(context).size.width;final crossAxisCount = (screenWidth / 100).floor();@@ -471,9 +558,11 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {((crossAxisCount - 1) * gridPadding))) /crossAxisCount;- return CustomScrollView(- slivers: [- (!userDismissedPersonGallerySuggestion && !widget.namedOnly)+ slivers.addAll(+ [+ (!userDismissedPersonGallerySuggestion &&+ !widget.namedOnly &&+ !_isSearching)? SliverToBoxAdapter(child: Dismissible(key: const Key("personGallerySuggestionAll"),@@ -510,17 +599,17 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {itemSize / (itemSize + (24 * textScaleFactor)),),delegate: SliverChildBuilderDelegate(- childCount: normalFaces.length,+ childCount: filteredNormalFaces.length,(context, index) {return !widget.namedOnly? SelectablePersonSearchExample(- searchResult: normalFaces[index],+ searchResult: filteredNormalFaces[index],size: itemSize,selectedPeople: widget.selectedPeople!,isDefaultFace: true,): PersonSearchExample(- searchResult: normalFaces[index],+ searchResult: filteredNormalFaces[index],size: itemSize,selectedPeople: widget.selectedPeople!,);@@ -533,7 +622,7 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {const SliverToBoxAdapter(child: SizedBox(height: 16),),- if (_showingAllFaces)+ if (showExtraFaces)SliverPadding(padding: const EdgeInsets.fromLTRB(horizontalEdgePadding,@@ -550,17 +639,17 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {itemSize / (itemSize + (24 * textScaleFactor)),),delegate: SliverChildBuilderDelegate(- childCount: extraFaces.length,+ childCount: filteredExtraFaces.length,(context, index) {return !widget.namedOnly? SelectablePersonSearchExample(- searchResult: extraFaces[index],+ searchResult: filteredExtraFaces[index],size: itemSize,selectedPeople: widget.selectedPeople!,isDefaultFace: false,): PersonSearchExample(- searchResult: extraFaces[index],+ searchResult: filteredExtraFaces[index],size: itemSize,selectedPeople: widget.selectedPeople!,);@@ -568,12 +657,13 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {),),),- if (_showingAllFaces)+ if (showExtraFaces)const SliverToBoxAdapter(child: SizedBox(height: 16),),],);+ return CustomScrollView(slivers: slivers);}},);diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dartindex 8a756510c0..7d5f59280a 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart@@ -13,6 +13,7 @@ import "package:photos/models/search/search_result.dart";import "package:photos/models/search/search_types.dart";import "package:photos/models/selected_people.dart";import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/components/buttons/icon_button_widget.dart";import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";import "package:photos/ui/viewer/file/thumbnail_widget.dart";@@ -82,6 +83,7 @@ class _PeopleSectionState extends State<PeopleSection> {debugPrint("Building section for ${widget.sectionType.name}");final shouldShowMore = _examples.length >= widget.limit - 1;final textTheme = getEnteTextTheme(context);+ final colorScheme = getEnteColorScheme(context);return _examples.isNotEmpty? GestureDetector(behavior: HitTestBehavior.opaque,@@ -106,16 +108,33 @@ class _PeopleSectionState extends State<PeopleSection> {style: textTheme.largeBold,),),- shouldShowMore- ? Padding(+ Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (shouldShowMore)+ IconButtonWidget(+ icon: Icons.search,+ iconButtonType: IconButtonType.secondary,+ iconColor: colorScheme.blurStrokePressed,+ onTap: () {+ routeToPage(+ context,+ const PeopleSectionAllPage(+ startInSearchMode: true,+ ),+ );+ },+ ),+ if (shouldShowMore)+ Padding(padding: const EdgeInsets.all(12),child: Icon(Icons.chevron_right_outlined,- color:- getEnteColorScheme(context).blurStrokePressed,+ color: colorScheme.blurStrokePressed,),- )- : const SizedBox.shrink(),+ ),+ ],+ ),],),const SizedBox(height: 2),