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

132 lines
4.6 KiB
Dart
Raw Normal View History

2023-06-06 16:43:32 +00:00
import "package:flutter/material.dart";
import "package:photos/generated/l10n.dart";
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/theme/colors.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 OutgoingAlbumItem extends StatelessWidget {
final CollectionWithThumbnail c;
2023-06-19 05:49:39 +00:00
static const heroTagPrefix = "outgoing_collection";
2023-06-06 16:43:32 +00:00
const OutgoingAlbumItem({super.key, required this.c});
@override
Widget build(BuildContext context) {
final shareesName = <String>[];
if (c.collection.hasSharees) {
for (int index = 0; index < c.collection.sharees!.length; index++) {
final sharee = c.collection.sharees![index]!;
final String name =
(sharee.name?.isNotEmpty ?? false) ? sharee.name! : sharee.email;
if (index < 2) {
shareesName.add(name);
} else {
final remaining = c.collection.sharees!.length - index;
if (remaining == 1) {
// If it's the last sharee
shareesName.add(name);
} else {
shareesName.add(
"and " +
remaining.toString() +
" other" +
(remaining > 1 ? "s" : ""),
);
}
break;
}
}
}
2023-06-19 05:49:39 +00:00
2023-06-06 16:43:32 +00:00
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: Container(
margin: const EdgeInsets.fromLTRB(16, 12, 16, 12),
child: Row(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(1),
child: SizedBox(
height: 60,
width: 60,
child: FutureBuilder<File?>(
future: CollectionsService.instance.getCover(c.collection),
builder: (context, snapshot) {
if (snapshot.hasData) {
2023-06-19 05:49:39 +00:00
final String heroTag = heroTagPrefix + snapshot.data!.tag;
return Hero(
tag: heroTag,
child: ThumbnailWidget(
snapshot.data!,
key: ValueKey(heroTag),
),
);
} else {
return const NoThumbnailWidget();
}
},
),
2023-06-06 16:43:32 +00:00
),
),
const Padding(padding: EdgeInsets.all(8)),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
c.collection.displayName,
style: const TextStyle(
fontSize: 16,
),
),
const Padding(padding: EdgeInsets.all(2)),
c.collection.hasLink
? (c.collection.publicURLs!.first!.isExpired
? const Icon(
Icons.link,
color: warning500,
)
: const Icon(Icons.link))
: const SizedBox.shrink(),
2023-06-06 16:43:32 +00:00
],
),
shareesName.isEmpty
? const SizedBox.shrink()
2023-06-06 16:43:32 +00:00
: Padding(
padding: const EdgeInsets.fromLTRB(0, 4, 0, 0),
child: Text(
S.of(context).sharedWith(shareesName.join(", ")),
style: TextStyle(
fontSize: 14,
color: Theme.of(context).primaryColorLight,
),
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
],
),
),
onTap: () {
final page = CollectionPage(
c,
appBarType: GalleryType.ownedCollection,
2023-06-19 05:49:39 +00:00
tagPrefix: heroTagPrefix,
2023-06-06 16:43:32 +00:00
);
routeToPage(context, page);
},
);
}
}