2023-08-09 21:47:49 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-11 04:40:11 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-13 17:28:09 +02:00
|
|
|
import 'package:flutter_map/flutter_map.dart';
|
2022-02-11 04:40:11 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-04-13 17:22:06 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/description_input.dart';
|
2023-08-27 07:07:35 +02:00
|
|
|
import 'package:immich_mobile/modules/map/ui/map_thumbnail.dart';
|
2022-11-08 19:00:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2023-01-11 22:54:12 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/drag_sheet.dart';
|
2022-03-13 17:28:09 +02:00
|
|
|
import 'package:latlong2/latlong.dart';
|
2022-11-24 19:39:27 +02:00
|
|
|
import 'package:immich_mobile/utils/bytes_units.dart';
|
2023-05-12 16:21:13 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2022-02-11 04:40:11 +02:00
|
|
|
|
2023-01-11 22:54:12 +02:00
|
|
|
class ExifBottomSheet extends HookConsumerWidget {
|
2023-04-13 17:22:06 +02:00
|
|
|
final Asset asset;
|
2022-02-11 04:40:11 +02:00
|
|
|
|
2023-04-13 17:22:06 +02:00
|
|
|
const ExifBottomSheet({Key? key, required this.asset}) : super(key: key);
|
2022-02-11 04:40:11 +02:00
|
|
|
|
2023-08-19 00:53:50 +02:00
|
|
|
bool get hasCoordinates =>
|
2023-04-13 17:22:06 +02:00
|
|
|
asset.exifInfo?.latitude != null && asset.exifInfo?.longitude != null;
|
2023-02-11 04:31:15 +02:00
|
|
|
|
2023-08-19 00:53:50 +02:00
|
|
|
String get formattedDateTime {
|
|
|
|
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;
|
|
|
|
|
2023-08-09 21:47:49 +02:00
|
|
|
if (Platform.isAndroid) {
|
|
|
|
Uri uri = Uri(
|
|
|
|
scheme: 'geo',
|
|
|
|
host: '$latitude,$longitude',
|
2023-08-27 07:07:35 +02:00
|
|
|
queryParameters: {
|
|
|
|
'z': '$zoomLevel',
|
|
|
|
'q': '$latitude,$longitude($formattedDateTime)',
|
|
|
|
},
|
2023-08-09 21:47:49 +02:00
|
|
|
);
|
|
|
|
if (await canLaunchUrl(uri)) {
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
} else if (Platform.isIOS) {
|
|
|
|
var params = {
|
|
|
|
'll': '$latitude,$longitude',
|
2023-08-19 00:53:50 +02:00
|
|
|
'q': formattedDateTime,
|
|
|
|
'z': '$zoomLevel',
|
2023-08-09 21:47:49 +02:00
|
|
|
};
|
|
|
|
Uri uri = Uri.https('maps.apple.com', '/', params);
|
2023-08-19 00:53:50 +02:00
|
|
|
if (await canLaunchUrl(uri)) {
|
2023-08-09 21:47:49 +02:00
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
}
|
2023-08-19 00:53:50 +02:00
|
|
|
|
|
|
|
return Uri(
|
|
|
|
scheme: 'https',
|
|
|
|
host: 'openstreetmap.org',
|
|
|
|
queryParameters: {'mlat': '$latitude', 'mlon': '$longitude'},
|
|
|
|
fragment: 'map=$zoomLevel/$latitude/$longitude',
|
2023-08-09 21:47:49 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-11 04:40:11 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-04-13 17:22:06 +02:00
|
|
|
final exifInfo = asset.exifInfo;
|
|
|
|
var isDarkTheme = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
var textColor = isDarkTheme ? Colors.white : Colors.black;
|
2023-03-04 00:38:30 +02:00
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
buildMap() {
|
2022-07-01 03:08:49 +02:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
2023-02-11 04:31:15 +02:00
|
|
|
child: LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
2023-08-27 07:07:35 +02:00
|
|
|
return MapThumbnail(
|
|
|
|
coords: LatLng(
|
|
|
|
exifInfo?.latitude ?? 0,
|
|
|
|
exifInfo?.longitude ?? 0,
|
2022-07-01 03:08:49 +02:00
|
|
|
),
|
2023-08-27 07:07:35 +02:00
|
|
|
height: 150,
|
|
|
|
zoom: 16.0,
|
|
|
|
markers: [
|
|
|
|
Marker(
|
|
|
|
anchorPos: AnchorPos.align(AnchorAlign.top),
|
|
|
|
point: LatLng(
|
2023-03-04 00:38:30 +02:00
|
|
|
exifInfo?.latitude ?? 0,
|
|
|
|
exifInfo?.longitude ?? 0,
|
2023-02-11 04:31:15 +02:00
|
|
|
),
|
2023-08-27 07:07:35 +02:00
|
|
|
builder: (ctx) => const Image(
|
|
|
|
image: AssetImage('assets/location-pin.png'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
onTap: (tapPosition, latLong) async {
|
|
|
|
Uri? uri = await _createCoordinatesUri();
|
2023-08-19 00:53:50 +02:00
|
|
|
|
2023-08-27 07:07:35 +02:00
|
|
|
if (uri == null) {
|
|
|
|
return;
|
|
|
|
}
|
2023-08-19 00:53:50 +02:00
|
|
|
|
2023-08-27 07:07:35 +02:00
|
|
|
debugPrint('Opening Map Uri: $uri');
|
|
|
|
launchUrl(uri);
|
|
|
|
},
|
2023-02-11 04:31:15 +02:00
|
|
|
);
|
|
|
|
},
|
2022-07-01 03:08:49 +02:00
|
|
|
),
|
|
|
|
);
|
2022-03-11 00:09:03 +02:00
|
|
|
}
|
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
buildSizeText(Asset a) {
|
|
|
|
String resolution = a.width != null && a.height != null
|
|
|
|
? "${a.height} x ${a.width} "
|
|
|
|
: "";
|
|
|
|
String fileSize = a.exifInfo?.fileSize != null
|
|
|
|
? formatBytes(a.exifInfo!.fileSize!)
|
|
|
|
: "";
|
|
|
|
String text = resolution + fileSize;
|
|
|
|
return text.isEmpty ? null : Text(text);
|
|
|
|
}
|
|
|
|
|
2023-02-11 04:31:15 +02:00
|
|
|
buildDragHeader() {
|
2023-05-12 16:21:13 +02:00
|
|
|
return const Column(
|
2023-02-11 04:31:15 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2023-05-12 16:21:13 +02:00
|
|
|
children: [
|
2023-02-11 04:31:15 +02:00
|
|
|
SizedBox(height: 12),
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: CustomDraggingHandle(),
|
|
|
|
),
|
|
|
|
SizedBox(height: 12),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildLocation() {
|
|
|
|
// Guard no lat/lng
|
2023-08-19 00:53:50 +02:00
|
|
|
if (!hasCoordinates) {
|
2023-02-11 04:31:15 +02:00
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
// Location
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"exif_bottom_sheet_location",
|
2023-04-13 17:22:06 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: textColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
).tr(),
|
|
|
|
buildMap(),
|
2023-04-13 17:22:06 +02:00
|
|
|
RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: textColor,
|
|
|
|
fontFamily: 'WorkSans',
|
|
|
|
),
|
|
|
|
children: [
|
|
|
|
if (exifInfo != null && exifInfo.city != null)
|
|
|
|
TextSpan(
|
|
|
|
text: exifInfo.city,
|
|
|
|
),
|
|
|
|
if (exifInfo != null &&
|
|
|
|
exifInfo.city != null &&
|
|
|
|
exifInfo.state != null)
|
|
|
|
const TextSpan(
|
|
|
|
text: ", ",
|
|
|
|
),
|
|
|
|
if (exifInfo != null && exifInfo.state != null)
|
|
|
|
TextSpan(
|
|
|
|
text: "${exifInfo.state}",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
Text(
|
2023-03-04 00:38:30 +02:00
|
|
|
"${exifInfo!.latitude!.toStringAsFixed(4)}, ${exifInfo.longitude!.toStringAsFixed(4)}",
|
2023-02-11 04:31:15 +02:00
|
|
|
style: const TextStyle(fontSize: 12),
|
2023-08-19 00:52:40 +02:00
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildDate() {
|
|
|
|
return Text(
|
2023-08-19 00:53:50 +02:00
|
|
|
formattedDateTime,
|
2023-02-11 04:31:15 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildDetail() {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 8.0),
|
|
|
|
child: Text(
|
|
|
|
"exif_bottom_sheet_details",
|
2023-04-13 17:22:06 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: textColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
).tr(),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
dense: true,
|
2023-04-13 17:22:06 +02:00
|
|
|
leading: Icon(
|
|
|
|
Icons.image,
|
|
|
|
color: textColor.withAlpha(200),
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
title: Text(
|
2023-04-13 17:22:06 +02:00
|
|
|
asset.fileName,
|
2023-02-11 04:31:15 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: textColor,
|
|
|
|
),
|
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
subtitle: buildSizeText(asset),
|
2023-02-11 04:31:15 +02:00
|
|
|
),
|
|
|
|
if (exifInfo?.make != null)
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
dense: true,
|
2023-04-13 17:22:06 +02:00
|
|
|
leading: Icon(
|
|
|
|
Icons.camera,
|
|
|
|
color: textColor.withAlpha(200),
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
title: Text(
|
|
|
|
"${exifInfo!.make} ${exifInfo.model}",
|
|
|
|
style: TextStyle(
|
|
|
|
color: textColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
2023-08-29 15:57:20 +02:00
|
|
|
"ƒ/${exifInfo.fNumber} ${exifInfo.exposureTime} ${exifInfo.focalLength} mm ISO ${exifInfo.iso ?? ''} ",
|
2023-02-11 04:31:15 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-04-13 17:22:06 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
// FocusScope.of(context).unfocus();
|
|
|
|
},
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Card(
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(15),
|
|
|
|
topRight: Radius.circular(15),
|
|
|
|
),
|
2023-01-18 17:59:23 +02:00
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
margin: const EdgeInsets.all(0),
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
if (constraints.maxWidth > 600) {
|
|
|
|
// Two column
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
buildDragHeader(),
|
|
|
|
buildDate(),
|
|
|
|
if (asset.isRemote) DescriptionInput(asset: asset),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
2023-08-19 00:53:50 +02:00
|
|
|
flex: hasCoordinates ? 5 : 0,
|
2023-04-13 17:22:06 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: buildLocation(),
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
Flexible(
|
|
|
|
flex: 5,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
|
|
child: buildDetail(),
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 50),
|
|
|
|
],
|
2023-02-04 22:42:42 +02:00
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// One column
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
buildDragHeader(),
|
|
|
|
buildDate(),
|
|
|
|
if (asset.isRemote) DescriptionInput(asset: asset),
|
|
|
|
const SizedBox(height: 8.0),
|
|
|
|
buildLocation(),
|
2023-08-19 00:53:50 +02:00
|
|
|
SizedBox(height: hasCoordinates ? 16.0 : 0.0),
|
2023-04-13 17:22:06 +02:00
|
|
|
buildDetail(),
|
|
|
|
const SizedBox(height: 50),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-01-11 22:54:12 +02:00
|
|
|
),
|
|
|
|
),
|
2022-02-11 04:40:11 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|