2023-06-06 16:43:32 +00:00
|
|
|
import "dart:math";
|
|
|
|
|
|
|
|
import "package:flutter/material.dart";
|
|
|
|
import "package:photos/db/files_db.dart";
|
2023-06-19 10:57:53 +00:00
|
|
|
import "package:photos/models/collection.dart";
|
2023-06-06 16:43:32 +00:00
|
|
|
import "package:photos/models/collection_items.dart";
|
2023-06-19 05:38:34 +00:00
|
|
|
import "package:photos/models/file.dart";
|
2023-06-06 16:43:32 +00:00
|
|
|
import "package:photos/models/gallery_type.dart";
|
2023-06-19 05:38:34 +00:00
|
|
|
import "package:photos/services/collections_service.dart";
|
2023-06-06 16:43:32 +00:00
|
|
|
import "package:photos/ui/sharing/user_avator_widget.dart";
|
2023-06-14 08:45:11 +00:00
|
|
|
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 {
|
2023-06-19 10:57:53 +00:00
|
|
|
final Collection c;
|
2023-06-19 09:41:21 +00:00
|
|
|
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-19 10:57:53 +00:00
|
|
|
|
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: [
|
2023-06-19 05:38:34 +00:00
|
|
|
FutureBuilder<File?>(
|
2023-06-19 10:57:53 +00:00
|
|
|
future: CollectionsService.instance.getCover(c),
|
2023-06-19 05:38:34 +00:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
2023-06-19 05:47:40 +00:00
|
|
|
final heroTag = heroTagPrefix + snapshot.data!.tag;
|
2023-06-19 05:38:34 +00:00
|
|
|
return Hero(
|
2023-06-14 08:45:11 +00:00
|
|
|
tag: heroTag,
|
|
|
|
child: ThumbnailWidget(
|
2023-06-19 05:38:34 +00:00
|
|
|
snapshot.data!,
|
2023-06-14 08:45:11 +00:00
|
|
|
key: Key(heroTag),
|
2023-06-19 10:57:53 +00:00
|
|
|
shouldShowArchiveStatus: c.hasShareeArchived(),
|
2023-06-14 08:45:11 +00:00
|
|
|
shouldShowSyncStatus: false,
|
|
|
|
),
|
2023-06-19 05:38:34 +00:00
|
|
|
);
|
|
|
|
} 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(
|
2023-06-19 10:57:53 +00:00
|
|
|
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(
|
2023-06-19 10:57:53 +00:00
|
|
|
c.displayName,
|
2023-06-06 16:43:32 +00:00
|
|
|
style: albumTitleTextStyle,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
FutureBuilder<int>(
|
2023-06-19 10:57:53 +00:00
|
|
|
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 {
|
2023-06-07 06:51:19 +00:00
|
|
|
return const SizedBox.shrink();
|
2023-06-06 16:43:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-06-19 10:57:53 +00:00
|
|
|
onTap: () async {
|
|
|
|
final thumbnail = await CollectionsService.instance.getCover(c);
|
2023-06-06 16:43:32 +00:00
|
|
|
routeToPage(
|
|
|
|
context,
|
|
|
|
CollectionPage(
|
2023-06-19 10:57:53 +00:00
|
|
|
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
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|