diff --git a/lib/db/photo_db.dart b/lib/db/photo_db.dart index c8d72dac8..3b37fe7e1 100644 --- a/lib/db/photo_db.dart +++ b/lib/db/photo_db.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:logging/logging.dart'; +import 'package:photos/models/location.dart'; import 'package:photos/models/photo.dart'; import 'package:path/path.dart'; import 'package:sqflite/sqflite.dart'; @@ -287,8 +288,8 @@ class PhotoDB { photo.uploadedFileId == null ? -1 : photo.uploadedFileId; row[columnTitle] = photo.title; row[columnDeviceFolder] = photo.deviceFolder; - row[columnLatitude] = photo.latitude; - row[columnLongitude] = photo.longitude; + row[columnLatitude] = photo.location.latitude; + row[columnLongitude] = photo.location.longitude; row[columnRemoteFolderId] = photo.remoteFolderId; row[columnRemotePath] = photo.remotePath; row[columnThumbnailPath] = photo.thumbnailPath; @@ -304,8 +305,7 @@ class PhotoDB { photo.uploadedFileId = row[columnUploadedFileId]; photo.title = row[columnTitle]; photo.deviceFolder = row[columnDeviceFolder]; - photo.latitude = row[columnLatitude]; - photo.longitude = row[columnLongitude]; + photo.location = Location(row[columnLatitude], row[columnLongitude]); photo.remoteFolderId = row[columnRemoteFolderId]; photo.remotePath = row[columnRemotePath]; photo.thumbnailPath = row[columnThumbnailPath]; diff --git a/lib/models/location.dart b/lib/models/location.dart new file mode 100644 index 000000000..822fbc43a --- /dev/null +++ b/lib/models/location.dart @@ -0,0 +1,6 @@ +class Location { + final double latitude; + final double longitude; + + Location(this.latitude, this.longitude); +} diff --git a/lib/models/photo.dart b/lib/models/photo.dart index 79a0fc165..7a3714e69 100644 --- a/lib/models/photo.dart +++ b/lib/models/photo.dart @@ -6,6 +6,7 @@ import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:photo_manager/photo_manager.dart'; import 'package:path/path.dart'; import 'package:photos/core/configuration.dart'; +import 'package:photos/models/location.dart'; class Photo { int generatedId; @@ -18,8 +19,7 @@ class Photo { String thumbnailPath; int createTimestamp; int updateTimestamp; - double latitude; - double longitude; + Location location; Photo(); Photo.fromJson(Map json) @@ -40,8 +40,7 @@ class Photo { photo.title = asset.title; photo.deviceFolder = pathEntity.name; final location = await asset.latlngAsync(); - photo.latitude = location.latitude; - photo.longitude = location.longitude; + photo.location = Location(location.latitude, location.longitude); photo.createTimestamp = asset.createDateTime.microsecondsSinceEpoch; if (photo.createTimestamp == 0) { try { diff --git a/lib/ui/location_search_results_page.dart b/lib/ui/location_search_results_page.dart index f94f17894..6b181c476 100644 --- a/lib/ui/location_search_results_page.dart +++ b/lib/ui/location_search_results_page.dart @@ -1,16 +1,25 @@ +import 'dart:async'; + import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:latlong/latlong.dart'; +import 'package:photos/models/location.dart'; import 'package:photos/models/photo.dart'; import 'package:photos/photo_repository.dart'; import 'package:photos/ui/gallery.dart'; import 'package:photos/ui/loading_widget.dart'; +class ViewPort { + final Location northEast; + final Location southWest; + + ViewPort(this.northEast, this.southWest); +} + class LocationSearchResultsPage extends StatefulWidget { - final LatLng location; + final ViewPort viewPort; final String name; - LocationSearchResultsPage(this.location, this.name, {Key key}) + LocationSearchResultsPage(this.viewPort, this.name, {Key key}) : super(key: key); @override @@ -36,10 +45,15 @@ class _LocationSearchResultsPageState extends State { future: _getResult(), builder: (context, snapshot) { if (snapshot.hasData) { + if (snapshot.data.isEmpty) { + return Center(child: Text("Nothing to see here.")); + } return Gallery( snapshot.data, Set(), ); + } else if (snapshot.hasError) { + return Center(child: Text(snapshot.error.toString())); } else { return Center(child: loadWidget); } @@ -47,26 +61,25 @@ class _LocationSearchResultsPageState extends State { ); } - Future> _getResult() async { + FutureOr> _getResult() async { final photos = PhotoRepository.instance.photos; final args = Map(); args['photos'] = photos; - args['location'] = widget.location; - args['maxDistance'] = 5000; - return await compute(_filterPhotos, args); + args['viewPort'] = widget.viewPort; + return _filterPhotos(args); } static List _filterPhotos(Map args) { List photos = args['photos']; - LatLng location = args['location']; - int maxDistance = args['maxDistance']; + ViewPort viewPort = args['viewPort']; final result = List(); for (final photo in photos) { - final distance = Distance().as(LengthUnit.Meter, location, - new LatLng(photo.latitude, photo.longitude)); - if (distance < maxDistance) { + if (viewPort.northEast.latitude > photo.location.latitude && + viewPort.southWest.latitude < photo.location.latitude && + viewPort.northEast.longitude > photo.location.longitude && + viewPort.southWest.longitude < photo.location.longitude) { result.add(photo); - } + } else {} } return result; } diff --git a/lib/ui/search_page.dart b/lib/ui/search_page.dart index 06b74aaac..164080c77 100644 --- a/lib/ui/search_page.dart +++ b/lib/ui/search_page.dart @@ -1,14 +1,10 @@ -import 'dart:developer'; - import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_typeahead/flutter_typeahead.dart'; -import 'package:latlong/latlong.dart'; import 'package:photos/core/configuration.dart'; import 'package:photos/face_search_manager.dart'; import 'package:photos/models/face.dart'; -import 'package:photos/models/photo.dart'; -import 'package:photos/photo_repository.dart'; +import 'package:photos/models/location.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'; @@ -41,7 +37,7 @@ class _SearchPageState extends State { loadingBuilder: (context) { return loadWidget; }, - debounceDuration: Duration(milliseconds: 100), + debounceDuration: Duration(milliseconds: 300), suggestionsCallback: (pattern) async { if (pattern.isEmpty) { return null; @@ -55,18 +51,23 @@ class _SearchPageState extends State { .data["results"]; }, itemBuilder: (context, suggestion) { - if (suggestion == null) { - return null; - } return LocationSearchResultWidget(suggestion['name']); }, onSuggestionSelected: (suggestion) { - double latitude = suggestion['geometry']['location']['lat']; - double longitude = suggestion['geometry']['location']['lng']; Navigator.pop(context); Navigator.of(context).push(MaterialPageRoute( builder: (context) => LocationSearchResultsPage( - new LatLng(latitude, longitude), + ViewPort( + Location( + suggestion['geometry']['viewport']['northeast'] + ['lat'], + suggestion['geometry']['viewport']['northeast'] + ['lng']), + Location( + suggestion['geometry']['viewport']['southwest'] + ['lat'], + suggestion['geometry']['viewport']['southwest'] + ['lng'])), suggestion['name'], ))); }, diff --git a/pubspec.lock b/pubspec.lock index d5cde34dc..fec2a426f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,13 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - ansicolor: - dependency: transitive - description: - name: ansicolor - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" archive: dependency: "direct main" description: @@ -71,13 +64,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.5" - console_log_handler: - dependency: transitive - description: - name: console_log_handler - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.6" convert: dependency: transitive description: @@ -226,13 +212,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.1" - latlong: - dependency: "direct main" - description: - name: latlong - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.1" like_button: dependency: "direct main" description: @@ -504,13 +483,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.4.1" - validate: - dependency: transitive - description: - name: validate - url: "https://pub.dartlang.org" - source: hosted - version: "1.7.0" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 299db01a4..22d5a9232 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -48,7 +48,6 @@ dependencies: logging: ^0.11.4 flutter_image_compress: ^0.6.5+1 flutter_typeahead: ^1.8.1 - latlong: ^0.6.1 dev_dependencies: flutter_test: