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';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-12-05 21:34:37 +02:00
|
|
|
import 'package:immich_mobile/extensions/asset_extensions.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-12-05 21:34:37 +02:00
|
|
|
import 'package:immich_mobile/extensions/duration_extensions.dart';
|
2023-04-13 17:22:06 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/description_input.dart';
|
2024-01-15 17:26:13 +02:00
|
|
|
import 'package:immich_mobile/modules/map/widgets/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/providers/asset.provider.dart';
|
2023-01-11 22:54:12 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/drag_sheet.dart';
|
2023-12-05 21:34:37 +02:00
|
|
|
import 'package:immich_mobile/utils/selection_handlers.dart';
|
2022-11-24 19:39:27 +02:00
|
|
|
import 'package:immich_mobile/utils/bytes_units.dart';
|
2024-01-15 17:26:13 +02:00
|
|
|
import 'package:maplibre_gl/maplibre_gl.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-12-05 21:34:37 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final assetWithExif = ref.watch(assetDetailProvider(asset));
|
|
|
|
final exifInfo = (assetWithExif.value ?? asset).exifInfo;
|
|
|
|
var textColor = context.isDarkTheme ? Colors.white : Colors.black;
|
2023-11-03 16:04:41 +02:00
|
|
|
|
2023-12-05 21:34:37 +02:00
|
|
|
bool hasCoordinates() =>
|
|
|
|
exifInfo != null &&
|
|
|
|
exifInfo.latitude != null &&
|
|
|
|
exifInfo.longitude != null &&
|
|
|
|
exifInfo.latitude != 0 &&
|
|
|
|
exifInfo.longitude != 0;
|
2023-08-19 00:53:50 +02:00
|
|
|
|
2023-12-05 21:34:37 +02:00
|
|
|
String formattedDateTime() {
|
|
|
|
final (dt, timeZone) =
|
|
|
|
(assetWithExif.value ?? asset).getTZAdjustedTimeAndOffset();
|
|
|
|
final date = DateFormat.yMMMEd().format(dt);
|
|
|
|
final time = DateFormat.jm().format(dt);
|
2023-08-19 00:53:50 +02:00
|
|
|
|
2023-12-05 21:34:37 +02:00
|
|
|
return '$date • $time GMT${timeZone.formatAsOffset()}';
|
2023-08-19 00:53:50 +02:00
|
|
|
}
|
|
|
|
|
2023-12-05 21:34:37 +02:00
|
|
|
Future<Uri?> createCoordinatesUri() async {
|
|
|
|
if (!hasCoordinates()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final double latitude = exifInfo!.latitude!;
|
|
|
|
final double longitude = exifInfo.longitude!;
|
2023-08-19 00:53:50 +02:00
|
|
|
|
2023-12-05 21:34:37 +02:00
|
|
|
const zoomLevel = 16;
|
2023-08-19 00:53:50 +02:00
|
|
|
|
2023-12-05 21:34:37 +02:00
|
|
|
if (Platform.isAndroid) {
|
|
|
|
Uri uri = Uri(
|
|
|
|
scheme: 'geo',
|
|
|
|
host: '$latitude,$longitude',
|
|
|
|
queryParameters: {
|
|
|
|
'z': '$zoomLevel',
|
|
|
|
'q': '$latitude,$longitude($formattedDateTime)',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if (await canLaunchUrl(uri)) {
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
} else if (Platform.isIOS) {
|
|
|
|
var params = {
|
|
|
|
'll': '$latitude,$longitude',
|
|
|
|
'q': formattedDateTime,
|
2023-08-27 07:07:35 +02:00
|
|
|
'z': '$zoomLevel',
|
2023-12-05 21:34:37 +02:00
|
|
|
};
|
|
|
|
Uri uri = Uri.https('maps.apple.com', '/', params);
|
|
|
|
if (await canLaunchUrl(uri)) {
|
|
|
|
return uri;
|
|
|
|
}
|
2023-08-09 21:47:49 +02:00
|
|
|
}
|
|
|
|
|
2023-12-05 21:34:37 +02:00
|
|
|
return Uri(
|
|
|
|
scheme: 'https',
|
|
|
|
host: 'openstreetmap.org',
|
|
|
|
queryParameters: {'mlat': '$latitude', 'mlon': '$longitude'},
|
|
|
|
fragment: 'map=$zoomLevel/$latitude/$longitude',
|
|
|
|
);
|
|
|
|
}
|
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(
|
2024-01-15 17:26:13 +02:00
|
|
|
centre: LatLng(
|
2023-08-27 07:07:35 +02:00
|
|
|
exifInfo?.latitude ?? 0,
|
|
|
|
exifInfo?.longitude ?? 0,
|
2022-07-01 03:08:49 +02:00
|
|
|
),
|
2023-08-27 07:07:35 +02:00
|
|
|
height: 150,
|
2023-12-05 21:34:37 +02:00
|
|
|
width: constraints.maxWidth,
|
|
|
|
zoom: 12.0,
|
2024-01-15 17:26:13 +02:00
|
|
|
assetMarkerRemoteId: asset.remoteId,
|
2023-08-27 07:07:35 +02:00
|
|
|
onTap: (tapPosition, latLong) async {
|
2023-12-05 21:34:37 +02:00
|
|
|
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;
|
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-12-05 21:34:37 +02:00
|
|
|
if (!hasCoordinates()) {
|
2024-01-06 05:02:16 +02:00
|
|
|
return asset.isRemote && !asset.isReadOnly
|
2023-12-05 21:34:37 +02:00
|
|
|
? ListTile(
|
|
|
|
minLeadingWidth: 0,
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
leading: const Icon(Icons.location_on),
|
|
|
|
title: Text(
|
|
|
|
"exif_bottom_sheet_location_add",
|
|
|
|
style: context.textTheme.bodyMedium?.copyWith(
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: context.primaryColor,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
onTap: () => handleEditLocation(
|
|
|
|
ref,
|
|
|
|
context,
|
|
|
|
[assetWithExif.value ?? asset],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink();
|
2023-02-11 04:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
// Location
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2023-12-05 21:34:37 +02:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"exif_bottom_sheet_location",
|
|
|
|
style: context.textTheme.labelMedium?.copyWith(
|
|
|
|
color:
|
|
|
|
context.textTheme.labelMedium?.color?.withAlpha(200),
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
).tr(),
|
2024-01-06 05:02:16 +02:00
|
|
|
if (asset.isRemote && !asset.isReadOnly)
|
2023-12-05 21:34:37 +02:00
|
|
|
IconButton(
|
|
|
|
onPressed: () => handleEditLocation(
|
|
|
|
ref,
|
|
|
|
context,
|
|
|
|
[assetWithExif.value ?? asset],
|
|
|
|
),
|
|
|
|
icon: const Icon(Icons.edit_outlined),
|
|
|
|
iconSize: 20,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
buildMap(),
|
2023-04-13 17:22:06 +02:00
|
|
|
RichText(
|
|
|
|
text: TextSpan(
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.labelLarge,
|
2023-04-13 17:22:06 +02:00
|
|
|
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-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.labelMedium?.copyWith(
|
|
|
|
color: context.textTheme.labelMedium?.color?.withAlpha(150),
|
|
|
|
),
|
2023-08-19 00:52:40 +02:00
|
|
|
),
|
2023-02-11 04:31:15 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildDate() {
|
2023-12-05 21:34:37 +02:00
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
formattedDateTime(),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
),
|
2024-01-06 05:02:16 +02:00
|
|
|
if (asset.isRemote && !asset.isReadOnly)
|
2023-12-05 21:34:37 +02:00
|
|
|
IconButton(
|
|
|
|
onPressed: () => handleEditDateTime(
|
|
|
|
ref,
|
|
|
|
context,
|
|
|
|
[assetWithExif.value ?? asset],
|
|
|
|
),
|
|
|
|
icon: const Icon(Icons.edit_outlined),
|
|
|
|
iconSize: 20,
|
|
|
|
),
|
|
|
|
],
|
2023-02-11 04:31:15 +02:00
|
|
|
);
|
|
|
|
}
|
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,
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.labelLarge,
|
2023-09-08 07:55:55 +02:00
|
|
|
),
|
|
|
|
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,
|
2023-11-20 16:58:03 +02:00
|
|
|
Text(imgSizeString, style: context.textTheme.bodySmall),
|
2023-09-08 07:55:55 +02:00
|
|
|
);
|
|
|
|
} 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-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.labelMedium?.copyWith(
|
|
|
|
color: context.textTheme.labelMedium?.color?.withAlpha(200),
|
|
|
|
fontWeight: FontWeight.w600,
|
2023-04-13 17:22:06 +02:00
|
|
|
),
|
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}",
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.labelLarge,
|
2023-02-11 04:31:15 +02:00
|
|
|
),
|
2023-11-09 18:19:53 +02:00
|
|
|
subtitle: exifInfo.f != null ||
|
|
|
|
exifInfo.exposureSeconds != null ||
|
|
|
|
exifInfo.mm != null ||
|
|
|
|
exifInfo.iso != null
|
|
|
|
? Text(
|
|
|
|
"ƒ/${exifInfo.fNumber} ${exifInfo.exposureTime} ${exifInfo.focalLength} mm ISO ${exifInfo.iso ?? ''} ",
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodySmall,
|
2023-11-09 18:19:53 +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-12-05 21:34:37 +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(),
|
2023-10-12 17:30:56 +02:00
|
|
|
assetWithExif.when(
|
|
|
|
data: (data) => DescriptionInput(asset: data),
|
|
|
|
error: (error, stackTrace) => Icon(
|
|
|
|
Icons.image_not_supported_outlined,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-10-12 17:30:56 +02:00
|
|
|
),
|
|
|
|
loading: () => const SizedBox(
|
|
|
|
width: 75,
|
|
|
|
height: 75,
|
|
|
|
child: CircularProgressIndicator.adaptive(),
|
|
|
|
),
|
|
|
|
),
|
2023-04-13 17:22:06 +02:00
|
|
|
buildLocation(),
|
2023-12-05 21:34:37 +02:00
|
|
|
SizedBox(height: hasCoordinates() ? 16.0 : 6.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
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|