2022-10-01 19:19:40 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2022-11-08 19:00:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/immich_image.dart';
|
2023-04-18 11:47:24 +02:00
|
|
|
import 'package:immich_mobile/utils/storage_indicator.dart';
|
2023-10-23 20:28:12 +02:00
|
|
|
import 'package:isar/isar.dart';
|
2022-10-01 19:19:40 +02:00
|
|
|
|
2023-09-12 15:43:15 +02:00
|
|
|
class ThumbnailImage extends StatelessWidget {
|
2022-11-08 19:00:24 +02:00
|
|
|
final Asset asset;
|
2023-05-17 19:36:02 +02:00
|
|
|
final int index;
|
|
|
|
final Asset Function(int index) loadAsset;
|
|
|
|
final int totalAssets;
|
2022-10-01 19:19:40 +02:00
|
|
|
final bool showStorageIndicator;
|
2023-10-22 04:38:07 +02:00
|
|
|
final bool showStack;
|
2022-10-01 19:19:40 +02:00
|
|
|
final bool useGrayBoxPlaceholder;
|
|
|
|
final bool isSelected;
|
|
|
|
final bool multiselectEnabled;
|
|
|
|
final Function? onSelect;
|
|
|
|
final Function? onDeselect;
|
2023-07-13 17:42:06 +02:00
|
|
|
final int heroOffset;
|
2022-10-01 19:19:40 +02:00
|
|
|
|
|
|
|
const ThumbnailImage({
|
|
|
|
Key? key,
|
|
|
|
required this.asset,
|
2023-05-17 19:36:02 +02:00
|
|
|
required this.index,
|
|
|
|
required this.loadAsset,
|
|
|
|
required this.totalAssets,
|
2022-10-01 19:19:40 +02:00
|
|
|
this.showStorageIndicator = true,
|
2023-10-22 04:38:07 +02:00
|
|
|
this.showStack = false,
|
2022-10-01 19:19:40 +02:00
|
|
|
this.useGrayBoxPlaceholder = false,
|
|
|
|
this.isSelected = false,
|
|
|
|
this.multiselectEnabled = false,
|
|
|
|
this.onDeselect,
|
|
|
|
this.onSelect,
|
2023-07-13 17:42:06 +02:00
|
|
|
this.heroOffset = 0,
|
2022-10-01 19:19:40 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
2023-09-12 15:43:15 +02:00
|
|
|
Widget build(BuildContext context) {
|
2023-07-29 08:32:57 +02:00
|
|
|
final isDarkTheme = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
final assetContainerColor =
|
|
|
|
isDarkTheme ? Colors.blueGrey : Theme.of(context).primaryColorLight;
|
2023-10-23 20:28:12 +02:00
|
|
|
// Assets from response DTOs do not have an isar id, querying which would give us the default autoIncrement id
|
|
|
|
final isFromResponse = asset.id == Isar.autoIncrement;
|
2023-07-29 08:32:57 +02:00
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
Widget buildSelectionIcon(Asset asset) {
|
2022-10-01 19:19:40 +02:00
|
|
|
if (isSelected) {
|
2023-07-29 08:32:57 +02:00
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
color: assetContainerColor,
|
|
|
|
),
|
|
|
|
child: Icon(
|
|
|
|
Icons.check_circle_rounded,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
2022-10-01 19:19:40 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Icon(
|
|
|
|
Icons.circle_outlined,
|
|
|
|
color: Colors.white,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-11 21:03:04 +02:00
|
|
|
Widget buildVideoIcon() {
|
|
|
|
final minutes = asset.duration.inMinutes;
|
|
|
|
final durationString = asset.duration.toString();
|
|
|
|
return Positioned(
|
|
|
|
top: 5,
|
2023-10-28 03:09:17 +02:00
|
|
|
right: 8,
|
2023-10-11 21:03:04 +02:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
minutes > 59
|
|
|
|
? durationString.substring(0, 7) // h:mm:ss
|
|
|
|
: minutes > 0
|
|
|
|
? durationString.substring(2, 7) // mm:ss
|
|
|
|
: durationString.substring(3, 7), // m:ss
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 10,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 3,
|
|
|
|
),
|
|
|
|
const Icon(
|
|
|
|
Icons.play_circle_fill_rounded,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-22 04:38:07 +02:00
|
|
|
Widget buildStackIcon() {
|
|
|
|
return Positioned(
|
2023-10-28 03:09:17 +02:00
|
|
|
top: !asset.isImage ? 28 : 5,
|
|
|
|
right: 8,
|
2023-10-22 04:38:07 +02:00
|
|
|
child: Row(
|
|
|
|
children: [
|
2023-10-26 16:19:06 +02:00
|
|
|
if (asset.stackChildrenCount > 1)
|
2023-10-22 04:38:07 +02:00
|
|
|
Text(
|
2023-10-26 16:19:06 +02:00
|
|
|
"${asset.stackChildrenCount}",
|
2023-10-22 04:38:07 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 10,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
2023-10-26 16:19:06 +02:00
|
|
|
if (asset.stackChildrenCount > 1)
|
2023-10-22 04:38:07 +02:00
|
|
|
const SizedBox(
|
|
|
|
width: 3,
|
|
|
|
),
|
|
|
|
const Icon(
|
|
|
|
Icons.burst_mode_rounded,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:43:15 +02:00
|
|
|
Widget buildImage() {
|
|
|
|
final image = SizedBox(
|
2023-07-29 08:32:57 +02:00
|
|
|
width: 300,
|
|
|
|
height: 300,
|
2023-08-10 15:38:49 +02:00
|
|
|
child: Hero(
|
2023-10-23 20:28:12 +02:00
|
|
|
tag: isFromResponse
|
|
|
|
? '${asset.remoteId}-$heroOffset'
|
|
|
|
: asset.id + heroOffset,
|
2023-08-10 15:38:49 +02:00
|
|
|
child: ImmichImage(
|
|
|
|
asset,
|
|
|
|
useGrayBoxPlaceholder: useGrayBoxPlaceholder,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
),
|
2023-07-29 08:32:57 +02:00
|
|
|
);
|
|
|
|
if (!multiselectEnabled || !isSelected) {
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
width: 0,
|
2023-10-22 04:38:07 +02:00
|
|
|
color: onDeselect == null ? Colors.grey : assetContainerColor,
|
2023-07-29 08:32:57 +02:00
|
|
|
),
|
2023-10-22 04:38:07 +02:00
|
|
|
color: onDeselect == null ? Colors.grey : assetContainerColor,
|
2023-07-29 08:32:57 +02:00
|
|
|
),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
topRight: Radius.circular(15.0),
|
|
|
|
bottomRight: Radius.circular(15.0),
|
|
|
|
bottomLeft: Radius.circular(15.0),
|
|
|
|
topLeft: Radius.zero,
|
|
|
|
),
|
|
|
|
child: image,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-01 19:19:40 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
if (multiselectEnabled) {
|
|
|
|
if (isSelected) {
|
|
|
|
onDeselect?.call();
|
|
|
|
} else {
|
|
|
|
onSelect?.call();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
AutoRouter.of(context).push(
|
|
|
|
GalleryViewerRoute(
|
2023-05-17 19:36:02 +02:00
|
|
|
initialIndex: index,
|
|
|
|
loadAsset: loadAsset,
|
|
|
|
totalAssets: totalAssets,
|
2023-07-13 17:42:06 +02:00
|
|
|
heroOffset: heroOffset,
|
2023-10-22 04:38:07 +02:00
|
|
|
showStack: showStack,
|
2022-10-01 19:19:40 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onLongPress: () {
|
|
|
|
onSelect?.call();
|
|
|
|
HapticFeedback.heavyImpact();
|
|
|
|
},
|
2023-08-10 15:38:49 +02:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: multiselectEnabled && isSelected
|
|
|
|
? Border.all(
|
|
|
|
color: onDeselect == null
|
|
|
|
? Colors.grey
|
|
|
|
: assetContainerColor,
|
|
|
|
width: 8,
|
|
|
|
)
|
|
|
|
: const Border(),
|
2022-10-01 19:19:40 +02:00
|
|
|
),
|
2023-09-12 15:43:15 +02:00
|
|
|
child: buildImage(),
|
2023-08-10 15:38:49 +02:00
|
|
|
),
|
|
|
|
if (multiselectEnabled)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(3.0),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: buildSelectionIcon(asset),
|
2022-10-01 19:19:40 +02:00
|
|
|
),
|
2023-08-10 15:38:49 +02:00
|
|
|
),
|
|
|
|
if (showStorageIndicator)
|
|
|
|
Positioned(
|
2023-10-28 03:09:17 +02:00
|
|
|
right: 8,
|
2023-08-10 15:38:49 +02:00
|
|
|
bottom: 5,
|
|
|
|
child: Icon(
|
|
|
|
storageIcon(asset),
|
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
2022-10-01 19:19:40 +02:00
|
|
|
),
|
2023-08-10 15:38:49 +02:00
|
|
|
),
|
|
|
|
if (asset.isFavorite)
|
|
|
|
const Positioned(
|
2023-10-28 03:09:17 +02:00
|
|
|
left: 8,
|
2023-08-10 15:38:49 +02:00
|
|
|
bottom: 5,
|
|
|
|
child: Icon(
|
|
|
|
Icons.favorite,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 18,
|
2023-02-05 05:25:11 +02:00
|
|
|
),
|
2023-08-10 15:38:49 +02:00
|
|
|
),
|
2023-10-11 21:03:04 +02:00
|
|
|
if (!asset.isImage) buildVideoIcon(),
|
2023-10-28 03:09:17 +02:00
|
|
|
if (asset.stackChildrenCount > 0) buildStackIcon(),
|
2023-08-10 15:38:49 +02:00
|
|
|
],
|
2022-10-01 19:19:40 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|