π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add search to all discovery tab sections
laurenspriem73d5935ccf0e
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dartindex c96e361abd..d0a2f6c727 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart@@ -2,9 +2,9 @@ import "dart:async";import "package:collection/collection.dart";import "package:flutter/material.dart";-import "package:flutter_animate/flutter_animate.dart";import "package:photos/events/event.dart";import "package:photos/extensions/list.dart";+import "package:photos/generated/l10n.dart";import "package:photos/models/search/album_search_result.dart";import "package:photos/models/search/generic_search_result.dart";import "package:photos/models/search/hierarchical/magic_filter.dart";@@ -13,7 +13,7 @@ import "package:photos/models/search/search_result.dart";import "package:photos/models/search/search_types.dart";import "package:photos/services/collections_service.dart";import "package:photos/ui/common/loading_widget.dart";-import "package:photos/ui/components/title_bar_title_widget.dart";+import "package:photos/ui/components/searchable_appbar.dart";import "package:photos/ui/viewer/gallery/collection_page.dart";import "package:photos/ui/viewer/search/result/magic_result_screen.dart";import "package:photos/ui/viewer/search/result/searchable_item.dart";@@ -21,7 +21,12 @@ import "package:photos/utils/navigation_util.dart";class SearchSectionAllPage extends StatefulWidget {final SectionType sectionType;- const SearchSectionAllPage({required this.sectionType, super.key});+ final bool startInSearchMode;+ const SearchSectionAllPage({+ required this.sectionType,+ this.startInSearchMode = false,+ super.key,+ });@overrideState<SearchSectionAllPage> createState() => _SearchSectionAllPageState();@@ -30,6 +35,9 @@ class SearchSectionAllPage extends StatefulWidget {class _SearchSectionAllPageState extends State<SearchSectionAllPage> {late Future<List<SearchResult>> sectionData;final streamSubscriptions = <StreamSubscription>[];+ String _searchQuery = "";++ bool get _isSearching => _searchQuery.trim().isNotEmpty;@overridevoid initState() {@@ -48,6 +56,33 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {}}+ void _updateSearchQuery(String value) {+ setState(() {+ _searchQuery = value;+ });+ }++ void _clearSearchQuery() {+ if (_searchQuery.isNotEmpty) {+ setState(() {+ _searchQuery = "";+ });+ }+ }++ List<SearchResult> _filterResults(List<SearchResult> sectionResults) {+ if (!_isSearching) {+ return sectionResults;+ }+ final query = _searchQuery.trim().toLowerCase();+ if (query.isEmpty) {+ return sectionResults;+ }+ return sectionResults+ .where((result) => result.name().toLowerCase().contains(query))+ .toList();+ }+@overridevoid dispose() {for (var subscriptions in streamSubscriptions) {@@ -58,188 +93,160 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {@overrideWidget build(BuildContext context) {+ const horizontalEdgePadding = 16.0;+ final cacheExtent = widget.sectionType == SectionType.album ? 400.0 : null;return Scaffold(- appBar: AppBar(- toolbarHeight: 48,- leadingWidth: 48,- leading: GestureDetector(- onTap: () {- Navigator.pop(context);- },- child: const Icon(- Icons.arrow_back_outlined,- ),- ),- ),- body: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Padding(- padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- TitleBarTitleWidget(- title: widget.sectionType.sectionTitle(context),- ),- FutureBuilder(- future: sectionData,- builder: (context, snapshot) {- if (snapshot.hasData) {- final sectionResults = snapshot.data!;- return Text(sectionResults.length.toString())- .animate()- .fadeIn(- duration: const Duration(milliseconds: 150),- curve: Curves.easeIn,- );- } else {- return const SizedBox.shrink();- }- },- ),- ],+ body: FutureBuilder<List<SearchResult>>(+ future: sectionData,+ builder: (context, snapshot) {+ final slivers = <Widget>[+ SearchableAppBar(+ title: Text(widget.sectionType.sectionTitle(context)),+ autoActivateSearch: widget.startInSearchMode,+ onSearch: _updateSearchQuery,+ onSearchClosed: _clearSearchQuery,+ centerTitle: false,+ searchIconPadding: const EdgeInsets.fromLTRB(+ 12,+ 12,+ horizontalEdgePadding,+ 12,+ ),),- ),- Expanded(- child: Padding(- padding: const EdgeInsets.symmetric(- vertical: 20,- horizontal: 16,+ ];++ if (!snapshot.hasData) {+ slivers.add(+ const SliverFillRemaining(+ child: Center(child: EnteLoadingWidget()),),- child: FutureBuilder(- future: sectionData,- builder: (context, snapshot) {- if (snapshot.hasData) {- List<SearchResult> sectionResults = snapshot.data!;-- if (widget.sectionType.sortByName) {- sectionResults.sort(- (a, b) =>- compareAsciiLowerCaseNatural(a.name(), b.name()),- );- }-- if (widget.sectionType == SectionType.location) {- final result = sectionResults.splitMatch(- (e) => e.type() == ResultType.location,- );- sectionResults = result.matched;- sectionResults.addAll(result.unmatched);- }- return ListView.separated(- itemBuilder: (context, index) {- if (index == 0 && widget.sectionType.isCTAVisible) {- return SearchableItemPlaceholder(- widget.sectionType,- );- }- final adjustedIndex =- widget.sectionType.isCTAVisible ? index - 1 : index;- if (sectionResults[adjustedIndex]- is AlbumSearchResult) {- final albumSectionResult =- sectionResults[adjustedIndex]- as AlbumSearchResult;- return SearchableItemWidget(- albumSectionResult,- resultCount:- CollectionsService.instance.getFileCount(- albumSectionResult- .collectionWithThumbnail.collection,- ),- onResultTap: () {- RecentSearches()- .add(sectionResults[adjustedIndex].name());-- routeToPage(- context,- CollectionPage(- albumSectionResult.collectionWithThumbnail,- tagPrefix: "searchable_item" +- albumSectionResult.heroTag(),- ),- );- },- );- }-- if (widget.sectionType == SectionType.magic) {- final magicSectionResult =- sectionResults[adjustedIndex]- as GenericSearchResult;- return SearchableItemWidget(- magicSectionResult,- onResultTap: () {- RecentSearches()- .add(sectionResults[adjustedIndex].name());- routeToPage(- context,- MagicResultScreen(- magicSectionResult.resultFiles(),- name: magicSectionResult.name(),- enableGrouping: magicSectionResult- .params["enableGrouping"]! as bool,- fileIdToPosMap: magicSectionResult- .params["fileIdToPosMap"]- as Map<int, int>,- heroTag: "searchable_item" +- magicSectionResult.heroTag(),- magicFilter: magicSectionResult- .getHierarchicalSearchFilter()- as MagicFilter,- ),- );- },- );- } else if (sectionResults[adjustedIndex]- is GenericSearchResult) {- final result = sectionResults[adjustedIndex]- as GenericSearchResult;- return SearchableItemWidget(- sectionResults[adjustedIndex],- onResultTap: result.onResultTap != null- ? () => result.onResultTap!(context)- : null,- );- }- return SearchableItemWidget(- sectionResults[adjustedIndex],- );- },- separatorBuilder: (context, index) {+ );+ return CustomScrollView(+ physics: const BouncingScrollPhysics(),+ cacheExtent: cacheExtent,+ slivers: slivers,+ );+ }++ List<SearchResult> sectionResults = snapshot.data!;++ if (widget.sectionType.sortByName) {+ sectionResults.sort(+ (a, b) => compareAsciiLowerCaseNatural(a.name(), b.name()),+ );+ }++ if (widget.sectionType == SectionType.location) {+ final result = sectionResults.splitMatch(+ (e) => e.type() == ResultType.location,+ );+ sectionResults = result.matched;+ sectionResults.addAll(result.unmatched);+ }++ final filteredResults = _filterResults(sectionResults);+ if (_isSearching && filteredResults.isEmpty) {+ slivers.add(+ SliverFillRemaining(+ child: Center(+ child: Text(+ AppLocalizations.of(context).noResultsFound + '.',+ ),+ ),+ ),+ );+ return CustomScrollView(+ physics: const BouncingScrollPhysics(),+ cacheExtent: cacheExtent,+ slivers: slivers,+ );+ }++ final showCTA = widget.sectionType.isCTAVisible && !_isSearching;+ final totalItems = filteredResults.length + (showCTA ? 1 : 0);+ if (totalItems > 0) {+ slivers.add(+ SliverPadding(+ padding: const EdgeInsets.symmetric(+ vertical: 20,+ horizontal: horizontalEdgePadding,+ ),+ sliver: SliverList(+ delegate: SliverChildBuilderDelegate(+ (context, index) {+ if (index.isOdd) {return const SizedBox(height: 10);- },- itemCount: sectionResults.length +- (widget.sectionType.isCTAVisible ? 1 : 0),- physics: const BouncingScrollPhysics(),- //This cache extend is needed for creating a new album- //using SearchSectionCTATile to work. This is so that- //SearchSectionCTATile doesn't get disposed when keyboard- //is open and the widget is out of view.- cacheExtent:- widget.sectionType == SectionType.album ? 400 : null,- )- .animate()- .fadeIn(- duration: const Duration(milliseconds: 225),- curve: Curves.easeIn,- )- .slide(- begin: const Offset(0, -0.01),- curve: Curves.easeIn,- duration: const Duration(- milliseconds: 225,+ }+ final itemIndex = index ~/ 2;+ if (showCTA && itemIndex == 0) {+ return SearchableItemPlaceholder(widget.sectionType);+ }+ final adjustedIndex = showCTA ? itemIndex - 1 : itemIndex;+ final result = filteredResults[adjustedIndex];+ if (result is AlbumSearchResult) {+ return SearchableItemWidget(+ result,+ resultCount: CollectionsService.instance.getFileCount(+ result.collectionWithThumbnail.collection,),+ onResultTap: () {+ RecentSearches().add(result.name());+ routeToPage(+ context,+ CollectionPage(+ result.collectionWithThumbnail,+ tagPrefix: "searchable_item" + result.heroTag(),+ ),+ );+ },+ );+ }++ if (widget.sectionType == SectionType.magic &&+ result is GenericSearchResult) {+ return SearchableItemWidget(+ result,+ onResultTap: () {+ RecentSearches().add(result.name());+ routeToPage(+ context,+ MagicResultScreen(+ result.resultFiles(),+ name: result.name(),+ enableGrouping:+ result.params["enableGrouping"]! as bool,+ fileIdToPosMap: result.params["fileIdToPosMap"]+ as Map<int, int>,+ heroTag: "searchable_item" + result.heroTag(),+ magicFilter:+ result.getHierarchicalSearchFilter()+ as MagicFilter,+ ),+ );+ },);- } else {- return const EnteLoadingWidget();- }- },+ } else if (result is GenericSearchResult) {+ return SearchableItemWidget(+ result,+ onResultTap: result.onResultTap != null+ ? () => result.onResultTap!(context)+ : null,+ );+ }+ return SearchableItemWidget(result);+ },+ childCount: totalItems * 2 - 1,+ ),+ ),),- ),- ),- ],+ );+ }+ return CustomScrollView(+ physics: const BouncingScrollPhysics(),+ cacheExtent: cacheExtent,+ slivers: slivers,+ );+ },),);}diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/albums_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/albums_section.dartindex 6febe0cc0e..ea7b518707 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/albums_section.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/albums_section.dart@@ -109,6 +109,7 @@ class _AlbumsSectionState extends State<AlbumsSection> {SectionHeader(SectionType.album,hasMore: (_albumSearchResults.length >= kSearchSectionLimit - 1),+ showSearch: true,),const SizedBox(height: 2),SizedBox(diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dartindex d67ac9e6be..7a0bde4453 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/file_type_section.dart@@ -102,6 +102,7 @@ class _FileTypeSectionState extends State<FileTypeSection> {SectionType.fileTypesAndExtension,hasMore:(_fileTypesSearchResults.length >= kSearchSectionLimit - 1),+ showSearch: true,),const SizedBox(height: 2),SizedBox(diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dartindex 1f8db52ba2..385b30d1f5 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart@@ -121,6 +121,7 @@ class _LocationsSectionState extends State<LocationsSection> {SectionType.location,hasMore:(_locationsSearchResults.length >= kSearchSectionLimit - 1),+ showSearch: true,),const SizedBox(height: 2),SizedBox(diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dartindex a527e5469d..4a37bd23c0 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/magic_section.dart@@ -102,6 +102,7 @@ class _MagicSectionState extends State<MagicSection> {SectionHeader(SectionType.magic,hasMore: (_magicSearchResults.length >= kSearchSectionLimit - 1),+ showSearch: true,),const SizedBox(height: 2),SizedBox(diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/section_header.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/section_header.dartindex 31f1f4a4d2..a8854a5a3e 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/section_header.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/section_header.dart@@ -1,16 +1,24 @@import "package:flutter/material.dart";import "package:photos/models/search/search_types.dart";import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/components/buttons/icon_button_widget.dart";import "package:photos/ui/viewer/search/result/search_section_all_page.dart";import "package:photos/utils/navigation_util.dart";class SectionHeader extends StatelessWidget {final SectionType sectionType;final bool hasMore;- const SectionHeader(this.sectionType, {required this.hasMore, super.key});+ final bool showSearch;+ const SectionHeader(+ this.sectionType, {+ required this.hasMore,+ this.showSearch = false,+ super.key,+ });@overrideWidget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);return GestureDetector(onTap: () {if (hasMore) {@@ -33,15 +41,32 @@ class SectionHeader extends StatelessWidget {),),hasMore- ? Container(- color: Colors.transparent,- child: Padding(- padding: const EdgeInsets.fromLTRB(24, 12, 12, 12),- child: Icon(- Icons.chevron_right_outlined,- color: getEnteColorScheme(context).blurStrokePressed,+ ? Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (showSearch)+ IconButtonWidget(+ icon: Icons.search,+ iconButtonType: IconButtonType.secondary,+ iconColor: colorScheme.blurStrokePressed,+ onTap: () {+ routeToPage(+ context,+ SearchSectionAllPage(+ sectionType: sectionType,+ startInSearchMode: true,+ ),+ );+ },+ ),+ Padding(+ padding: const EdgeInsets.fromLTRB(24, 12, 12, 12),+ child: Icon(+ Icons.chevron_right_outlined,+ color: colorScheme.blurStrokePressed,+ ),),- ),+ ],): const SizedBox.shrink(),],