modified code to work with the new object returned by getLocationsToMatchedFiles

This commit is contained in:
ashilkn 2022-08-03 16:39:11 +05:30
parent 96c68e6d99
commit 40bee92e64
4 changed files with 18 additions and 26 deletions

View file

@ -909,9 +909,7 @@ class UserService {
Map<String, List<File>> locationsToMatchedFiles = {};
for (var locationAndBbox in matchedLocationNamesAndBboxs) {
locationsToMatchedFiles.addAll({
locationAndBbox['place']: []
}); //{"Kochi": [f1,f2,...], "Chennai":[f1,f2,..],...}
locationsToMatchedFiles.addAll({locationAndBbox['place']: []});
for (File file in allFiles) {
if (_isValidLocation(file.location)) {
if (file.location.latitude >
@ -932,10 +930,9 @@ class UserService {
}
}
locationsToMatchedFiles.removeWhere(
(key, value) => value == [],
(key, value) => value.isEmpty,
); //removes entries of locations with no files
//[{'place':'india', 'matchedFiles':[f1,f2,f3...]},{'place':....}, ..}]
//{"Kochi": [f1,f2,...], "Chennai":[f1,f2,..],...}
return locationsToMatchedFiles;
} on DioError catch (e) {
_logger.info(e);

View file

@ -1,16 +1,17 @@
import 'package:flutter/material.dart';
import 'package:photos/ente_theme_data.dart';
import 'package:photos/models/file.dart';
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
import 'package:photos/ui/viewer/search/location_collection_page.dart';
import 'package:photos/utils/navigation_util.dart';
class LocationResultsWidget extends StatelessWidget {
final Map<String, dynamic> locationAndFiles;
const LocationResultsWidget(this.locationAndFiles, {Key key})
final MapEntry<String, List<File>> locationToMatchedFiles;
const LocationResultsWidget(this.locationToMatchedFiles, {Key key})
: super(key: key);
@override
Widget build(BuildContext context) {
int noOfMemories = locationAndFiles['matchingFiles'].length;
int noOfMemories = locationToMatchedFiles.value.length;
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: Padding(
@ -29,7 +30,7 @@ class LocationResultsWidget extends StatelessWidget {
),
const SizedBox(height: 8),
Text(
locationAndFiles['place'],
locationToMatchedFiles.key,
style: const TextStyle(fontSize: 18),
overflow: TextOverflow.ellipsis,
),
@ -52,7 +53,7 @@ class LocationResultsWidget extends StatelessWidget {
SizedBox(
height: 50,
width: 50,
child: ThumbnailWidget(locationAndFiles['matchingFiles'][0]),
child: ThumbnailWidget(locationToMatchedFiles.value[0]),
),
],
),
@ -61,7 +62,7 @@ class LocationResultsWidget extends StatelessWidget {
routeToPage(
context,
LocationCollectionPage(
files: locationAndFiles['matchingFiles'],
files: locationToMatchedFiles.value,
),
);
},

View file

@ -9,11 +9,11 @@ import 'package:photos/ui/viewer/search/search_result_widgets/location_result_wi
class SearchResultsSuggestions extends StatelessWidget {
final List<CollectionWithThumbnail> matchedCollectionsWithThumbnail;
final List<File> matchedFiles;
final List<Map<String, Object>> matchedLocationsAndFiles;
final Map<String, List<File>> locationsToMatchedFiles;
const SearchResultsSuggestions(
this.matchedCollectionsWithThumbnail,
this.matchedFiles,
this.matchedLocationsAndFiles, {
this.locationsToMatchedFiles, {
Key key,
}) : super(key: key);
@ -26,8 +26,8 @@ class SearchResultsSuggestions extends StatelessWidget {
for (File file in matchedFiles) {
suggestions.add(file);
}
for (Map<String, Object> locationAndFiles in matchedLocationsAndFiles) {
// log(locationAndFiles.toString());
for (MapEntry<String, List<File>> locationAndFiles
in locationsToMatchedFiles.entries) {
suggestions.add(locationAndFiles);
}
return Container(
@ -41,7 +41,7 @@ class SearchResultsSuggestions extends StatelessWidget {
return CollectionResultWidget(value);
} else if (value is File) {
return FilenameResultWidget(value);
} else if (value is Map<String, Object>) {
} else if (value is MapEntry<String, List<File>>) {
return LocationResultsWidget(value);
} else {
throw StateError("Invalid/Unsupported value");

View file

@ -1,5 +1,3 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:photos/db/files_db.dart';
import 'package:photos/ente_theme_data.dart';
@ -47,7 +45,7 @@ class _SearchIconWidgetState extends State<SearchIconWidget> {
Widget searchWidget() {
List<CollectionWithThumbnail> matchedCollections = [];
List<File> matchedFiles = [];
List<Map<String, Object>> matchedFilesWithLocation = [];
Map<String, List<File>> locationsToMatchedFiles = {};
return Column(
children: [
Row(
@ -75,12 +73,8 @@ class _SearchIconWidgetState extends State<SearchIconWidget> {
.getFilteredCollectionsWithThumbnail(value);
matchedFiles =
await FilesDB.instance.getFilesOnFileNameSearch(value);
matchedFilesWithLocation = await UserService.instance
locationsToMatchedFiles = await UserService.instance
.getLocationsToMatchedFiles(value);
log(
'search_widget.dart --------- ' +
matchedFilesWithLocation.toString(),
);
_searchQuery.value = value;
},
autofocus: true,
@ -109,7 +103,7 @@ class _SearchIconWidgetState extends State<SearchIconWidget> {
? SearchResultsSuggestions(
matchedCollections,
matchedFiles,
matchedFilesWithLocation,
locationsToMatchedFiles,
)
: const SizedBox.shrink();
},