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';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2023-03-19 21:47:51 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2024-02-27 17:51:19 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_thumbnail.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
|
|
|
|
class AlbumThumbnailCard extends StatelessWidget {
|
2023-02-08 21:42:45 +02:00
|
|
|
final Function()? onTap;
|
|
|
|
|
2023-03-19 21:47:51 +02:00
|
|
|
/// Whether or not to show the owner of the album (or "Owned")
|
|
|
|
/// in the subtitle of the album
|
|
|
|
final bool showOwner;
|
|
|
|
|
2022-08-21 18:41:36 +02:00
|
|
|
const AlbumThumbnailCard({
|
2024-01-27 18:14:32 +02:00
|
|
|
super.key,
|
2022-08-21 18:41:36 +02:00
|
|
|
required this.album,
|
2023-02-08 21:42:45 +02:00
|
|
|
this.onTap,
|
2023-03-19 21:47:51 +02:00
|
|
|
this.showOwner = false,
|
2024-01-27 18:14:32 +02:00
|
|
|
});
|
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) {
|
2023-11-09 18:19:53 +02:00
|
|
|
var isDarkTheme = context.isDarkTheme;
|
|
|
|
|
2023-02-08 21:42:45 +02:00
|
|
|
return LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
2023-02-11 22:23:32 +02:00
|
|
|
var cardSize = constraints.maxWidth;
|
2022-08-03 07:04:34 +02:00
|
|
|
|
2023-02-11 22:23:32 +02:00
|
|
|
buildEmptyThumbnail() {
|
|
|
|
return Container(
|
|
|
|
height: cardSize,
|
|
|
|
width: cardSize,
|
|
|
|
decoration: BoxDecoration(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: isDarkTheme ? Colors.grey[800] : Colors.grey[200],
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
child: Center(
|
|
|
|
child: Icon(
|
|
|
|
Icons.no_photography,
|
|
|
|
size: cardSize * .15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-11-30 18:58:07 +02:00
|
|
|
|
2024-02-27 17:51:19 +02:00
|
|
|
buildAlbumThumbnail() => ImmichThumbnail(
|
|
|
|
asset: album.thumbnail.value,
|
2023-03-04 00:38:30 +02:00
|
|
|
width: cardSize,
|
|
|
|
height: cardSize,
|
|
|
|
);
|
2022-08-08 15:11:56 +02:00
|
|
|
|
2023-03-19 21:47:51 +02:00
|
|
|
buildAlbumTextRow() {
|
|
|
|
// Add the owner name to the subtitle
|
|
|
|
String? owner;
|
|
|
|
if (showOwner) {
|
2023-03-27 04:35:52 +02:00
|
|
|
if (album.ownerId == Store.get(StoreKey.currentUser).id) {
|
2023-03-19 21:47:51 +02:00
|
|
|
owner = 'album_thumbnail_owned'.tr();
|
|
|
|
} else if (album.ownerName != null) {
|
|
|
|
owner = 'album_thumbnail_shared_by'.tr(args: [album.ownerName!]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RichText(
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
text: TextSpan(
|
|
|
|
children: [
|
|
|
|
TextSpan(
|
|
|
|
text: album.assetCount == 1
|
|
|
|
? 'album_thumbnail_card_item'
|
|
|
|
.tr(args: ['${album.assetCount}'])
|
|
|
|
: 'album_thumbnail_card_items'
|
|
|
|
.tr(args: ['${album.assetCount}']),
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodyMedium,
|
2023-03-19 21:47:51 +02:00
|
|
|
),
|
|
|
|
if (owner != null) const TextSpan(text: ' · '),
|
|
|
|
if (owner != null)
|
|
|
|
TextSpan(
|
|
|
|
text: owner,
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodyMedium,
|
2023-03-19 21:47:51 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-11 22:23:32 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: onTap,
|
|
|
|
child: Flex(
|
|
|
|
direction: Axis.vertical,
|
2023-02-08 21:42:45 +02:00
|
|
|
children: [
|
2023-02-11 22:23:32 +02:00
|
|
|
Flexible(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: cardSize,
|
|
|
|
height: cardSize,
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
2023-03-04 00:38:30 +02:00
|
|
|
child: album.thumbnail.value == null
|
2023-02-11 22:23:32 +02:00
|
|
|
? buildEmptyThumbnail()
|
|
|
|
: buildAlbumThumbnail(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: SizedBox(
|
|
|
|
width: cardSize,
|
|
|
|
child: Text(
|
|
|
|
album.name,
|
2023-12-07 20:14:09 +02:00
|
|
|
overflow: TextOverflow.ellipsis,
|
2023-11-20 16:58:03 +02:00
|
|
|
style: context.textTheme.bodyMedium?.copyWith(
|
|
|
|
color: context.primaryColor,
|
|
|
|
fontWeight: FontWeight.w500,
|
2023-02-11 22:23:32 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
2023-03-19 21:47:51 +02:00
|
|
|
buildAlbumTextRow(),
|
2023-02-11 22:23:32 +02:00
|
|
|
],
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
);
|
2023-02-08 21:42:45 +02:00
|
|
|
},
|
2022-08-03 07:04:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|