Remove face search widgets
This commit is contained in:
parent
28c1069388
commit
7e5426088f
3 changed files with 1 additions and 171 deletions
|
@ -1,78 +0,0 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:photos/models/face.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/utils/file_name_util.dart';
|
||||
|
||||
class FaceSearchService {
|
||||
final _logger = Logger("FaceSearchManager");
|
||||
final _dio = Dio();
|
||||
|
||||
FaceSearchService._privateConstructor();
|
||||
static final FaceSearchService instance =
|
||||
FaceSearchService._privateConstructor();
|
||||
|
||||
Future<List<Face>> getFaces() {
|
||||
return _dio
|
||||
.get(
|
||||
Configuration.instance.getHttpEndpoint() + "/photos/faces",
|
||||
options: Options(
|
||||
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
)
|
||||
.then((response) => (response.data["faces"] as List)
|
||||
.map((face) => new Face.fromJson(face))
|
||||
.toList())
|
||||
.catchError(_onError);
|
||||
}
|
||||
|
||||
Future<List<File>> getFaceSearchResults(
|
||||
Face face, int beforeCreationTime, int limit) async {
|
||||
_logger.info("Fetching since creation " + beforeCreationTime.toString());
|
||||
final result = await _dio
|
||||
.get(
|
||||
Configuration.instance.getHttpEndpoint() +
|
||||
"/search/face/" +
|
||||
face.id.toString(),
|
||||
queryParameters: {
|
||||
"limit": limit,
|
||||
"beforeCreationTime": beforeCreationTime,
|
||||
},
|
||||
options:
|
||||
Options(headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
)
|
||||
.then((response) {
|
||||
return (response.data["result"] as List)
|
||||
.map((p) => File.fromJson(p))
|
||||
.toList();
|
||||
}).catchError(_onError);
|
||||
final files = List<File>();
|
||||
if (result == null) {
|
||||
return throw ("Oops. Could not fetch search results.");
|
||||
}
|
||||
for (File file in result) {
|
||||
try {
|
||||
files.add(await FilesDB.instance.getMatchingFile(
|
||||
file.localID,
|
||||
file.title,
|
||||
file.deviceFolder,
|
||||
file.creationTime,
|
||||
file.modificationTime,
|
||||
alternateTitle: getHEICFileNameForJPG(file)));
|
||||
} catch (e) {
|
||||
// Not available locally
|
||||
files.add(file);
|
||||
}
|
||||
}
|
||||
files.sort((first, second) {
|
||||
return second.creationTime.compareTo(first.creationTime);
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
void _onError(error) {
|
||||
_logger.severe(error);
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/services/face_search_service.dart';
|
||||
import 'package:photos/models/face.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/ui/gallery.dart';
|
||||
import 'package:photos/ui/gallery_app_bar_widget.dart';
|
||||
|
||||
class FaceSearchResultsPage extends StatelessWidget {
|
||||
final FaceSearchService _faceSearchManager = FaceSearchService.instance;
|
||||
final Face face;
|
||||
final selectedFiles = SelectedFiles();
|
||||
|
||||
FaceSearchResultsPage(this.face, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var gallery = Gallery(
|
||||
asyncLoader: (lastFile, limit) => _faceSearchManager.getFaceSearchResults(
|
||||
face,
|
||||
lastFile == null
|
||||
? DateTime.now().microsecondsSinceEpoch
|
||||
: lastFile.creationTime,
|
||||
limit),
|
||||
tagPrefix: "face_search_results",
|
||||
selectedFiles: selectedFiles,
|
||||
);
|
||||
return Scaffold(
|
||||
appBar: GalleryAppBarWidget(
|
||||
GalleryAppBarType.search_results,
|
||||
"Search results",
|
||||
selectedFiles,
|
||||
),
|
||||
body: Container(
|
||||
child: gallery,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/services/face_search_service.dart';
|
||||
import 'package:photos/models/face.dart';
|
||||
import 'package:photos/ui/circular_network_image_widget.dart';
|
||||
import 'package:photos/ui/face_search_results_page.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/location_search_widget.dart';
|
||||
|
||||
class SearchPage extends StatefulWidget {
|
||||
|
@ -12,9 +7,6 @@ class SearchPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _SearchPageState extends State<SearchPage> {
|
||||
final FaceSearchService _faceSearchManager = FaceSearchService.instance;
|
||||
String _searchString = "";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -27,53 +19,7 @@ class _SearchPageState extends State<SearchPage> {
|
|||
)
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
child: _searchString.isEmpty ? _getSearchSuggestions() : Container(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getSearchSuggestions() {
|
||||
return FutureBuilder<List<Face>>(
|
||||
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 if (snapshot.hasError) {
|
||||
return Center(child: Text("Error: " + snapshot.error.toString()));
|
||||
} else {
|
||||
return Center(child: loadWidget);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildItem(BuildContext context, Face face) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_routeToSearchResults(face, context);
|
||||
},
|
||||
child: CircularNetworkImageWidget(face.getThumbnailUrl(), 60),
|
||||
);
|
||||
}
|
||||
|
||||
void _routeToSearchResults(Face face, BuildContext context) {
|
||||
final page = FaceSearchResultsPage(face);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return page;
|
||||
},
|
||||
),
|
||||
body: Container(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue