Skip to content

armgit / ente

Public Imported from GitHub
0

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

Show cities search in location section

Neeraj Gupta3080dcf9f16f
diff --git a/lib/models/search/search_types.dart b/lib/models/search/search_types.dart
index f2fa891c49..92c71cd873 100644
--- a/lib/models/search/search_types.dart
+++ b/lib/models/search/search_types.dart
@@ -25,6 +25,7 @@ enum ResultType {
collection,
file,
location,
+ locationSuggestion,
month,
year,
fileType,
diff --git a/lib/services/search_service.dart b/lib/services/search_service.dart
index 5820013997..484b692c88 100644
--- a/lib/services/search_service.dart
+++ b/lib/services/search_service.dart
@@ -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);
diff --git a/lib/ui/viewer/search/result/search_result_widget.dart b/lib/ui/viewer/search/result/search_result_widget.dart
index 2a37cc7891..5564af7c9c 100644
--- a/lib/ui/viewer/search/result/search_result_widget.dart
+++ b/lib/ui/viewer/search/result/search_result_widget.dart
@@ -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:
diff --git a/lib/ui/viewer/search/result/search_section_all_page.dart b/lib/ui/viewer/search/result/search_section_all_page.dart
index 65c5ec9ab5..59761009af 100644
--- a/lib/ui/viewer/search/result/search_section_all_page.dart
+++ b/lib/ui/viewer/search/result/search_section_all_page.dart
@@ -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) {
diff --git a/lib/ui/viewer/search/result/searchable_item.dart b/lib/ui/viewer/search/result/searchable_item.dart
index a8a280296f..1124d925e2 100644
--- a/lib/ui/viewer/search/result/searchable_item.dart
+++ b/lib/ui/viewer/search/result/searchable_item.dart
@@ -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(