2022-08-21 18:41:36 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
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';
|
|
|
|
import 'package:immich_mobile/routing/router.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 {
|
2022-08-21 18:41:36 +02:00
|
|
|
const AlbumThumbnailCard({
|
|
|
|
Key? key,
|
|
|
|
required this.album,
|
|
|
|
}) : super(key: key);
|
2022-08-03 07:04:34 +02:00
|
|
|
|
|
|
|
final AlbumResponseDto album;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var box = Hive.box(userInfoBox);
|
|
|
|
|
2022-08-08 15:11:56 +02:00
|
|
|
final cardSize = MediaQuery.of(context).size.width / 2 - 18;
|
|
|
|
|
2022-08-03 07:04:34 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
AutoRouter.of(context).push(AlbumViewerRoute(albumId: album.id));
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 32.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
2022-08-21 18:41:36 +02:00
|
|
|
child: CachedNetworkImage(
|
|
|
|
memCacheHeight: max(400, cardSize.toInt() * 3),
|
2022-08-08 15:11:56 +02:00
|
|
|
width: cardSize,
|
|
|
|
height: cardSize,
|
2022-08-03 07:04:34 +02:00
|
|
|
fit: BoxFit.cover,
|
|
|
|
fadeInDuration: const Duration(milliseconds: 200),
|
2022-08-21 18:41:36 +02:00
|
|
|
imageUrl:
|
|
|
|
getAlbumThumbnailUrl(album, type: ThumbnailFormat.JPEG),
|
|
|
|
httpHeaders: {
|
|
|
|
"Authorization": "Bearer ${box.get(accessTokenKey)}"
|
|
|
|
},
|
|
|
|
cacheKey: "${album.albumThumbnailAssetId}",
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
2022-08-08 15:11:56 +02:00
|
|
|
child: SizedBox(
|
|
|
|
width: cardSize,
|
|
|
|
child: Text(
|
|
|
|
album.albumName,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-08-11 05:48:25 +02:00
|
|
|
album.assetCount == 1
|
2022-08-08 15:11:56 +02:00
|
|
|
? 'album_thumbnail_card_item'
|
|
|
|
: 'album_thumbnail_card_items',
|
2022-08-03 07:04:34 +02:00
|
|
|
style: const TextStyle(
|
2022-08-16 01:53:30 +02:00
|
|
|
fontSize: 12,
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2022-08-11 05:48:25 +02:00
|
|
|
).tr(args: ['${album.assetCount}']),
|
2022-08-03 07:04:34 +02:00
|
|
|
if (album.shared)
|
|
|
|
const Text(
|
2022-08-08 15:11:56 +02:00
|
|
|
'album_thumbnail_card_shared',
|
2022-08-03 07:04:34 +02:00
|
|
|
style: TextStyle(
|
2022-08-16 01:53:30 +02:00
|
|
|
fontSize: 12,
|
2022-08-03 07:04:34 +02:00
|
|
|
),
|
2022-08-08 15:11:56 +02:00
|
|
|
).tr()
|
2022-08-03 07:04:34 +02:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|