2024-01-05 06:20:55 +01:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2023-01-27 06:16:28 +01:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-11-09 17:19:53 +01:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-01-27 06:16:28 +01:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/album.entity.dart';
|
2024-06-26 21:31:55 +02:00
|
|
|
import 'package:immich_mobile/services/api.service.dart';
|
2023-01-27 06:16:28 +01:00
|
|
|
import 'package:immich_mobile/utils/image_url_builder.dart';
|
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
|
|
class AlbumThumbnailListTile extends StatelessWidget {
|
|
|
|
const AlbumThumbnailListTile({
|
2024-01-27 17:14:32 +01:00
|
|
|
super.key,
|
2023-01-27 06:16:28 +01:00
|
|
|
required this.album,
|
|
|
|
this.onTap,
|
2024-01-27 17:14:32 +01:00
|
|
|
});
|
2023-01-27 06:16:28 +01:00
|
|
|
|
2023-02-06 08:13:32 +01:00
|
|
|
final Album album;
|
2023-01-27 06:16:28 +01:00
|
|
|
final void Function()? onTap;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var cardSize = 68.0;
|
|
|
|
|
|
|
|
buildEmptyThumbnail() {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
2023-11-09 17:19:53 +01:00
|
|
|
color: context.isDarkTheme ? Colors.grey[800] : Colors.grey[200],
|
2023-01-27 06:16:28 +01:00
|
|
|
),
|
|
|
|
child: SizedBox(
|
|
|
|
height: cardSize,
|
|
|
|
width: cardSize,
|
|
|
|
child: const Center(
|
|
|
|
child: Icon(Icons.no_photography),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildAlbumThumbnail() {
|
|
|
|
return CachedNetworkImage(
|
|
|
|
width: cardSize,
|
|
|
|
height: cardSize,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
fadeInDuration: const Duration(milliseconds: 200),
|
|
|
|
imageUrl: getAlbumThumbnailUrl(
|
|
|
|
album,
|
2024-05-31 19:44:04 +02:00
|
|
|
type: AssetMediaSize.thumbnail,
|
2023-01-27 06:16:28 +01:00
|
|
|
),
|
2024-06-26 21:31:55 +02:00
|
|
|
httpHeaders: ApiService.getRequestHeaders(),
|
2024-05-31 19:44:04 +02:00
|
|
|
cacheKey:
|
|
|
|
getAlbumThumbNailCacheKey(album, type: AssetMediaSize.thumbnail),
|
2023-03-15 22:29:07 +01:00
|
|
|
errorWidget: (context, url, error) =>
|
|
|
|
const Icon(Icons.image_not_supported_outlined),
|
2023-01-27 06:16:28 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
behavior: HitTestBehavior.opaque,
|
2023-01-27 23:20:45 +01:00
|
|
|
onTap: onTap ??
|
|
|
|
() {
|
2024-01-05 06:20:55 +01:00
|
|
|
context.pushRoute(AlbumViewerRoute(albumId: album.id));
|
2023-01-27 23:20:45 +01:00
|
|
|
},
|
2023-01-27 06:16:28 +01:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 12.0),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
2023-12-06 15:56:09 +01:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
2023-03-03 23:38:30 +01:00
|
|
|
child: album.thumbnail.value == null
|
2023-01-27 06:16:28 +01:00
|
|
|
? buildEmptyThumbnail()
|
|
|
|
: buildAlbumThumbnail(),
|
|
|
|
),
|
2023-12-06 15:56:09 +01:00
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
album.name,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2023-01-27 06:16:28 +01:00
|
|
|
),
|
2023-12-06 15:56:09 +01:00
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
album.assetCount == 1
|
|
|
|
? 'album_thumbnail_card_item'
|
|
|
|
: 'album_thumbnail_card_items',
|
|
|
|
style: const TextStyle(
|
2023-01-27 06:16:28 +01:00
|
|
|
fontSize: 12,
|
|
|
|
),
|
2023-12-06 15:56:09 +01:00
|
|
|
).tr(args: ['${album.assetCount}']),
|
|
|
|
if (album.shared)
|
|
|
|
const Text(
|
|
|
|
'album_thumbnail_card_shared',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
).tr(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-01-27 06:16:28 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|