diff --git a/lib/face_search_manager.dart b/lib/face_search_manager.dart index 3a6601b90..433968cf8 100644 --- a/lib/face_search_manager.dart +++ b/lib/face_search_manager.dart @@ -7,7 +7,7 @@ import 'package:photos/models/face.dart'; import 'package:photos/models/photo.dart'; class FaceSearchManager { - final logger = Logger("FaceSearchManager"); + final _logger = Logger("FaceSearchManager"); final _dio = Dio(); FaceSearchManager._privateConstructor(); @@ -28,20 +28,36 @@ class FaceSearchManager { } Future> getFaceSearchResults(Face face) async { - var futures = _dio + final result = await _dio .get( - Configuration.instance.getHttpEndpoint() + - "/photos/search/face/" + - face.faceID.toString(), - options: Options( - headers: {"X-Auth-Token": Configuration.instance.getToken()}), - ) - .then((response) => (response.data["results"] as List) - .map((result) => (PhotoDB.instance.getPhotoByPath(result)))); - return Future.wait(await futures); + Configuration.instance.getHttpEndpoint() + + "/photos/search/face/" + + face.faceID.toString(), + queryParameters: { + "limit": 100, + }, + options: + Options(headers: {"X-Auth-Token": Configuration.instance.getToken()}), + ) + .then((response) { + return (response.data["result"] as List) + .map((p) => Photo.fromJson(p)) + .toList(); + }).catchError(_onError); + final photos = List(); + for (Photo photo in result) { + try { + photos.add(await PhotoDB.instance.getMatchingPhoto(photo.localId, + photo.title, photo.deviceFolder, photo.createTimestamp)); + } catch (e) { + // Not available locally + photos.add(photo); + } + } + return photos; } void _onError(error) { - logger.severe(error); + _logger.severe(error); } } diff --git a/lib/ui/face_search_results_page.dart b/lib/ui/face_search_results_page.dart index 67c07f738..82da4b861 100644 --- a/lib/ui/face_search_results_page.dart +++ b/lib/ui/face_search_results_page.dart @@ -4,6 +4,7 @@ import 'package:photos/face_search_manager.dart'; import 'package:photos/models/face.dart'; import 'package:photos/models/photo.dart'; import 'package:photos/ui/circular_network_image_widget.dart'; +import 'package:photos/ui/gallery.dart'; import 'package:photos/ui/loading_widget.dart'; import 'package:photos/ui/thumbnail_widget.dart'; import 'package:photos/ui/detail_page.dart'; @@ -22,14 +23,11 @@ class FaceSearchResultsPage extends StatelessWidget { appBar: AppBar( title: Text("Search results"), actions: [ - Hero( - tag: "face_" + _face.faceID.toString(), - child: CircularNetworkImageWidget( - Configuration.instance.getHttpEndpoint() + - "/" + - _face.thumbnailPath, - 20), - ) + CircularNetworkImageWidget( + Configuration.instance.getHttpEndpoint() + + "/" + + _face.thumbnailPath, + 20), ], ), body: Container( @@ -43,13 +41,10 @@ class FaceSearchResultsPage extends StatelessWidget { future: _faceSearchManager.getFaceSearchResults(_face), builder: (context, snapshot) { if (snapshot.hasData) { - return GridView.builder( - itemBuilder: (_, index) => - _buildItem(context, snapshot.data, index), - itemCount: snapshot.data.length, - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 4, - )); + return Gallery( + snapshot.data, + Set(), + ); } else { return Center(child: loadWidget); } diff --git a/lib/ui/search_page.dart b/lib/ui/search_page.dart index 26d51ab0d..e07c12824 100644 --- a/lib/ui/search_page.dart +++ b/lib/ui/search_page.dart @@ -63,12 +63,9 @@ class SearchPage extends StatelessWidget { onTap: () { _routeToSearchResults(face, context); }, - child: Hero( - tag: "face_" + face.faceID.toString(), - child: CircularNetworkImageWidget( - Configuration.instance.getHttpEndpoint() + "/" + face.thumbnailPath, - 60), - ), + child: CircularNetworkImageWidget( + Configuration.instance.getHttpEndpoint() + "/" + face.thumbnailPath, + 60), ); }