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-11-03 16:04:41 +02:00
|
|
|
import 'package:timezone/timezone.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-09-12 15:43:15 +02:00
|
|
|
import 'package:immich_mobile/shared/models/exif_info.dart';
|
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.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-09-12 15:43:15 +02:00
|
|
|
bool hasCoordinates(ExifInfo? exifInfo) =>
|
|
|
|
exifInfo != null &&
|
|
|
|
exifInfo.latitude != null &&
|
|
|
|
exifInfo.longitude != null &&
|
|
|
|
exifInfo.latitude != 0 &&
|
|
|
|
exifInfo.longitude != 0;
|
2023-02-11 04:31:15 +02:00
|
|
|
|
2023-11-03 16:04:41 +02:00
|
|
|
String formatTimeZone(Duration d) =>
|
|
|
|
"GMT${d.isNegative ? '-': '+'}${d.inHours.abs().toString().padLeft(2, '0')}:${d.inMinutes.abs().remainder(60).toString().padLeft(2, '0')}";
|
|
|
|
|
2023-08-19 00:53:50 +02:00
|
|
|
String get formattedDateTime {
|
2023-11-03 16:04:41 +02:00
|
|
|
DateTime dt = asset.fileCreatedAt.toLocal();
|
|
|
|
String? timeZone;
|
|
|
|
if (asset.exifInfo?.dateTimeOriginal != null) {
|
|
|
|
dt = asset.exifInfo!.dateTimeOriginal!;
|
|
|
|
if (asset.exifInfo?.timeZone != null) {
|
|
|
|
dt = dt.toUtc();
|
|
|
|
try {
|
|
|
|
final location = getLocation(asset.exifInfo!.timeZone!);
|
|
|
|
dt = TZDateTime.from(dt, location);
|
|
|
|
} on LocationNotFoundException {
|
|
|
|
RegExp re = RegExp(r'^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$', caseSensitive: false);
|
|
|
|
final m = re.firstMatch(asset.exifInfo!.timeZone!);
|
|
|
|
if (m != null) {
|
|
|
|
final duration = Duration(hours: int.parse(m.group(1) ?? '0'), minutes: int.parse(m.group(2) ?? '0'));
|
|
|
|
dt = dt.add(duration);
|
|
|
|
timeZone = formatTimeZone(duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final date = DateFormat.yMMMEd().format(dt);
|
|
|
|
final time = DateFormat.jm().format(dt);
|
|
|
|
timeZone ??= formatTimeZone(dt.timeZoneOffset);
|
2023-08-19 00:53:50 +02:00
|
|
|
|
2023-11-03 16:04:41 +02:00
|
|
|
return '$date • $time $timeZone';
|
2023-08-19 00:53:50 +02:00
|
|
|
}
|
|
|
|
|
2023-09-12 15:43:15 +02:00
|
|
|
Future<Uri?> _createCoordinatesUri(ExifInfo? exifInfo) async {
|
|
|
|
if (!hasCoordinates(exifInfo)) {
|
2023-08-19 00:53:50 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:43:15 +02:00
|
|
|
final double latitude = exifInfo!.latitude!;
|
|
|
|
final double longitude = exifInfo.longitude!;
|
2023-08-19 00:53:50 +02:00
|
|
|
|
|
|
|
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-09-12 15:43:15 +02:00
|
|
|
final assetWithExif = ref.watch(assetDetailProvider(asset));
|
|
|
|
final exifInfo = (assetWithExif.value ?? asset).exifInfo;
|
2023-04-13 17:22:06 +02:00
|
|
|
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 {
|
2023-09-12 15:43:15 +02:00
|
|
|
Uri? uri = await _createCoordinatesUri(exifInfo);
|
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;
|
2023-09-08 07:55:55 +02:00
|
|
|
return text.isNotEmpty ? text : null;
|
2023-02-04 22:42:42 +02:00
|
|
|
}
|
|
|
|
|
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-09-12 15:43:15 +02:00
|
|
|
if (!hasCoordinates(exifInfo)) {
|
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,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-09-08 07:55:55 +02:00
|
|
|
|
|
|
|
buildImageProperties() {
|
|
|
|
// Helper to create the ListTile and avoid repeating code
|
|
|
|
createImagePropertiesListStyle(title, subtitle) => ListTile(
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
dense: true,
|
|
|
|
leading: Icon(
|
|
|
|
Icons.image,
|
|
|
|
color: textColor.withAlpha(200),
|
|
|
|
),
|
|
|
|
titleAlignment: ListTileTitleAlignment.center,
|
|
|
|
title: Text(
|
|
|
|
title,
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: textColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
subtitle: subtitle,
|
|
|
|
);
|
|
|
|
|
|
|
|
final imgSizeString = buildSizeText(asset);
|
|
|
|
|
|
|
|
if (imgSizeString == null && asset.fileName.isNotEmpty) {
|
|
|
|
// There is only filename
|
|
|
|
return createImagePropertiesListStyle(
|
|
|
|
asset.fileName,
|
|
|
|
null,
|
|
|
|
);
|
|
|
|
} else if (imgSizeString != null && asset.fileName.isNotEmpty) {
|
|
|
|
// There is both filename and size information
|
|
|
|
return createImagePropertiesListStyle(
|
|
|
|
asset.fileName,
|
|
|
|
Text(imgSizeString),
|
|
|
|
);
|
|
|
|
} else if (imgSizeString != null && asset.fileName.isEmpty) {
|
|
|
|
// There is only size information
|
|
|
|
return createImagePropertiesListStyle(
|
|
|
|
imgSizeString,
|
|
|
|
null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-02-11 04:31:15 +02:00
|
|
|
|
|
|
|
buildDetail() {
|
2023-09-08 07:55:55 +02:00
|
|
|
final imgProperties = buildImageProperties();
|
|
|
|
|
|
|
|
// There are no details
|
|
|
|
if (imgProperties == null &&
|
|
|
|
(exifInfo == null || exifInfo.make == null)) {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
|
2023-02-11 04:31:15 +02:00
|
|
|
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(),
|
|
|
|
),
|
2023-09-08 07:55:55 +02:00
|
|
|
if (imgProperties != null) imgProperties,
|
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,
|
|
|
|
),
|
|
|
|
),
|
2023-10-31 12:33:08 +02:00
|
|
|
subtitle: exifInfo.f != null || exifInfo.exposureSeconds != null || exifInfo.mm != null || exifInfo.iso != null ? Text(
|
2023-08-29 15:57:20 +02:00
|
|
|
"ƒ/${exifInfo.fNumber} ${exifInfo.exposureTime} ${exifInfo.focalLength} mm ISO ${exifInfo.iso ?? ''} ",
|
2023-10-31 12:33:08 +02:00
|
|
|
) : null,
|
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-09-12 15:43:15 +02:00
|
|
|
flex: hasCoordinates(exifInfo) ? 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(),
|
2023-10-12 17:30:56 +02:00
|
|
|
assetWithExif.when(
|
|
|
|
data: (data) => DescriptionInput(asset: data),
|
|
|
|
error: (error, stackTrace) => Icon(
|
|
|
|
Icons.image_not_supported_outlined,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
loading: () => const SizedBox(
|
|
|
|
width: 75,
|
|
|
|
height: 75,
|
|
|
|
child: CircularProgressIndicator.adaptive(),
|
|
|
|
),
|
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
const SizedBox(height: 8.0),
|
|
|
|
buildLocation(),
|
2023-09-12 15:43:15 +02:00
|
|
|
SizedBox(height: hasCoordinates(exifInfo) ? 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
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|