From 4ee8a30a5a7828e2f1029e53822385cb82ac2adc Mon Sep 17 00:00:00 2001 From: Steffen Auer <60623116+SteffenAuer@users.noreply.github.com> Date: Sat, 19 Aug 2023 00:53:50 +0200 Subject: [PATCH] chore(mobile): ios map launch, use OSM as map fallback, use dates as labels (#3772) --- .../asset_viewer/ui/exif_bottom_sheet.dart | 66 +++++++++++-------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/mobile/lib/modules/asset_viewer/ui/exif_bottom_sheet.dart b/mobile/lib/modules/asset_viewer/ui/exif_bottom_sheet.dart index 11af03fa53..da01f9ec23 100644 --- a/mobile/lib/modules/asset_viewer/ui/exif_bottom_sheet.dart +++ b/mobile/lib/modules/asset_viewer/ui/exif_bottom_sheet.dart @@ -16,16 +16,32 @@ class ExifBottomSheet extends HookConsumerWidget { const ExifBottomSheet({Key? key, required this.asset}) : super(key: key); - bool get showMap => + bool get hasCoordinates => asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null; - Future _createCoordinatesUri(double latitude, double longitude) async { - const zoomLevel = 5; + String get formattedDateTime { + final fileCreatedAt = asset.fileCreatedAt.toLocal(); + final date = DateFormat.yMMMEd().format(fileCreatedAt); + final time = DateFormat.jm().format(fileCreatedAt); + + return '$date • $time'; + } + + Future _createCoordinatesUri() async { + if (!hasCoordinates) { + return null; + } + + double latitude = asset.exifInfo!.latitude!; + double longitude = asset.exifInfo!.longitude!; + + const zoomLevel = 16; + if (Platform.isAndroid) { Uri uri = Uri( scheme: 'geo', host: '$latitude,$longitude', - queryParameters: {'z': '$zoomLevel', 'q': '$latitude,$longitude'}, + queryParameters: {'z': '$zoomLevel', 'q': formattedDateTime}, ); if (await canLaunchUrl(uri)) { return uri; @@ -33,16 +49,20 @@ class ExifBottomSheet extends HookConsumerWidget { } else if (Platform.isIOS) { var params = { 'll': '$latitude,$longitude', - 'q': '$latitude, $longitude', + 'q': formattedDateTime, + 'z': '$zoomLevel', }; Uri uri = Uri.https('maps.apple.com', '/', params); - if (!await canLaunchUrl(uri)) { + if (await canLaunchUrl(uri)) { return uri; } } - return Uri.https( - 'www.google.com', - '/maps/place/$latitude,$longitude/@$latitude,$longitude,${zoomLevel}z', + + return Uri( + scheme: 'https', + host: 'openstreetmap.org', + queryParameters: {'mlat': '$latitude', 'mlon': '$longitude'}, + fragment: 'map=$zoomLevel/$latitude/$longitude', ); } @@ -72,16 +92,14 @@ class ExifBottomSheet extends HookConsumerWidget { ), zoom: 16.0, onTap: (tapPosition, latLong) async { - if (exifInfo != null && - exifInfo.latitude != null && - exifInfo.longitude != null) { - launchUrl( - await _createCoordinatesUri( - exifInfo.latitude!, - exifInfo.longitude!, - ), - ); + Uri? uri = await _createCoordinatesUri(); + + if (uri == null) { + return; } + + debugPrint('Opening Map Uri: $uri'); + launchUrl(uri); }, ), nonRotatedChildren: [ @@ -151,7 +169,7 @@ class ExifBottomSheet extends HookConsumerWidget { buildLocation() { // Guard no lat/lng - if (!showMap) { + if (!hasCoordinates) { return Container(); } @@ -207,12 +225,8 @@ class ExifBottomSheet extends HookConsumerWidget { } buildDate() { - final fileCreatedAt = asset.fileCreatedAt.toLocal(); - final date = DateFormat.yMMMEd().format(fileCreatedAt); - final time = DateFormat.jm().format(fileCreatedAt); - return Text( - '$date • $time', + formattedDateTime, style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 14, @@ -306,7 +320,7 @@ class ExifBottomSheet extends HookConsumerWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Flexible( - flex: showMap ? 5 : 0, + flex: hasCoordinates ? 5 : 0, child: Padding( padding: const EdgeInsets.only(right: 8.0), child: buildLocation(), @@ -336,7 +350,7 @@ class ExifBottomSheet extends HookConsumerWidget { if (asset.isRemote) DescriptionInput(asset: asset), const SizedBox(height: 8.0), buildLocation(), - SizedBox(height: showMap ? 16.0 : 0.0), + SizedBox(height: hasCoordinates ? 16.0 : 0.0), buildDetail(), const SizedBox(height: 50), ],