π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make search previews adapt to screen width
ashilkn310b6b625ac4
diff --git a/mobile/apps/photos/changes/dynamic-search-preview-limits.md b/mobile/apps/photos/changes/dynamic-search-preview-limits.mdnew file mode 100644index 0000000000..e581bed859--- /dev/null+++ b/mobile/apps/photos/changes/dynamic-search-preview-limits.md@@ -0,0 +1 @@+- Adjust search tab preview counts to fit the screen width.diff --git a/mobile/apps/photos/lib/models/search/search_types.dart b/mobile/apps/photos/lib/models/search/search_types.dartindex bd3915a226..851e99c269 100644--- a/mobile/apps/photos/lib/models/search/search_types.dart+++ b/mobile/apps/photos/lib/models/search/search_types.dart@@ -258,7 +258,10 @@ extension SectionTypeExtensions on SectionType {: kMinimumClusterSizeSearchResult,);case SectionType.magic:- return SearchService.instance.getMagicSectionResults(context!);+ return SearchService.instance.getMagicSectionResults(+ context!,+ limit: limit,+ );case SectionType.wrapped:return Future.value(const <SearchResult>[]);case SectionType.location:diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dartindex 3636e5e682..a4243afb1c 100644--- a/mobile/apps/photos/lib/services/search_service.dart+++ b/mobile/apps/photos/lib/services/search_service.dart@@ -428,10 +428,16 @@ class SearchService {}Future<List<GenericSearchResult>> getMagicSectionResults(- BuildContext context,- ) async {+ BuildContext context, {+ int? limit,+ }) async {if (hasGrantedMLConsent) {- return magicCacheService.getMagicGenericSearchResult(context);+ final results = await magicCacheService.getMagicGenericSearchResult(+ context,+ );+ return limit == null+ ? results+ : results.take(limit).toList(growable: false);} else {return <GenericSearchResult>[];}diff --git a/mobile/apps/photos/lib/states/all_sections_examples_state.dart b/mobile/apps/photos/lib/states/all_sections_examples_state.dartindex c42b3fac4f..af1654da5b 100644--- a/mobile/apps/photos/lib/states/all_sections_examples_state.dart+++ b/mobile/apps/photos/lib/states/all_sections_examples_state.dart@@ -4,7 +4,6 @@ import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/foundation.dart";import "package:flutter/material.dart";import "package:logging/logging.dart";-import "package:photos/core/constants.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/files_updated_event.dart";import "package:photos/events/people_changed_event.dart";@@ -13,6 +12,7 @@ import "package:photos/events/tab_changed_event.dart";import "package:photos/models/search/search_result.dart";import "package:photos/models/search/search_types.dart";import "package:photos/services/search_service.dart";+import "package:photos/ui/viewer/search_tab/search_tab_preview_limits.dart";class AllSectionsExamplesData {final List<List<SearchResult>> sectionResults;@@ -26,7 +26,13 @@ class AllSectionsExamplesData {class AllSectionsExamplesProvider extends StatefulWidget {final Widget child;- const AllSectionsExamplesProvider({super.key, required this.child});+ final SearchTabPreviewLimits previewLimits;++ const AllSectionsExamplesProvider({+ super.key,+ required this.child,+ required this.previewLimits,+ });@overrideState<AllSectionsExamplesProvider> createState() =>@@ -115,6 +121,15 @@ class _AllSectionsExamplesProviderState}}+ @override+ void didUpdateWidget(covariant AllSectionsExamplesProvider oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.previewLimits != widget.previewLimits &&+ _firstLoadInProgressOrComplete) {+ reloadAllSections();+ }+ }+void reloadAllSections() {_firstLoadInProgressOrComplete = true;_logger.info('queue reload all sections');@@ -133,7 +148,7 @@ class _AllSectionsExamplesProviderStateallSectionsExamples.add(Future.value([]));} else {allSectionsExamples.add(- sectionType.getData(context, limit: kSearchSectionLimit),+ sectionType.getData(context, limit: _fetchLimitFor(sectionType)),);}}@@ -161,6 +176,15 @@ class _AllSectionsExamplesProviderState_initialLoadTimer = null;}+ int _fetchLimitFor(SectionType sectionType) {+ return switch (sectionType) {+ SectionType.face => widget.previewLimits.faceFetchLimit,+ SectionType.magic => widget.previewLimits.magicFetchLimit,+ SectionType.location => widget.previewLimits.locationFetchLimit,+ _ => 0,+ };+ }+@overridevoid dispose() {_onPeopleChangedEvent.cancel();diff --git a/mobile/apps/photos/lib/ui/rituals/rituals_banner.dart b/mobile/apps/photos/lib/ui/rituals/rituals_banner.dartindex 10b4183876..e806ab3a52 100644--- a/mobile/apps/photos/lib/ui/rituals/rituals_banner.dart+++ b/mobile/apps/photos/lib/ui/rituals/rituals_banner.dart@@ -20,12 +20,14 @@ import "package:photos/ui/rituals/start_new_ritual_card.dart";import "package:photos/ui/viewer/search_tab/search_tab_horizontal_scroll.dart";class RitualsBanner extends StatelessWidget {- const RitualsBanner({super.key});+ const RitualsBanner({super.key, required this.resultLimit});static const _cardRadius = 25.0;static const _minCardHeight = 94.0;static const _cardWidth = 167.5;+ final int resultLimit;+@overrideWidget build(BuildContext context) {if (!flagService.ritualsFlag) {@@ -68,13 +70,16 @@ class RitualsBanner extends StatelessWidget {Builder(builder: (context) {final cardHeight = _cardHeightFor(context);+ final visibleRituals = rituals+ .take(resultLimit)+ .toList(growable: false);return SearchTabHorizontalScrollView(height: cardHeight,child: Row(children: [for (final (index, item) in _buildRowItems(context,- rituals,+ visibleRituals,summary,cardHeight,).indexed) ...[diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dartindex d40abbd4e4..6c9a2c2ae7 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/contacts_section.dart@@ -4,7 +4,6 @@ import "package:ente_components/ente_components.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/material.dart";import "package:flutter_svg/flutter_svg.dart";-import "package:photos/core/constants.dart";import "package:photos/events/event.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/search/generic_search_result.dart";@@ -21,7 +20,9 @@ import "package:photos/ui/viewer/search_tab/search_tab_horizontal_scroll.dart";import "package:photos/ui/viewer/search_tab/section_header.dart";class ContactsSectionLoader extends StatefulWidget {- const ContactsSectionLoader({super.key});+ final int resultLimit;++ const ContactsSectionLoader({super.key, required this.resultLimit});@overrideState<ContactsSectionLoader> createState() => _ContactsSectionLoaderState();@@ -36,18 +37,29 @@ class _ContactsSectionLoaderState extends State<ContactsSectionLoader> {return const SizedBox.shrink();}_contactsFuture ??= SearchService.instance.getAllContactsSearchResults(- kSearchSectionLimit,+ widget.resultLimit + 1,);return FutureBuilder<List<GenericSearchResult>>(future: _contactsFuture!,builder: (context, snapshot) {if (snapshot.hasData) {- return ContactsSection(snapshot.data!);+ return ContactsSection(+ snapshot.data!,+ resultLimit: widget.resultLimit,+ );}return const ContactsLoadingSection();},);}++ @override+ void didUpdateWidget(covariant ContactsSectionLoader oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.resultLimit != widget.resultLimit) {+ _contactsFuture = null;+ }+ }}class ContactsLoadingSection extends StatelessWidget {@@ -70,7 +82,13 @@ class ContactsLoadingSection extends StatelessWidget {class ContactsSection extends StatefulWidget {final List<GenericSearchResult> contactSearchResults;- const ContactsSection(this.contactSearchResults, {super.key});+ final int resultLimit;++ const ContactsSection(+ this.contactSearchResults, {+ super.key,+ required this.resultLimit,+ });@overrideState<ContactsSection> createState() => _ContactsSectionState();@@ -94,7 +112,7 @@ class _ContactsSectionState extends State<ContactsSection> {_contactSearchResults =(await SectionType.contacts.getData(context,- limit: kSearchSectionLimit,+ limit: widget.resultLimit + 1,))as List<GenericSearchResult>;setState(() {});@@ -159,6 +177,9 @@ class _ContactsSectionState extends State<ContactsSection> {),);} else {+ final visibleResults = _contactSearchResults+ .take(widget.resultLimit)+ .toList(growable: false);return Padding(padding: const EdgeInsets.only(bottom: 20),child: Column(@@ -166,14 +187,13 @@ class _ContactsSectionState extends State<ContactsSection> {children: [SectionHeader(SectionType.contacts,- hasMore:- (_contactSearchResults.length >= kSearchSectionLimit - 1),+ hasMore: _contactSearchResults.length > widget.resultLimit,),const SizedBox(height: 4),SearchTabHorizontalRow(spacing: 12,children: [- for (final contactSearchResult in _contactSearchResults)+ for (final contactSearchResult in visibleResults)ContactRecommendation(contactSearchResult,key: ValueKey(contactSearchResult.name()),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 36b234bcd0..8c53529ab2 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@@ -4,7 +4,6 @@ import "package:ente_components/ente_components.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:figma_squircle/figma_squircle.dart";import "package:flutter/material.dart";-import "package:photos/core/constants.dart";import "package:photos/events/event.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/search/generic_search_result.dart";@@ -23,7 +22,13 @@ import "package:photos/ui/viewer/search_tab/section_header.dart";class LocationsSection extends StatefulWidget {final List<GenericSearchResult> locationsSearchResults;- const LocationsSection(this.locationsSearchResults, {super.key});+ final int resultLimit;++ const LocationsSection(+ this.locationsSearchResults, {+ super.key,+ required this.resultLimit,+ });@overrideState<LocationsSection> createState() => _LocationsSectionState();@@ -45,7 +50,7 @@ class _LocationsSectionState extends State<LocationsSection> {_locationsSearchResults =(await SectionType.location.getData(context,- limit: kSearchSectionLimit,+ limit: widget.resultLimit + 1,))as List<GenericSearchResult>;setState(() {});@@ -106,6 +111,9 @@ class _LocationsSectionState extends State<LocationsSection> {),);} else {+ final visibleResults = _locationsSearchResults+ .take(widget.resultLimit)+ .toList(growable: false);return Padding(padding: const EdgeInsets.only(bottom: 20),child: Column(@@ -113,15 +121,14 @@ class _LocationsSectionState extends State<LocationsSection> {children: [SectionHeader(SectionType.location,- hasMore:- (_locationsSearchResults.length >= kSearchSectionLimit - 1),+ hasMore: _locationsSearchResults.length > widget.resultLimit,),const SizedBox(height: 4),SearchTabHorizontalRow(spacing: 10,children: [const GoToMapTile(),- for (final locationSearchResult in _locationsSearchResults)+ for (final locationSearchResult in visibleResults)LocationRecommendation(locationSearchResult),],),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 da930de87f..f016969cf3 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@@ -3,7 +3,6 @@ import "dart:async";import "package:ente_components/ente_components.dart";import "package:figma_squircle/figma_squircle.dart";import "package:flutter/material.dart";-import "package:photos/core/constants.dart";import "package:photos/events/event.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/search/generic_search_result.dart";@@ -17,7 +16,13 @@ import "package:photos/ui/viewer/search_tab/section_header.dart";class MagicSection extends StatefulWidget {final List<GenericSearchResult> magicSearchResults;- const MagicSection(this.magicSearchResults, {super.key});+ final int resultLimit;++ const MagicSection(+ this.magicSearchResults, {+ super.key,+ required this.resultLimit,+ });@overrideState<MagicSection> createState() => _MagicSectionState();@@ -39,7 +44,7 @@ class _MagicSectionState extends State<MagicSection> {_magicSearchResults =(await SectionType.magic.getData(context,- limit: kSearchSectionLimit,+ limit: widget.resultLimit + 1,))as List<GenericSearchResult>;setState(() {});@@ -98,6 +103,9 @@ class _MagicSectionState extends State<MagicSection> {// );return const SizedBox.shrink();} else {+ final visibleResults = _magicSearchResults+ .take(widget.resultLimit)+ .toList(growable: false);return Padding(padding: const EdgeInsets.only(bottom: 20),child: Column(@@ -105,13 +113,13 @@ class _MagicSectionState extends State<MagicSection> {children: [SectionHeader(SectionType.magic,- hasMore: (_magicSearchResults.length >= kSearchSectionLimit - 1),+ hasMore: _magicSearchResults.length > widget.resultLimit,),const SizedBox(height: 4),SearchTabHorizontalRow(spacing: 10,children: [- for (final magicSearchResult in _magicSearchResults)+ for (final magicSearchResult in visibleResults)MagicRecommendation(magicSearchResult),],),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 7510a20e96..c2f32215bc 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@@ -3,7 +3,6 @@ import "dart:async";import "package:ente_components/theme/text_styles.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/material.dart";-import "package:photos/core/constants.dart";import "package:photos/events/event.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/file/file.dart";@@ -33,9 +32,13 @@ import "package:photos/ui/viewer/search_tab/section_header.dart";class PeopleSection extends StatefulWidget {final SectionType sectionType = SectionType.face;final List<GenericSearchResult> examples;- final int limit;+ final int resultLimit;- const PeopleSection({super.key, required this.examples, this.limit = 7});+ const PeopleSection({+ super.key,+ required this.examples,+ required this.resultLimit,+ });@overrideState<PeopleSection> createState() => _PeopleSectionState();@@ -57,7 +60,7 @@ class _PeopleSectionState extends State<PeopleSection> {_examples =await widget.sectionType.getData(context,- limit: kSearchSectionLimit,+ limit: widget.resultLimit + 1,)as List<GenericSearchResult>;setState(() {});@@ -83,6 +86,9 @@ class _PeopleSectionState extends State<PeopleSection> {@overrideWidget build(BuildContext context) {final textTheme = getEnteTextTheme(context);+ final visibleExamples = _examples+ .take(widget.resultLimit)+ .toList(growable: false);return _examples.isNotEmpty? GestureDetector(behavior: HitTestBehavior.opaque,@@ -92,9 +98,12 @@ class _PeopleSectionState extends State<PeopleSection> {child: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- SectionHeader(widget.sectionType, hasMore: true),+ SectionHeader(+ widget.sectionType,+ hasMore: _examples.length > widget.resultLimit,+ ),const SizedBox(height: 4),- SearchExampleRow(_examples, widget.sectionType),+ SearchExampleRow(visibleExamples, widget.sectionType),const SizedBox(height: 20),],),diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dartindex b28bdc3a3d..1d79f773bd 100644--- a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart@@ -26,6 +26,7 @@ import "package:photos/ui/viewer/search_tab/locations_section.dart";import "package:photos/ui/viewer/search_tab/magic_section.dart";import "package:photos/ui/viewer/search_tab/people_section.dart";import "package:photos/ui/viewer/search_tab/search_tab_horizontal_scroll.dart";+import "package:photos/ui/viewer/search_tab/search_tab_preview_limits.dart";import "package:photos/ui/wrapped/wrapped_discovery_section.dart";class SearchTab extends StatefulWidget {@@ -92,17 +93,25 @@ class _SearchTabState extends State<SearchTab> {),),Expanded(- child: AllSectionsExamplesProvider(- child: FadeIndexedStack(- lazy: false,- duration: const Duration(milliseconds: 150),- index: index,- children: const [- AllSearchSections(),- SearchSuggestionsWidget(),- NoResultWidget(),- ],- ),+ child: LayoutBuilder(+ builder: (context, constraints) {+ final previewLimits = SearchTabPreviewLimits.forWidth(+ constraints.maxWidth,+ );+ return AllSectionsExamplesProvider(+ previewLimits: previewLimits,+ child: FadeIndexedStack(+ lazy: false,+ duration: const Duration(milliseconds: 150),+ index: index,+ children: [+ AllSearchSections(previewLimits: previewLimits),+ const SearchSuggestionsWidget(),+ const NoResultWidget(),+ ],+ ),+ );+ },),),],@@ -194,7 +203,9 @@ class _SearchHeaderTitle extends StatelessWidget {}class AllSearchSections extends StatefulWidget {- const AllSearchSections({super.key});+ final SearchTabPreviewLimits previewLimits;++ const AllSearchSections({super.key, required this.previewLimits});@overrideState<AllSearchSections> createState() => _AllSearchSectionsState();@@ -248,10 +259,22 @@ class _AllSearchSectionsState extends State<AllSearchSections> {resultsBySection[SectionType.face]!.isNotEmpty;final sectionWidgets = [if (hasGrantedMLConsent)- PeopleSection(examples: examplesFor(SectionType.face)),- MagicSection(examplesFor(SectionType.magic)),- LocationsSection(examplesFor(SectionType.location)),- if (!isLocalGalleryMode) const _RitualsDiscoverySection(),+ PeopleSection(+ examples: examplesFor(SectionType.face),+ resultLimit: widget.previewLimits.faceResults,+ ),+ MagicSection(+ examplesFor(SectionType.magic),+ resultLimit: widget.previewLimits.magicResults,+ ),+ LocationsSection(+ examplesFor(SectionType.location),+ resultLimit: widget.previewLimits.locationResults,+ ),+ if (!isLocalGalleryMode)+ _RitualsDiscoverySection(+ resultLimit: widget.previewLimits.ritualResults,+ ),ValueListenableBuilder<WrappedEntryState>(valueListenable: wrappedService.stateListenable,builder: (BuildContext context, WrappedEntryState state, _) {@@ -266,7 +289,9 @@ class _AllSearchSectionsState extends State<AllSearchSections> {);},),- const ContactsSectionLoader(),+ ContactsSectionLoader(+ resultLimit: widget.previewLimits.contactResults,+ ),FileTypeSection(hasAnySearchableFiles: hasAnySearchableFiles),];return ListView.builder(@@ -334,16 +359,18 @@ class _AllSearchSectionsState extends State<AllSearchSections> {}class _RitualsDiscoverySection extends StatelessWidget {- const _RitualsDiscoverySection();+ final int resultLimit;++ const _RitualsDiscoverySection({required this.resultLimit});@overrideWidget build(BuildContext context) {if (!flagService.ritualsFlag) {return const SizedBox.shrink();}- return const Padding(- padding: EdgeInsets.only(bottom: 20),- child: RitualsBanner(),+ return Padding(+ padding: const EdgeInsets.only(bottom: 20),+ child: RitualsBanner(resultLimit: resultLimit),);}}diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab_preview_limits.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab_preview_limits.dartnew file mode 100644index 0000000000..2e2ca6cadc--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab_preview_limits.dart@@ -0,0 +1,93 @@+import "dart:math" as math;++import "package:photos/ui/viewer/search_tab/search_tab_horizontal_scroll.dart";++class SearchTabPreviewLimits {+ const SearchTabPreviewLimits({+ required this.faceResults,+ required this.magicResults,+ required this.locationResults,+ required this.contactResults,+ required this.ritualResults,+ });++ static const _extraItems = 4;+ static const _mediaTileWidth = 108.0;+ static const _mediaTileSpacing = 10.0;+ static const _contactTileWidth = 92.0;+ static const _contactTileSpacing = 12.0;+ static const _ritualTileWidth = 167.5;+ static const _ritualTileSpacing = 10.0;+ static const _fixedLocationTiles = 1;+ static const _fixedContactTiles = 1;+ static const _fixedRitualTiles = 1;++ final int faceResults;+ final int magicResults;+ final int locationResults;+ final int contactResults;+ final int ritualResults;++ int get faceFetchLimit => faceResults + 1;+ int get magicFetchLimit => magicResults + 1;+ int get locationFetchLimit => locationResults + 1;++ static SearchTabPreviewLimits forWidth(double width) {+ final rowWidth = width - (searchTabSectionHorizontalPadding * 2);+ final mediaLimit = _limitForRow(+ rowWidth: rowWidth,+ itemWidth: _mediaTileWidth,+ spacing: _mediaTileSpacing,+ );++ return SearchTabPreviewLimits(+ faceResults: mediaLimit,+ magicResults: mediaLimit,+ locationResults: mediaLimit - _fixedLocationTiles,+ contactResults:+ _limitForRow(+ rowWidth: rowWidth,+ itemWidth: _contactTileWidth,+ spacing: _contactTileSpacing,+ ) -+ _fixedContactTiles,+ ritualResults:+ _limitForRow(+ rowWidth: rowWidth,+ itemWidth: _ritualTileWidth,+ spacing: _ritualTileSpacing,+ ) -+ _fixedRitualTiles,+ );+ }++ static int _limitForRow({+ required double rowWidth,+ required double itemWidth,+ required double spacing,+ }) {+ final visibleItems = ((rowWidth + spacing) / (itemWidth + spacing)).floor();+ return math.max(1, visibleItems) + _extraItems;+ }++ @override+ bool operator ==(Object other) {+ return other is SearchTabPreviewLimits &&+ other.faceResults == faceResults &&+ other.magicResults == magicResults &&+ other.locationResults == locationResults &&+ other.contactResults == contactResults &&+ other.ritualResults == ritualResults;+ }++ @override+ int get hashCode {+ return Object.hash(+ faceResults,+ magicResults,+ locationResults,+ contactResults,+ ritualResults,+ );+ }+}