Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Defer file type search previews

ashilkn92e1a8af8b2c
diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dart
index eed8fe4a88..62130e2eb7 100644
--- a/mobile/apps/photos/lib/db/files_db.dart
+++ b/mobile/apps/photos/lib/db/files_db.dart
@@ -2049,6 +2049,14 @@ class FilesDB with SqlDbBase {
return deduplicatedFiles;
}
+ Future<bool> hasAnyFile() async {
+ final db = await instance.sqliteAsyncDB;
+ final rows = await db.getAll(
+ 'SELECT 1 FROM $filesTable LIMIT 1',
+ );
+ return rows.isNotEmpty;
+ }
+
Future<FileLoadResult> fetchAllUploadedAndSharedFilesWithLocation(
int startTime,
int endTime, {
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index bcfde4dd64..f1822a5ab5 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -198,6 +198,14 @@ class SearchService {
return _cachedFilesForSearch!;
}
+ Future<bool> hasAnyFilesForSearch() async {
+ if (_cachedFilesFuture != null && _cachedFilesForSearch != null) {
+ return (await _cachedFilesForSearch!).isNotEmpty;
+ }
+
+ return FilesDB.instance.hasAnyFile();
+ }
+
Future<List<EnteFile>> getAllFilesForHierarchicalSearch() async {
if (_cachedFilesFuture != null &&
_cachedFilesForHierarchicalSearch != null) {
@@ -502,6 +510,76 @@ class SearchService {
return searchResults;
}
+ GenericSearchResult _buildFileTypeSearchResult(
+ FileType fileType,
+ String typeName,
+ List<EnteFile> files,
+ ) {
+ return GenericSearchResult(
+ ResultType.fileType,
+ typeName,
+ files,
+ hierarchicalSearchFilter: FileTypeFilter(
+ fileType: fileType,
+ typeName: typeName,
+ occurrence: kMostRelevantFilter,
+ matchedUploadedIDs: filesToUploadedFileIDs(files),
+ ),
+ );
+ }
+
+ GenericSearchResult _buildFileExtensionSearchResult(
+ String extensionName,
+ List<EnteFile> files,
+ ) {
+ return GenericSearchResult(
+ ResultType.fileExtension,
+ extensionName,
+ files,
+ hierarchicalSearchFilter: TopLevelGenericFilter(
+ filterName: extensionName,
+ occurrence: kMostRelevantFilter,
+ filterResultType: ResultType.fileExtension,
+ matchedUploadedIDs: filesToUploadedFileIDs(files),
+ filterIcon: CupertinoIcons.doc_text,
+ ),
+ );
+ }
+
+ String _fileExtension(String fileName) {
+ final extensionSeparatorIndex = fileName.lastIndexOf(".");
+ if (extensionSeparatorIndex < 0 ||
+ extensionSeparatorIndex == fileName.length - 1) {
+ return "";
+ }
+ return fileName.substring(extensionSeparatorIndex + 1).toUpperCase();
+ }
+
+ Future<GenericSearchResult> getFileTypeResult({
+ required FileType fileType,
+ required String typeName,
+ }) async {
+ final allFiles = await getAllFilesForSearch();
+ final matchedFiles = allFiles.where((e) => e.fileType == fileType).toList();
+ return _buildFileTypeSearchResult(fileType, typeName, matchedFiles);
+ }
+
+ Future<GenericSearchResult> getFileExtensionResult({
+ required String extension,
+ required String extensionName,
+ }) async {
+ final normalizedExtension = extension.startsWith(".")
+ ? extension.substring(1).toUpperCase()
+ : extension.toUpperCase();
+ final allFiles = await getAllFilesForSearch();
+ final matchedFiles = allFiles
+ .where(
+ (file) => _fileExtension(file.displayName) == normalizedExtension,
+ )
+ .toList();
+ return _buildFileExtensionSearchResult(extensionName, matchedFiles);
+ }
+
Future<List<GenericSearchResult>> getFileTypeResults(
BuildContext context,
String query,
@@ -515,16 +593,10 @@ class SearchService {
allFiles.where((e) => e.fileType == fileType).toList();
if (matchedFiles.isNotEmpty) {
searchResults.add(
- GenericSearchResult(
- ResultType.fileType,
+ _buildFileTypeSearchResult(
+ fileType,
fileTypeString,
matchedFiles,
- hierarchicalSearchFilter: FileTypeFilter(
- fileType: fileType,
- typeName: fileTypeString,
- occurrence: kMostRelevantFilter,
- matchedUploadedIDs: filesToUploadedFileIDs(matchedFiles),
- ),
),
);
}
@@ -537,6 +609,7 @@ class SearchService {
BuildContext context,
int? limit,
) async {
+ final stopwatch = Stopwatch()..start();
final List<GenericSearchResult> searchResults = [];
final List<EnteFile> allFiles = await getAllFilesForSearch();
final fileTypesAndMatchingFiles = <FileType, List<EnteFile>>{};
@@ -548,12 +621,7 @@ class SearchService {
}
fileTypesAndMatchingFiles[file.fileType]!.add(file);
- final String fileName = file.displayName;
- late final String ext;
- //Noticed that some old edited files do not have extensions and a '.'
- ext = fileName.contains(".")
- ? fileName.split(".").last.toUpperCase()
- : "";
+ final ext = _fileExtension(file.displayName);
if (ext != "") {
if (!extensionsAndMatchingFiles.containsKey(ext)) {
@@ -566,37 +634,29 @@ class SearchService {
fileTypesAndMatchingFiles.forEach((key, value) {
final name = getHumanReadableString(context, key);
searchResults.add(
- GenericSearchResult(
- ResultType.fileType,
+ _buildFileTypeSearchResult(
+ key,
name,
value,
- hierarchicalSearchFilter: FileTypeFilter(
- fileType: key,
- typeName: name,
- occurrence: kMostRelevantFilter,
- matchedUploadedIDs: filesToUploadedFileIDs(value),
- ),
),
);
});
extensionsAndMatchingFiles.forEach((key, value) {
searchResults.add(
- GenericSearchResult(
- ResultType.fileExtension,
+ _buildFileExtensionSearchResult(
key + "s",
value,
- hierarchicalSearchFilter: TopLevelGenericFilter(
- filterName: key + "s",
- occurrence: kMostRelevantFilter,
- filterResultType: ResultType.fileExtension,
- matchedUploadedIDs: filesToUploadedFileIDs(value),
- filterIcon: CupertinoIcons.doc_text,
- ),
),
);
});
+ final elapsed = stopwatch.elapsedMilliseconds;
+ _logger.info(
+ "getAllFileTypesAndExtensionsResults took $elapsed ms",
+ );
+ stopwatch.stop();
+
if (limit != null) {
return searchResults.sublist(0, min(limit, searchResults.length));
} else {
@@ -743,7 +803,10 @@ class SearchService {
for (EnteFile eachFile in allFiles) {
final String fileName = eachFile.displayName;
if (fileName.contains(query)) {
- final String exnType = fileName.split(".").last.toUpperCase();
+ final String exnType = _fileExtension(fileName);
+ if (exnType.isEmpty) {
+ continue;
+ }
if (!resultMap.containsKey(exnType)) {
resultMap[exnType] = <EnteFile>[];
}
@@ -752,17 +815,9 @@ class SearchService {
}
for (MapEntry<String, List<EnteFile>> entry in resultMap.entries) {
searchResults.add(
- GenericSearchResult(
- ResultType.fileExtension,
+ _buildFileExtensionSearchResult(
entry.key.toUpperCase(),
entry.value,
- hierarchicalSearchFilter: TopLevelGenericFilter(
- filterName: entry.key.toUpperCase(),
- occurrence: kMostRelevantFilter,
- filterResultType: ResultType.fileExtension,
- matchedUploadedIDs: filesToUploadedFileIDs(entry.value),
- filterIcon: CupertinoIcons.doc_text,
- ),
),
);
}
diff --git a/mobile/apps/photos/lib/states/all_sections_examples_state.dart b/mobile/apps/photos/lib/states/all_sections_examples_state.dart
index b81f50ff67..b455d634ab 100644
--- a/mobile/apps/photos/lib/states/all_sections_examples_state.dart
+++ b/mobile/apps/photos/lib/states/all_sections_examples_state.dart
@@ -12,6 +12,17 @@ import "package:photos/events/people_sort_order_change_event.dart";
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";
+
+class AllSectionsExamplesData {
+ final List<List<SearchResult>> sectionResults;
+ final bool hasAnySearchableFiles;
+
+ const AllSectionsExamplesData({
+ required this.sectionResults,
+ required this.hasAnySearchableFiles,
+ });
+}
class AllSectionsExamplesProvider extends StatefulWidget {
final Widget child;
@@ -30,7 +41,12 @@ class _AllSectionsExamplesProviderState
//can listen to a list of events and rebuild (see sectionUpdateEvents()
//in search_types.dart) and new results will not reflect in
//[allSectionsExamplesFuture] unless reloadAllSections() is called.
- Future<List<List<SearchResult>>> allSectionsExamplesFuture = Future.value([]);
+ Future<AllSectionsExamplesData> allSectionsExamplesFuture = Future.value(
+ const AllSectionsExamplesData(
+ sectionResults: [],
+ hasAnySearchableFiles: false,
+ ),
+ );
late StreamSubscription<FilesUpdatedEvent> _filesUpdatedEvent;
late StreamSubscription<PeopleChangedEvent> _onPeopleChangedEvent;
@@ -104,11 +120,13 @@ class _AllSectionsExamplesProviderState
setState(() {
_logger.info("'_debounceTimer: reloading all sections in search tab");
final allSectionsExamples = <Future<List<SearchResult>>>[];
+ final hasAnySearchableFilesFuture =
+ SearchService.instance.hasAnyFilesForSearch();
for (SectionType sectionType in SectionType.values) {
- // Contacts section have been moved to shared collections tab
- // temporarily from search tab. So we can skip computing data here
- // since 'allSectionsExamples' is for search tab sections only.
- if (sectionType == SectionType.contacts) {
+ // Contacts section has been moved to shared collections tab.
+ // File types are rendered as lazy placeholders in the search tab.
+ if (sectionType == SectionType.contacts ||
+ sectionType == SectionType.fileTypesAndExtension) {
allSectionsExamples.add(Future.value([]));
} else {
allSectionsExamples.add(
@@ -117,10 +135,17 @@ class _AllSectionsExamplesProviderState
}
}
try {
- allSectionsExamplesFuture = Future.wait<List<SearchResult>>(
- allSectionsExamples,
- eagerError: false,
- );
+ allSectionsExamplesFuture = () async {
+ final sectionResults = await Future.wait<List<SearchResult>>(
+ allSectionsExamples,
+ eagerError: false,
+ );
+ final hasAnySearchableFiles = await hasAnySearchableFilesFuture;
+ return AllSectionsExamplesData(
+ sectionResults: sectionResults,
+ hasAnySearchableFiles: hasAnySearchableFiles,
+ );
+ }();
} catch (e) {
_logger.severe("Error reloading all sections: $e");
}
@@ -155,7 +180,7 @@ class _AllSectionsExamplesProviderState
}
class InheritedAllSectionsExamples extends InheritedWidget {
- final Future<List<List<SearchResult>>> allSectionsExamplesFuture;
+ final Future<AllSectionsExamplesData> allSectionsExamplesFuture;
final ValueNotifier<bool> isDebouncingNotifier;
const InheritedAllSectionsExamples(
this.allSectionsExamplesFuture,
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart
index a0352717db..f35cb59f8c 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/no_result_widget.dart
@@ -31,14 +31,16 @@ class _NoResultWidgetState extends State<NoResultWidget> {
InheritedAllSectionsExamples.of(context)
.allSectionsExamplesFuture
.then((value) {
- if (value.isEmpty) return;
+ final sectionResultsByType = value.sectionResults;
+ if (sectionResultsByType.isEmpty) return;
for (int i = 0; i < searchTypes.length; i++) {
final SectionType sectionType = searchTypes[i];
final int sectionIndex = SectionType.values.indexOf(sectionType);
- if (sectionIndex < 0 || sectionIndex >= value.length) {
+ if (sectionIndex < 0 || sectionIndex >= sectionResultsByType.length) {
continue;
}
- final List<SearchResult> sectionResults = value[sectionIndex];
+ final List<SearchResult> sectionResults =
+ sectionResultsByType[sectionIndex];
final querySuggestions = <String>[];
for (int j = 0; j < 2 && j < sectionResults.length; j++) {
querySuggestions.add(sectionResults[j].name());
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.dart
index 000fd52b1a..a698d6eaee 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
@@ -2,66 +2,29 @@ import "dart:async";
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:logging/logging.dart";
+import "package:photos/models/file/file_type.dart";
import "package:photos/models/search/generic_search_result.dart";
import "package:photos/models/search/recent_searches.dart";
import "package:photos/models/search/search_types.dart";
+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/viewer/search/result/search_result_page.dart";
import "package:photos/ui/viewer/search/search_section_cta.dart";
import "package:photos/ui/viewer/search_tab/section_header.dart";
-class FileTypeSection extends StatefulWidget {
- final List<GenericSearchResult> fileTypesSearchResults;
- const FileTypeSection(this.fileTypesSearchResults, {super.key});
+class FileTypeSection extends StatelessWidget {
+ final bool hasAnySearchableFiles;
- @override
- State<FileTypeSection> createState() => _FileTypeSectionState();
-}
-
-class _FileTypeSectionState extends State<FileTypeSection> {
- late List<GenericSearchResult> _fileTypesSearchResults;
- final streamSubscriptions = <StreamSubscription>[];
-
- @override
- void initState() {
- super.initState();
- _fileTypesSearchResults = widget.fileTypesSearchResults;
-
- final streamsToListenTo =
- SectionType.fileTypesAndExtension.sectionUpdateEvents();
- for (Stream<Event> stream in streamsToListenTo) {
- streamSubscriptions.add(
- stream.listen((event) async {
- _fileTypesSearchResults =
- (await SectionType.fileTypesAndExtension.getData(
- context,
- limit: kSearchSectionLimit,
- )) as List<GenericSearchResult>;
- setState(() {});
- }),
- );
- }
- }
-
- @override
- void dispose() {
- for (var subscriptions in streamSubscriptions) {
- subscriptions.cancel();
- }
- super.dispose();
- }
-
- @override
- void didUpdateWidget(covariant FileTypeSection oldWidget) {
- super.didUpdateWidget(oldWidget);
- _fileTypesSearchResults = widget.fileTypesSearchResults;
- }
+ const FileTypeSection({
+ required this.hasAnySearchableFiles,
+ super.key,
+ });
@override
Widget build(BuildContext context) {
- if (_fileTypesSearchResults.isEmpty) {
+ if (!hasAnySearchableFiles) {
final textTheme = getEnteTextTheme(context);
return Padding(
padding: const EdgeInsets.only(left: 12, right: 8),
@@ -92,42 +55,126 @@ class _FileTypeSectionState extends State<FileTypeSection> {
],
),
);
- } else {
- return Padding(
- padding: const EdgeInsets.symmetric(vertical: 8),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SectionHeader(
- SectionType.fileTypesAndExtension,
- hasMore:
- (_fileTypesSearchResults.length >= kSearchSectionLimit - 1),
- ),
- const SizedBox(height: 2),
- SizedBox(
- child: SingleChildScrollView(
- padding: const EdgeInsets.symmetric(horizontal: 4.5),
- physics: const BouncingScrollPhysics(),
- scrollDirection: Axis.horizontal,
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: _fileTypesSearchResults
- .map(
- (fileTypeSearchResult) =>
- FileTypeRecommendation(fileTypeSearchResult),
- )
- .toList(),
- ),
+ }
+
+ final tiles = _previewTiles(context);
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SectionHeader(
+ SectionType.fileTypesAndExtension,
+ hasMore: true,
+ ),
+ const SizedBox(height: 2),
+ SizedBox(
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.symmetric(horizontal: 4.5),
+ physics: const BouncingScrollPhysics(),
+ scrollDirection: Axis.horizontal,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: tiles
+ .map(
+ (tile) => _FileTypeRecommendation(tile),
+ )
+ .toList(),
),
),
- ],
- ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ List<_FileTypeTile> _previewTiles(BuildContext context) {
+ return [
+ _FileTypeTile.fileType(
+ assetKey: "PHOTO",
+ name: getHumanReadableString(context, FileType.image),
+ type: FileType.image,
+ ),
+ _FileTypeTile.fileType(
+ assetKey: "VIDEO",
+ name: getHumanReadableString(context, FileType.video),
+ type: FileType.video,
+ ),
+ _FileTypeTile.fileType(
+ assetKey: "LIVE",
+ name: getHumanReadableString(context, FileType.livePhoto),
+ type: FileType.livePhoto,
+ ),
+ const _FileTypeTile.extension(
+ assetKey: "PNG",
+ name: "PNGs",
+ extension: "PNG",
+ ),
+ const _FileTypeTile.extension(
+ assetKey: "JPG",
+ name: "JPGs",
+ extension: "JPG",
+ ),
+ const _FileTypeTile.extension(
+ assetKey: "HEIC",
+ name: "HEICs",
+ extension: "HEIC",
+ ),
+ const _FileTypeTile.extension(
+ assetKey: "MP4",
+ name: "MP4s",
+ extension: "MP4",
+ ),
+ ];
+ }
+}
+
+class _FileTypeTile {
+ final String assetKey;
+ final String name;
+ final FileType? fileType;
+ final String? extension;
+
+ const _FileTypeTile.fileType({
+ required this.assetKey,
+ required this.name,
+ required FileType type,
+ }) : fileType = type,
+ extension = null;
+
+ const _FileTypeTile.extension({
+ required this.assetKey,
+ required this.name,
+ required this.extension,
+ }) : fileType = null,
+ assert(extension != null);
+
+ Future<GenericSearchResult> resolve() {
+ final type = fileType;
+ if (type != null) {
+ return SearchService.instance.getFileTypeResult(
+ fileType: type,
+ typeName: name,
);
}
+ return SearchService.instance.getFileExtensionResult(
+ extension: extension!,
+ extensionName: name,
+ );
}
}
-class FileTypeRecommendation extends StatelessWidget {
+class _FileTypeRecommendation extends StatefulWidget {
+ final _FileTypeTile tile;
+
+ const _FileTypeRecommendation(this.tile);
+
+ @override
+ State<_FileTypeRecommendation> createState() =>
+ _FileTypeRecommendationState();
+}
+
+class _FileTypeRecommendationState extends State<_FileTypeRecommendation> {
static const knownTypesToAssetPath = {
"PHOTO": "assets/type_photos.png",
"VIDEO": "assets/type_videos.png",
@@ -142,74 +189,108 @@ class FileTypeRecommendation extends StatelessWidget {
"PNG": "assets/type_PNG.png",
"WEBP": "assets/type_WEBP.png",
};
- final GenericSearchResult fileTypeSearchResult;
- const FileTypeRecommendation(this.fileTypeSearchResult, {super.key});
+
+ final _logger = Logger("FileTypeRecommendation");
+ bool _isResolving = false;
@override
Widget build(BuildContext context) {
- final fileTypeKey =
- fileTypeKeyFromSearchResult(fileTypeSearchResult.name.call());
+ final fileTypeKey = widget.tile.assetKey;
final assetPath = knownTypesToAssetPath[fileTypeKey];
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 68),
child: GestureDetector(
- onTap: () {
- RecentSearches().add(fileTypeSearchResult.name());
- if (fileTypeSearchResult.onResultTap != null) {
- fileTypeSearchResult.onResultTap!(context);
- } else {
- routeToPage(
- context,
- SearchResultPage(fileTypeSearchResult),
- );
- }
- },
- child: assetPath != null
- ? Image.asset(assetPath)
- : Stack(
- alignment: Alignment.center,
- children: [
- Image.asset(
- "assets/type_unknown.png",
- ),
- Positioned(
- bottom: 18,
- child: ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 48),
- child: FittedBox(
- fit: BoxFit.scaleDown,
- child: Text(
- fileTypeKey,
- style: const TextStyle(
- fontSize: 14,
- fontFamily: "Inter",
- color: Colors.white,
- letterSpacing: 0.75,
- ),
- textAlign: TextAlign.center,
- maxLines: 1,
- ),
- ),
- ),
- ),
- ],
+ onTap: _onTap,
+ child: Stack(
+ alignment: Alignment.center,
+ children: [
+ assetPath != null
+ ? Image.asset(assetPath)
+ : _UnknownFileTypeImage(fileTypeKey),
+ if (_isResolving)
+ const EnteLoadingWidget(
+ color: Colors.white,
+ size: 20,
+ padding: 0,
),
+ ],
+ ),
),
),
);
}
- String fileTypeKeyFromSearchResult(String name) {
- String fileTypeKey = "";
- //remove 's' at the end of string
- if (RegExp(r's$').hasMatch(name)) {
- fileTypeKey = name.substring(0, name.length - 1);
+ Future<void> _onTap() async {
+ if (_isResolving) {
+ return;
}
- //use only 1st word if there exists multiple words
- fileTypeKey = fileTypeKey.split(" ").first.toUpperCase();
+ setState(() {
+ _isResolving = true;
+ });
- return fileTypeKey;
+ try {
+ final searchResult = await widget.tile.resolve();
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ _isResolving = false;
+ });
+ RecentSearches().add(searchResult.name());
+ unawaited(
+ routeToPage(
+ context,
+ SearchResultPage(searchResult),
+ ),
+ );
+ } catch (e, s) {
+ _logger.severe("Failed to resolve file type result", e, s);
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ _isResolving = false;
+ });
+ }
+ }
+}
+
+class _UnknownFileTypeImage extends StatelessWidget {
+ final String fileTypeKey;
+
+ const _UnknownFileTypeImage(this.fileTypeKey);
+
+ @override
+ Widget build(BuildContext context) {
+ return Stack(
+ alignment: Alignment.center,
+ children: [
+ Image.asset(
+ "assets/type_unknown.png",
+ ),
+ Positioned(
+ bottom: 18,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 48),
+ child: FittedBox(
+ fit: BoxFit.scaleDown,
+ child: Text(
+ fileTypeKey,
+ style: const TextStyle(
+ fontSize: 14,
+ fontFamily: "Inter",
+ color: Colors.white,
+ letterSpacing: 0.75,
+ ),
+ textAlign: TextAlign.center,
+ maxLines: 1,
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
}
}
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.dart
index d4492738fc..ef4a6ffe43 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
@@ -7,7 +7,6 @@ import "package:photos/generated/intl/app_localizations.dart";
import "package:photos/models/search/album_search_result.dart";
import "package:photos/models/search/generic_search_result.dart";
import "package:photos/models/search/index_of_indexed_stack.dart";
-import "package:photos/models/search/search_result.dart";
import "package:photos/models/search/search_types.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/wrapped/wrapped_service.dart";
@@ -109,27 +108,32 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
padding: const EdgeInsets.only(top: 4),
child: Stack(
children: [
- FutureBuilder<List<List<SearchResult>>>(
+ FutureBuilder<AllSectionsExamplesData>(
future: InheritedAllSectionsExamples.of(
context,
).allSectionsExamplesFuture,
builder: (context, snapshot) {
- if (snapshot.hasData && snapshot.data!.isNotEmpty) {
+ if (snapshot.hasData &&
+ snapshot.data!.sectionResults.isNotEmpty) {
+ final sectionResultsByType = snapshot.data!.sectionResults;
+ final hasAnySearchableFiles =
+ snapshot.data!.hasAnySearchableFiles;
// In offline mode, skip the empty state check since DeviceAlbumsSection
// fetches its own data and may have albums to show
if (!isLocalGalleryMode &&
- snapshot.data!.every((element) => element.isEmpty)) {
+ !hasAnySearchableFiles &&
+ sectionResultsByType.every((element) => element.isEmpty)) {
return const Padding(
padding: EdgeInsets.only(bottom: 72),
child: SearchTabEmptyState(),
);
}
- if (snapshot.data!.length != searchTypes.length) {
+ if (sectionResultsByType.length != searchTypes.length) {
return Padding(
padding: const EdgeInsets.only(bottom: 72),
child: Text(
AppLocalizations.of(context).searchSectionsLengthMismatch(
- snapshotLength: snapshot.data!.length,
+ snapshotLength: sectionResultsByType.length,
searchLength: searchTypes.length,
),
),
@@ -138,8 +142,8 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
final faceSectionIndex = searchTypes.indexOf(SectionType.face);
final hasSurfacedOfflineFaces = isLocalGalleryMode &&
faceSectionIndex >= 0 &&
- faceSectionIndex < snapshot.data!.length &&
- snapshot.data!.elementAt(faceSectionIndex).isNotEmpty;
+ faceSectionIndex < sectionResultsByType.length &&
+ sectionResultsByType.elementAt(faceSectionIndex).isNotEmpty;
return ListView.builder(
padding: const EdgeInsets.only(bottom: 180),
physics: const BouncingScrollPhysics(),
@@ -162,7 +166,7 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
return const SizedBox.shrink();
}
return PeopleSection(
- examples: snapshot.data!.elementAt(sectionIndex)
+ examples: sectionResultsByType.elementAt(sectionIndex)
as List<GenericSearchResult>,
);
case SectionType.album:
@@ -170,7 +174,7 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
return const DeviceAlbumsSection();
}
return AlbumsSection(
- snapshot.data!.elementAt(sectionIndex)
+ sectionResultsByType.elementAt(sectionIndex)
as List<AlbumSearchResult>,
);
case SectionType.ritual:
@@ -196,19 +200,18 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
);
case SectionType.location:
return LocationsSection(
- snapshot.data!.elementAt(sectionIndex)
+ sectionResultsByType.elementAt(sectionIndex)
as List<GenericSearchResult>,
);
case SectionType.contacts:
return const SizedBox.shrink();
case SectionType.fileTypesAndExtension:
return FileTypeSection(
- snapshot.data!.elementAt(sectionIndex)
- as List<GenericSearchResult>,
+ hasAnySearchableFiles: hasAnySearchableFiles,
);
case SectionType.magic:
return MagicSection(
- snapshot.data!.elementAt(sectionIndex)
+ sectionResultsByType.elementAt(sectionIndex)
as List<GenericSearchResult>,
);
}