Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add search bar to manual people tagging

laurenspriembbfc6cd6f03d
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 f7ea236f4d..b163a2e42c 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
@@ -9,6 +9,7 @@ import "package:photos/services/machine_learning/face_ml/person/person_service.d
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/searchable_appbar.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";
import "package:photos/ui/viewer/people/person_face_widget.dart";
@@ -80,6 +81,7 @@ class AddFilesToPersonPage extends StatefulWidget {
class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
late Future<List<GenericSearchResult>> _personsFuture;
+ String _searchQuery = "";
@override
void initState() {
@@ -90,6 +92,32 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
: AddFilesToPersonPage.loadNamedPersons();
}
+ List<GenericSearchResult> _filterPersons(
+ List<GenericSearchResult> persons,
+ ) {
+ final query = _searchQuery.trim().toLowerCase();
+ if (query.isEmpty) {
+ return persons;
+ }
+ return persons
+ .where((person) => person.name().toLowerCase().contains(query))
+ .toList();
+ }
+
+ void _updateSearchQuery(String value) {
+ setState(() {
+ _searchQuery = value;
+ });
+ }
+
+ void _clearSearchQuery() {
+ if (_searchQuery.isNotEmpty) {
+ setState(() {
+ _searchQuery = "";
+ });
+ }
+ }
+
@override
Widget build(BuildContext context) {
final smallFontSize = getEnteTextTheme(context).small.fontSize!;
@@ -100,29 +128,56 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
const gridPadding = 16.0;
return Scaffold(
- appBar: AppBar(
- title: Text(AppLocalizations.of(context).addPerson),
- centerTitle: false,
- ),
body: FutureBuilder<List<GenericSearchResult>>(
future: _personsFuture,
builder: (context, snapshot) {
+ final slivers = <Widget>[
+ SearchableAppBar(
+ title: Text(AppLocalizations.of(context).addPerson),
+ onSearch: _updateSearchQuery,
+ onSearchClosed: _clearSearchQuery,
+ centerTitle: false,
+ searchIconPadding: const EdgeInsets.fromLTRB(
+ 12,
+ 12,
+ horizontalEdgePadding,
+ 12,
+ ),
+ ),
+ ];
if (snapshot.connectionState == ConnectionState.waiting) {
- return const Center(child: EnteLoadingWidget());
+ 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",
snapshot.error,
snapshot.stackTrace,
);
- return const Center(child: Icon(Icons.error_outline_rounded));
- } else if (!snapshot.hasData || snapshot.data!.isEmpty) {
- return Center(
- child: Text(AppLocalizations.of(context).noResultsFound),
+ slivers.add(
+ const SliverFillRemaining(
+ child: Center(child: Icon(Icons.error_outline_rounded)),
+ ),
);
+ return CustomScrollView(slivers: slivers);
}
- final results = snapshot.data!;
+ final persons = snapshot.data ?? [];
+ final results = _filterPersons(persons);
+ if (results.isEmpty) {
+ slivers.add(
+ SliverFillRemaining(
+ child: Center(
+ child: Text(AppLocalizations.of(context).noResultsFound),
+ ),
+ ),
+ );
+ return CustomScrollView(slivers: slivers);
+ }
final screenWidth = MediaQuery.of(context).size.width;
final estimatedCount = (screenWidth / 100).floor();
final crossAxisCount = estimatedCount > 0 ? estimatedCount : 1;
@@ -132,38 +187,37 @@ class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
crossAxisCount;
final bottomPadding = MediaQuery.paddingOf(context).bottom;
- return CustomScrollView(
- slivers: [
- SliverPadding(
- padding: EdgeInsets.fromLTRB(
- horizontalEdgePadding,
- 16,
- horizontalEdgePadding,
- 16 + bottomPadding,
+ 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),
),
- sliver: SliverGrid(
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- mainAxisSpacing: gridPadding,
- crossAxisSpacing: gridPadding,
- crossAxisCount: crossAxisCount,
- childAspectRatio: itemSize / (itemSize + textHeight),
- ),
- delegate: SliverChildBuilderDelegate(
- childCount: results.length,
- (context, index) {
- final person = results[index];
- return _ManualPersonGridTile(
- result: person,
- size: itemSize,
- labelHeight: textHeight,
- onTap: () => _onPersonSelected(person),
- );
- },
- ),
+ delegate: SliverChildBuilderDelegate(
+ childCount: results.length,
+ (context, index) {
+ final person = results[index];
+ return _ManualPersonGridTile(
+ result: person,
+ size: itemSize,
+ labelHeight: textHeight,
+ onTap: () => _onPersonSelected(person),
+ );
+ },
),
),
- ],
+ ),
);
+ return CustomScrollView(slivers: slivers);
},
),
);
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.dart
index 34c3f9b275..0044db8704 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
@@ -531,14 +531,12 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
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)) {
+ final filteredExtraFaces = _filterFaces(extraFaces);
+ final hasResults = _isSearching
+ ? filteredNormalFaces.isNotEmpty || filteredExtraFaces.isNotEmpty
+ : filteredNormalFaces.isNotEmpty ||
+ (!widget.namedOnly && filteredExtraFaces.isNotEmpty);
+ if (_isLoaded && !hasResults) {
slivers.add(
SliverFillRemaining(
child: Center(
@@ -558,31 +556,13 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
((crossAxisCount - 1) * gridPadding))) /
crossAxisCount;
- slivers.addAll(
- [
- (!userDismissedPersonGallerySuggestion &&
- !widget.namedOnly &&
- !_isSearching)
- ? SliverToBoxAdapter(
- child: Dismissible(
- key: const Key("personGallerySuggestionAll"),
- direction: DismissDirection.horizontal,
- onDismissed: (direction) {
- setState(() {
- userDismissedPersonGallerySuggestion = true;
- });
- },
- child: PersonGallerySuggestion(
- person: null,
- onClose: () {
- setState(() {
- userDismissedPersonGallerySuggestion = true;
- });
- },
- ),
- ),
- )
- : const SliverToBoxAdapter(child: SizedBox.shrink()),
+ if (_isSearching) {
+ final searchResults = [
+ ...filteredNormalFaces,
+ ...filteredExtraFaces,
+ ];
+ final defaultFaces = filteredNormalFaces.toSet();
+ slivers.add(
SliverPadding(
padding: const EdgeInsets.fromLTRB(
horizontalEdgePadding,
@@ -599,17 +579,18 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
itemSize / (itemSize + (24 * textScaleFactor)),
),
delegate: SliverChildBuilderDelegate(
- childCount: filteredNormalFaces.length,
+ childCount: searchResults.length,
(context, index) {
+ final result = searchResults[index];
return !widget.namedOnly
? SelectablePersonSearchExample(
- searchResult: filteredNormalFaces[index],
+ searchResult: result,
size: itemSize,
selectedPeople: widget.selectedPeople!,
- isDefaultFace: true,
+ isDefaultFace: defaultFaces.contains(result),
)
: PersonSearchExample(
- searchResult: filteredNormalFaces[index],
+ searchResult: result,
size: itemSize,
selectedPeople: widget.selectedPeople!,
);
@@ -617,12 +598,38 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
),
),
),
- if (_showMoreLessOption)
- SliverToBoxAdapter(child: _buildShowMoreOrLessButton(context)),
+ );
+ slivers.add(
const SliverToBoxAdapter(
child: SizedBox(height: 16),
),
- if (showExtraFaces)
+ );
+ } else {
+ final showExtraFaces =
+ _showingAllFaces && filteredExtraFaces.isNotEmpty;
+ slivers.addAll(
+ [
+ (!userDismissedPersonGallerySuggestion && !widget.namedOnly)
+ ? SliverToBoxAdapter(
+ child: Dismissible(
+ key: const Key("personGallerySuggestionAll"),
+ direction: DismissDirection.horizontal,
+ onDismissed: (direction) {
+ setState(() {
+ userDismissedPersonGallerySuggestion = true;
+ });
+ },
+ child: PersonGallerySuggestion(
+ person: null,
+ onClose: () {
+ setState(() {
+ userDismissedPersonGallerySuggestion = true;
+ });
+ },
+ ),
+ ),
+ )
+ : const SliverToBoxAdapter(child: SizedBox.shrink()),
SliverPadding(
padding: const EdgeInsets.fromLTRB(
horizontalEdgePadding,
@@ -639,17 +646,17 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
itemSize / (itemSize + (24 * textScaleFactor)),
),
delegate: SliverChildBuilderDelegate(
- childCount: filteredExtraFaces.length,
+ childCount: filteredNormalFaces.length,
(context, index) {
return !widget.namedOnly
? SelectablePersonSearchExample(
- searchResult: filteredExtraFaces[index],
+ searchResult: filteredNormalFaces[index],
size: itemSize,
selectedPeople: widget.selectedPeople!,
- isDefaultFace: false,
+ isDefaultFace: true,
)
: PersonSearchExample(
- searchResult: filteredExtraFaces[index],
+ searchResult: filteredNormalFaces[index],
size: itemSize,
selectedPeople: widget.selectedPeople!,
);
@@ -657,12 +664,55 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
),
),
),
- if (showExtraFaces)
+ if (_showMoreLessOption)
+ SliverToBoxAdapter(
+ child: _buildShowMoreOrLessButton(context),
+ ),
const SliverToBoxAdapter(
child: SizedBox(height: 16),
),
- ],
- );
+ if (showExtraFaces)
+ SliverPadding(
+ padding: const EdgeInsets.fromLTRB(
+ horizontalEdgePadding,
+ 16,
+ horizontalEdgePadding,
+ 16,
+ ),
+ sliver: SliverGrid(
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
+ mainAxisSpacing: gridPadding,
+ crossAxisSpacing: gridPadding,
+ crossAxisCount: crossAxisCount,
+ childAspectRatio:
+ itemSize / (itemSize + (24 * textScaleFactor)),
+ ),
+ delegate: SliverChildBuilderDelegate(
+ childCount: filteredExtraFaces.length,
+ (context, index) {
+ return !widget.namedOnly
+ ? SelectablePersonSearchExample(
+ searchResult: filteredExtraFaces[index],
+ size: itemSize,
+ selectedPeople: widget.selectedPeople!,
+ isDefaultFace: false,
+ )
+ : PersonSearchExample(
+ searchResult: filteredExtraFaces[index],
+ size: itemSize,
+ selectedPeople: widget.selectedPeople!,
+ );
+ },
+ ),
+ ),
+ ),
+ if (showExtraFaces)
+ const SliverToBoxAdapter(
+ child: SizedBox(height: 16),
+ ),
+ ],
+ );
+ }
return CustomScrollView(slivers: slivers);
}
},