1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

chore(mobile): ios map launch, use OSM as map fallback, use dates as labels (#3772)

This commit is contained in:
Steffen Auer 2023-08-19 00:53:50 +02:00 committed by GitHub
parent 6243bce46c
commit 4ee8a30a5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,16 +16,32 @@ class ExifBottomSheet extends HookConsumerWidget {
const ExifBottomSheet({Key? key, required this.asset}) : super(key: key); const ExifBottomSheet({Key? key, required this.asset}) : super(key: key);
bool get showMap => bool get hasCoordinates =>
asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null; asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null;
Future<Uri> _createCoordinatesUri(double latitude, double longitude) async { String get formattedDateTime {
const zoomLevel = 5; final fileCreatedAt = asset.fileCreatedAt.toLocal();
final date = DateFormat.yMMMEd().format(fileCreatedAt);
final time = DateFormat.jm().format(fileCreatedAt);
return '$date$time';
}
Future<Uri?> _createCoordinatesUri() async {
if (!hasCoordinates) {
return null;
}
double latitude = asset.exifInfo!.latitude!;
double longitude = asset.exifInfo!.longitude!;
const zoomLevel = 16;
if (Platform.isAndroid) { if (Platform.isAndroid) {
Uri uri = Uri( Uri uri = Uri(
scheme: 'geo', scheme: 'geo',
host: '$latitude,$longitude', host: '$latitude,$longitude',
queryParameters: {'z': '$zoomLevel', 'q': '$latitude,$longitude'}, queryParameters: {'z': '$zoomLevel', 'q': formattedDateTime},
); );
if (await canLaunchUrl(uri)) { if (await canLaunchUrl(uri)) {
return uri; return uri;
@ -33,16 +49,20 @@ class ExifBottomSheet extends HookConsumerWidget {
} else if (Platform.isIOS) { } else if (Platform.isIOS) {
var params = { var params = {
'll': '$latitude,$longitude', 'll': '$latitude,$longitude',
'q': '$latitude, $longitude', 'q': formattedDateTime,
'z': '$zoomLevel',
}; };
Uri uri = Uri.https('maps.apple.com', '/', params); Uri uri = Uri.https('maps.apple.com', '/', params);
if (!await canLaunchUrl(uri)) { if (await canLaunchUrl(uri)) {
return uri; return uri;
} }
} }
return Uri.https(
'www.google.com', return Uri(
'/maps/place/$latitude,$longitude/@$latitude,$longitude,${zoomLevel}z', 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, zoom: 16.0,
onTap: (tapPosition, latLong) async { onTap: (tapPosition, latLong) async {
if (exifInfo != null && Uri? uri = await _createCoordinatesUri();
exifInfo.latitude != null &&
exifInfo.longitude != null) { if (uri == null) {
launchUrl( return;
await _createCoordinatesUri(
exifInfo.latitude!,
exifInfo.longitude!,
),
);
} }
debugPrint('Opening Map Uri: $uri');
launchUrl(uri);
}, },
), ),
nonRotatedChildren: [ nonRotatedChildren: [
@ -151,7 +169,7 @@ class ExifBottomSheet extends HookConsumerWidget {
buildLocation() { buildLocation() {
// Guard no lat/lng // Guard no lat/lng
if (!showMap) { if (!hasCoordinates) {
return Container(); return Container();
} }
@ -207,12 +225,8 @@ class ExifBottomSheet extends HookConsumerWidget {
} }
buildDate() { buildDate() {
final fileCreatedAt = asset.fileCreatedAt.toLocal();
final date = DateFormat.yMMMEd().format(fileCreatedAt);
final time = DateFormat.jm().format(fileCreatedAt);
return Text( return Text(
'$date$time', formattedDateTime,
style: const TextStyle( style: const TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 14, fontSize: 14,
@ -306,7 +320,7 @@ class ExifBottomSheet extends HookConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Flexible( Flexible(
flex: showMap ? 5 : 0, flex: hasCoordinates ? 5 : 0,
child: Padding( child: Padding(
padding: const EdgeInsets.only(right: 8.0), padding: const EdgeInsets.only(right: 8.0),
child: buildLocation(), child: buildLocation(),
@ -336,7 +350,7 @@ class ExifBottomSheet extends HookConsumerWidget {
if (asset.isRemote) DescriptionInput(asset: asset), if (asset.isRemote) DescriptionInput(asset: asset),
const SizedBox(height: 8.0), const SizedBox(height: 8.0),
buildLocation(), buildLocation(),
SizedBox(height: showMap ? 16.0 : 0.0), SizedBox(height: hasCoordinates ? 16.0 : 0.0),
buildDetail(), buildDetail(),
const SizedBox(height: 50), const SizedBox(height: 50),
], ],