ente/lib/ui/tabs/shared/incoming_album_item.dart

134 lines
4.7 KiB
Dart
Raw Normal View History

2023-06-06 16:43:32 +00:00
import "dart:math";
import "package:flutter/material.dart";
import "package:photos/db/files_db.dart";
import "package:photos/models/collection.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/models/collection_items.dart";
import "package:photos/models/file.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/models/gallery_type.dart";
import "package:photos/services/collections_service.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/ui/sharing/user_avator_widget.dart";
import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";
2023-06-06 16:43:32 +00:00
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
import "package:photos/utils/navigation_util.dart";
class IncomingAlbumItem extends StatelessWidget {
final Collection c;
static const String heroTagPrefix = "shared_collection";
2023-06-06 16:43:32 +00:00
const IncomingAlbumItem(
this.c, {
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
const double horizontalPaddingOfGridRow = 16;
const double crossAxisSpacingOfGrid = 9;
final TextStyle albumTitleTextStyle =
2023-06-13 06:41:31 +00:00
Theme.of(context).textTheme.titleMedium!.copyWith(fontSize: 14);
2023-06-06 16:43:32 +00:00
final Size size = MediaQuery.of(context).size;
final int albumsCountInOneRow = max(size.width ~/ 220.0, 2);
final double totalWhiteSpaceOfRow = (horizontalPaddingOfGridRow * 2) +
(albumsCountInOneRow - 1) * crossAxisSpacingOfGrid;
final double sideOfThumbnail = (size.width / albumsCountInOneRow) -
(totalWhiteSpaceOfRow / albumsCountInOneRow);
2023-06-06 16:43:32 +00:00
return GestureDetector(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(1),
child: SizedBox(
height: sideOfThumbnail,
width: sideOfThumbnail,
child: Stack(
children: [
FutureBuilder<File?>(
future: CollectionsService.instance.getCover(c),
builder: (context, snapshot) {
if (snapshot.hasData) {
2023-06-19 05:47:40 +00:00
final heroTag = heroTagPrefix + snapshot.data!.tag;
return Hero(
tag: heroTag,
child: ThumbnailWidget(
snapshot.data!,
key: Key(heroTag),
shouldShowArchiveStatus: c.hasShareeArchived(),
shouldShowSyncStatus: false,
),
);
} else {
return const NoThumbnailWidget();
}
},
),
2023-06-06 16:43:32 +00:00
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(right: 8.0, bottom: 8.0),
child: UserAvatarWidget(
c.owner!,
2023-06-06 16:43:32 +00:00
thumbnailView: true,
),
),
),
],
),
),
),
const SizedBox(height: 4),
Row(
children: [
Container(
constraints: BoxConstraints(maxWidth: sideOfThumbnail - 40),
child: Text(
c.displayName,
2023-06-06 16:43:32 +00:00
style: albumTitleTextStyle,
overflow: TextOverflow.ellipsis,
),
),
FutureBuilder<int>(
future: FilesDB.instance.collectionFileCount(c.id),
2023-06-06 16:43:32 +00:00
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data! > 0) {
return RichText(
text: TextSpan(
style: albumTitleTextStyle.copyWith(
color: albumTitleTextStyle.color!.withOpacity(0.5),
),
children: [
const TextSpan(text: " \u2022 "),
TextSpan(text: snapshot.data.toString()),
],
),
);
} else {
return const SizedBox.shrink();
2023-06-06 16:43:32 +00:00
}
},
),
],
),
],
),
onTap: () async {
final thumbnail = await CollectionsService.instance.getCover(c);
2023-06-06 16:43:32 +00:00
routeToPage(
context,
CollectionPage(
CollectionWithThumbnail(
c,
thumbnail,
),
2023-06-06 16:43:32 +00:00
appBarType: GalleryType.sharedCollection,
2023-06-19 05:47:40 +00:00
tagPrefix: heroTagPrefix,
2023-06-06 16:43:32 +00:00
),
);
},
);
}
}