Vishnu Mohandas 5 лет назад
Родитель
Сommit
aebcf9cbfa
3 измененных файлов с 41 добавлено и 33 удалено
  1. 28 12
      lib/face_search_manager.dart
  2. 10 15
      lib/ui/face_search_results_page.dart
  3. 3 6
      lib/ui/search_page.dart

+ 28 - 12
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<List<Photo>> 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<Photo>();
+    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);
   }
 }

+ 10 - 15
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: <Widget>[
-          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<Photo>(),
+          );
         } else {
           return Center(child: loadWidget);
         }

+ 3 - 6
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),
     );
   }