From 60e7b2c5d936888498a6b28fd4a8ce8f10bbb510 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Tue, 1 Dec 2020 13:56:56 +0900 Subject: [PATCH] various fixes: ocean GPS, ~0 GPS, delayed op feedback --- .../aves/channel/calls/MetadataHandler.kt | 7 +++---- lib/model/image_entry.dart | 13 +++++++++---- lib/model/image_metadata.dart | 17 ++++++++++++----- lib/widgets/common/action_mixins/feedback.dart | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt index f152348e0..09aea57f2 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt @@ -353,10 +353,9 @@ class MetadataHandler(private val context: Context) : MethodCallHandler { if (locationString != null) { val matcher = Metadata.VIDEO_LOCATION_PATTERN.matcher(locationString) if (matcher.find() && matcher.groupCount() >= 2) { - // keep `0.0` as `0.0`, not `0` - val latitude = matcher.group(1)?.toDoubleOrNull() ?: 0.0 - val longitude = matcher.group(2)?.toDoubleOrNull() ?: 0.0 - if (latitude != 0.0 || longitude != 0.0) { + val latitude = matcher.group(1)?.toDoubleOrNull() + val longitude = matcher.group(2)?.toDoubleOrNull() + if (latitude != null && longitude != null) { metadataMap[KEY_LATITUDE] = latitude metadataMap[KEY_LONGITUDE] = longitude } diff --git a/lib/model/image_entry.dart b/lib/model/image_entry.dart index ed1df3392..2de981063 100644 --- a/lib/model/image_entry.dart +++ b/lib/model/image_entry.dart @@ -375,12 +375,17 @@ class ImageEntry { : call()); if (addresses != null && addresses.isNotEmpty) { final address = addresses.first; + final cc = address.countryCode; + final cn = address.countryName; + final aa = address.adminArea; addressDetails = AddressDetails( contentId: contentId, - countryCode: address.countryCode, - countryName: address.countryName, - adminArea: address.adminArea, - locality: address.locality, + countryCode: cc, + countryName: cn, + adminArea: aa, + // if country & admin fields are null, it is likely the ocean, + // which is identified by `featureName` but we default to the address line anyway + locality: address.locality ?? (cc == null && cn == null && aa == null ? address.addressLine : null), ); } } catch (error, stackTrace) { diff --git a/lib/model/image_metadata.dart b/lib/model/image_metadata.dart index 9471d0ec0..ee984acc7 100644 --- a/lib/model/image_metadata.dart +++ b/lib/model/image_metadata.dart @@ -34,9 +34,11 @@ class CatalogMetadata { bool isFlipped; int rotationDegrees; final String mimeType, xmpSubjects, xmpTitleDescription; - final double latitude, longitude; + double latitude, longitude; Address address; + static const double _precisionErrorTolerance = 1e-9; + CatalogMetadata({ this.contentId, this.mimeType, @@ -48,10 +50,15 @@ class CatalogMetadata { this.xmpTitleDescription, double latitude, double longitude, - }) - // Geocoder throws an IllegalArgumentException when a coordinate has a funky values like 1.7056881853375E7 - : latitude = latitude == null || latitude < -90.0 || latitude > 90.0 ? null : latitude, - longitude = longitude == null || longitude < -180.0 || longitude > 180.0 ? null : longitude; + }) { + // Geocoder throws an `IllegalArgumentException` when a coordinate has a funky values like `1.7056881853375E7` + // We also exclude zero coordinates, taking into account precision errors (e.g. {5.952380952380953e-11,-2.7777777777777777e-10}), + // but Flutter's `precisionErrorTolerance` (1e-10) is slightly too lenient for this case. + if (latitude != null && longitude != null && (latitude.abs() > _precisionErrorTolerance || longitude.abs() > _precisionErrorTolerance)) { + this.latitude = latitude < -90.0 || latitude > 90.0 ? null : latitude; + this.longitude = longitude < -180.0 || longitude > 180.0 ? null : longitude; + } + } CatalogMetadata copyWith({ @required int contentId, diff --git a/lib/widgets/common/action_mixins/feedback.dart b/lib/widgets/common/action_mixins/feedback.dart index eca65b6c9..ae69e3a7b 100644 --- a/lib/widgets/common/action_mixins/feedback.dart +++ b/lib/widgets/common/action_mixins/feedback.dart @@ -56,7 +56,7 @@ mixin FeedbackMixin { stream: opStream, builder: (context, snapshot) { Widget child = SizedBox.shrink(); - if (!snapshot.hasError && snapshot.connectionState == ConnectionState.active) { + if (!snapshot.hasError) { final percent = processed.length.toDouble() / selection.length; child = CircularPercentIndicator( percent: percent,