diff --git a/lib/core/constants.dart b/lib/core/constants.dart new file mode 100644 index 000000000..95232cd27 --- /dev/null +++ b/lib/core/constants.dart @@ -0,0 +1,2 @@ +const String ENDPOINT = "http://192.168.0.106:8080"; +const String USER = "umbu"; // TODO: Fix me diff --git a/lib/face_search_manager.dart b/lib/face_search_manager.dart new file mode 100644 index 000000000..185c2abbb --- /dev/null +++ b/lib/face_search_manager.dart @@ -0,0 +1,24 @@ +import 'package:dio/dio.dart'; +import 'package:logger/logger.dart'; +import 'package:myapp/core/constants.dart' as Constants; + +import 'models/face.dart'; + +class FaceSearchManager { + final _logger = Logger(); + final _dio = Dio(); + + Future> getFaces() { + return _dio + .get(Constants.ENDPOINT + "/faces", + queryParameters: {"user": Constants.USER}) + .then((response) => (response.data["faces"] as List) + .map((face) => new Face.fromJson(face)) + .toList()) + .catchError(_onError); + } + + void _onError(error) { + _logger.e(error); + } +} diff --git a/lib/main.dart b/lib/main.dart index 917430a6c..91f93258f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -79,7 +79,6 @@ class HomeWidget extends StatelessWidget { child: TextField( readOnly: true, onTap: () { - logger.i("Tapped"); Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext context) { diff --git a/lib/models/face.dart b/lib/models/face.dart new file mode 100644 index 000000000..7d817f09d --- /dev/null +++ b/lib/models/face.dart @@ -0,0 +1,8 @@ +class Face { + final int faceID; + final String thumbnailURL; + + Face.fromJson(Map json) + : faceID = json["faceID"], + thumbnailURL = json["thumbnailURL"]; +} diff --git a/lib/photo_sync_manager.dart b/lib/photo_sync_manager.dart index c93a408be..5f5a07acd 100644 --- a/lib/photo_sync_manager.dart +++ b/lib/photo_sync_manager.dart @@ -10,12 +10,11 @@ import 'package:photo_manager/photo_manager.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:dio/dio.dart'; import 'package:myapp/models/photo.dart'; +import 'package:myapp/core/constants.dart' as Constants; class PhotoSyncManager { final _logger = Logger(); final _dio = Dio(); - final _endpoint = "http://192.168.0.106:8080"; - final _user = "umbu"; final List _assets; static final _lastSyncTimestampKey = "last_sync_timestamp_0"; static final _lastDBUpdateTimestampKey = "last_db_update_timestamp"; @@ -113,7 +112,7 @@ class PhotoSyncManager { } else { var localPath = path + basename(photo.url); await _dio - .download(_endpoint + photo.url, localPath) + .download(Constants.ENDPOINT + photo.url, localPath) .catchError(_onError); photo.localPath = localPath; Photo.setThumbnail(photo); @@ -125,10 +124,11 @@ class PhotoSyncManager { } Future> _getDiff(int lastSyncTimestamp) async { - Response response = await _dio.get(_endpoint + "/diff", queryParameters: { - "user": _user, - "lastSyncTimestamp": lastSyncTimestamp - }).catchError(_onError); + Response response = await _dio.get(Constants.ENDPOINT + "/diff", + queryParameters: { + "user": Constants.USER, + "lastSyncTimestamp": lastSyncTimestamp + }).catchError(_onError); _logger.i(response.toString()); if (response != null) { return (response.data["diff"] as List) @@ -142,10 +142,10 @@ class PhotoSyncManager { Future _uploadFile(String path, String hash) async { var formData = FormData.fromMap({ "file": await MultipartFile.fromFile(path, filename: basename(path)), - "user": _user, + "user": Constants.USER, }); var response = await _dio - .post(_endpoint + "/upload", data: formData) + .post(Constants.ENDPOINT + "/upload", data: formData) .catchError(_onError); _logger.i(response.toString()); var photo = Photo.fromJson(response.data); diff --git a/lib/ui/search_page.dart b/lib/ui/search_page.dart index 6dd6e6082..1b78542ae 100644 --- a/lib/ui/search_page.dart +++ b/lib/ui/search_page.dart @@ -1,6 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:myapp/face_search_manager.dart'; +import 'package:myapp/models/face.dart'; +import 'package:myapp/core/constants.dart' as Constants; class SearchPage extends StatelessWidget { + final FaceSearchManager _faceSearchManager = FaceSearchManager(); @override Widget build(BuildContext context) { return Scaffold( @@ -30,6 +34,44 @@ class SearchPage extends StatelessWidget { ) ], ), + body: Container( + child: _getSearchSuggestions(), + ), ); } + + Widget _getSearchSuggestions() { + return FutureBuilder>( + future: _faceSearchManager.getFaces(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return Container( + height: 60, + margin: EdgeInsets.only(top: 4, left: 4), + child: ListView.builder( + scrollDirection: Axis.horizontal, + itemCount: snapshot.data.length, + itemBuilder: (context, index) { + return _buildItem(context, snapshot.data[index]); + }), + ); + } else { + return Text("Loading..."); + } + }, + ); + } + + Widget _buildItem(BuildContext context, Face face) { + return new Container( + width: 60.0, + height: 60.0, + margin: const EdgeInsets.only(right: 8), + decoration: new BoxDecoration( + shape: BoxShape.circle, + image: new DecorationImage( + fit: BoxFit.contain, + image: + new NetworkImage(Constants.ENDPOINT + face.thumbnailURL)))); + } }