Show cities search in location section
This commit is contained in:
parent
f30c139097
commit
3080dcf9f1
5 changed files with 40 additions and 4 deletions
|
@ -25,6 +25,7 @@ enum ResultType {
|
|||
collection,
|
||||
file,
|
||||
location,
|
||||
locationSuggestion,
|
||||
month,
|
||||
year,
|
||||
fileType,
|
||||
|
|
|
@ -708,6 +708,7 @@ class SearchService {
|
|||
final locationTagEntities =
|
||||
(await LocationService.instance.getLocationTags());
|
||||
final allFiles = await getAllFiles();
|
||||
final List<EnteFile> filesWithNoLocTag = [];
|
||||
|
||||
for (int i = 0; i < locationTagEntities.length; i++) {
|
||||
if (limit != null && i >= limit) break;
|
||||
|
@ -716,15 +717,20 @@ class SearchService {
|
|||
|
||||
for (EnteFile file in allFiles) {
|
||||
if (file.hasLocation) {
|
||||
bool hasLocationTag = false;
|
||||
for (LocalEntity<LocationTag> tag in tagToItemsMap.keys) {
|
||||
if (isFileInsideLocationTag(
|
||||
tag.item.centerPoint,
|
||||
file.location!,
|
||||
tag.item.radius,
|
||||
)) {
|
||||
hasLocationTag = true;
|
||||
tagToItemsMap[tag]!.add(file);
|
||||
}
|
||||
}
|
||||
if (!hasLocationTag) {
|
||||
filesWithNoLocTag.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -753,6 +759,23 @@ class SearchService {
|
|||
);
|
||||
}
|
||||
}
|
||||
if (limit == null || tagSearchResults.length < limit) {
|
||||
final results = await LocationService.instance
|
||||
.getFilesInCity(filesWithNoLocTag, '');
|
||||
final List<City> sortedByResultCount = results.keys.toList()
|
||||
..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));
|
||||
for (final city in sortedByResultCount) {
|
||||
if (results[city]!.length <= 1) continue;
|
||||
// If the location tag already exists for a city, don't add it again
|
||||
tagSearchResults.add(
|
||||
GenericSearchResult(
|
||||
ResultType.locationSuggestion,
|
||||
city.city,
|
||||
results[city]!,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return tagSearchResults;
|
||||
} catch (e) {
|
||||
_logger.severe("Error in getAllLocationTags", e);
|
||||
|
|
|
@ -131,6 +131,8 @@ class SearchResultWidget extends StatelessWidget {
|
|||
return "Day";
|
||||
case ResultType.location:
|
||||
return "Location";
|
||||
case ResultType.locationSuggestion:
|
||||
return "Add Location";
|
||||
case ResultType.fileType:
|
||||
return "Type";
|
||||
case ResultType.fileExtension:
|
||||
|
|
|
@ -3,6 +3,7 @@ import "dart:async";
|
|||
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/models/search/album_search_result.dart";
|
||||
import "package:photos/models/search/generic_search_result.dart";
|
||||
import "package:photos/models/search/recent_searches.dart";
|
||||
|
@ -83,8 +84,6 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {
|
|||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final sectionResults = snapshot.data!;
|
||||
sectionResults
|
||||
.sort((a, b) => a.name().compareTo(b.name()));
|
||||
return Text(sectionResults.length.toString())
|
||||
.animate()
|
||||
.fadeIn(
|
||||
|
@ -109,7 +108,15 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {
|
|||
future: sectionData,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final sectionResults = snapshot.data!;
|
||||
List<SearchResult> sectionResults = snapshot.data!;
|
||||
sectionResults.sort((a, b) => a.name().compareTo(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 (sectionResults.length == index) {
|
||||
|
|
|
@ -77,7 +77,10 @@ class SearchableItemWidget extends StatelessWidget {
|
|||
children: [
|
||||
Text(
|
||||
searchResult.name(),
|
||||
style: textTheme.body,
|
||||
style: searchResult.type() ==
|
||||
ResultType.locationSuggestion
|
||||
? textTheme.bodyFaint
|
||||
: textTheme.body,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(
|
||||
|
|
Loading…
Add table
Reference in a new issue