2022-08-21 18:41:36 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2022-08-08 15:11:56 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:immich_mobile/constants/hive_box.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2022-08-21 18:41:36 +02:00
|
|
|
import 'package:immich_mobile/utils/image_url_builder.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
|
|
class AlbumThumbnailCard extends StatelessWidget {
|
2023-02-08 21:42:45 +02:00
|
|
|
final Function()? onTap;
|
|
|
|
|
2022-08-21 18:41:36 +02:00
|
|
|
const AlbumThumbnailCard({
|
|
|
|
Key? key,
|
|
|
|
required this.album,
|
2023-02-08 21:42:45 +02:00
|
|
|
this.onTap,
|
2022-08-21 18:41:36 +02:00
|
|
|
}) : super(key: key);
|
2022-08-03 07:04:34 +02:00
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
final Album album;
|
2022-08-03 07:04:34 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var box = Hive.box(userInfoBox);
|
2022-11-30 18:58:07 +02:00
|
|
|
var isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
2023-02-08 21:42:45 +02:00
|
|
|
return LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
var cardSize = constraints.maxWidth;
|
2022-08-03 07:04:34 +02:00
|
|
|
|
2023-02-08 21:42:45 +02:00
|
|
|
buildEmptyThumbnail() {
|
|
|
|
return Container(
|
2022-11-30 18:58:07 +02:00
|
|
|
height: cardSize,
|
|
|
|
width: cardSize,
|
2023-02-08 21:42:45 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: isDarkMode ? Colors.grey[800] : Colors.grey[200],
|
2022-11-30 18:58:07 +02:00
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
child: Center(
|
|
|
|
child: Icon(
|
|
|
|
Icons.no_photography,
|
|
|
|
size: cardSize * .15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-11-30 18:58:07 +02:00
|
|
|
|
2023-02-08 21:42:45 +02:00
|
|
|
buildAlbumThumbnail() {
|
|
|
|
return CachedNetworkImage(
|
|
|
|
width: cardSize,
|
|
|
|
height: cardSize,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
fadeInDuration: const Duration(milliseconds: 200),
|
|
|
|
imageUrl: getAlbumThumbnailUrl(
|
|
|
|
album,
|
|
|
|
type: ThumbnailFormat.JPEG,
|
|
|
|
),
|
|
|
|
httpHeaders: {"Authorization": "Bearer ${box.get(accessTokenKey)}"},
|
|
|
|
cacheKey: getAlbumThumbNailCacheKey(album, type: ThumbnailFormat.JPEG),
|
|
|
|
);
|
|
|
|
}
|
2022-08-08 15:11:56 +02:00
|
|
|
|
2023-02-08 21:42:45 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: onTap,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 32.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
child: album.albumThumbnailAssetId == null
|
|
|
|
? buildEmptyThumbnail()
|
|
|
|
: buildAlbumThumbnail(),
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: SizedBox(
|
|
|
|
width: cardSize,
|
|
|
|
child: Text(
|
|
|
|
album.name,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
album.assetCount == 1
|
|
|
|
? 'album_thumbnail_card_item'
|
|
|
|
: 'album_thumbnail_card_items',
|
|
|
|
style: const TextStyle(
|
2022-08-16 01:53:30 +02:00
|
|
|
fontSize: 12,
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
).tr(args: ['${album.assetCount}']),
|
|
|
|
if (album.shared)
|
|
|
|
const Text(
|
|
|
|
'album_thumbnail_card_shared',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
).tr()
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
);
|
|
|
|
},
|
2022-08-03 07:04:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|