[mob][photos] Add trip location names

This commit is contained in:
laurenspriem
2025-02-13 09:33:15 +05:30
parent e6f72ea1c3
commit 2fd5c703c9

View File

@@ -1498,8 +1498,11 @@ class SearchService {
for (final trip in tripsToShow) {
final year =
DateTime.fromMicrosecondsSinceEpoch(trip.averageCreationTime).year;
final String? locationName = await _tryFindLocationName(trip.files);
String name = "Trip in $year!";
if (year == currentTime.year - 1) {
if (locationName != null) {
name = "Trip to $locationName!";
} else if (year == currentTime.year - 1) {
name = "Last year's trip!";
}
final photoSelection = await _bestSelection(trip.files);
@@ -1546,8 +1549,11 @@ class SearchService {
final year =
DateTime.fromMicrosecondsSinceEpoch(trip.averageCreationTime)
.year;
final String? locationName = await _tryFindLocationName(trip.files);
String name = "Trip in $year!";
if (year == currentTime.year - 1) {
if (locationName != null) {
name = "Trip to $locationName!";
} else if (year == currentTime.year - 1) {
name = "Last year's trip!";
}
final photoSelection = await _bestSelection(trip.files);
@@ -1843,6 +1849,22 @@ class SearchService {
return ((dayOfYear - 1) ~/ 7) + 1;
}
Future<String?> _tryFindLocationName(List<EnteFile> files) async {
final results = await locationService.getFilesInCity(files, '');
final List<City> sortedByResultCount = results.keys.toList()
..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));
if (sortedByResultCount.isEmpty) return null;
final biggestPlace = sortedByResultCount.first;
if (results[biggestPlace]!.length > files.length / 2) {
return biggestPlace.city;
}
if (results.length > 2 &&
results.keys.map((city) => city.country).toSet().length == 1) {
return biggestPlace.country;
}
return null;
}
/// Returns the best selection of files from the given list.
/// Makes sure that the selection is not more than [prefferedSize] or 10 files,
/// and that each year of the original list is represented.