2022-08-11 12:28:06 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-05 10:04:48 +00:00
|
|
|
import "package:intl/intl.dart";
|
2022-08-11 12:28:06 +00:00
|
|
|
import 'package:photos/db/files_db.dart';
|
2022-12-15 11:24:51 +00:00
|
|
|
import 'package:photos/models/collection.dart';
|
2022-08-11 12:28:06 +00:00
|
|
|
import 'package:photos/models/collection_items.dart';
|
2023-06-19 17:07:03 +00:00
|
|
|
import "package:photos/models/file.dart";
|
2022-12-15 11:24:51 +00:00
|
|
|
import 'package:photos/models/gallery_type.dart';
|
2023-06-19 17:07:03 +00:00
|
|
|
import "package:photos/services/collections_service.dart";
|
2022-10-19 11:16:27 +00:00
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
2023-01-17 08:30:33 +00:00
|
|
|
import 'package:photos/ui/viewer/file/file_icons_widget.dart';
|
2022-10-19 09:49:32 +00:00
|
|
|
import 'package:photos/ui/viewer/file/no_thumbnail_widget.dart';
|
2022-08-11 12:28:06 +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';
|
2023-01-17 07:48:14 +00:00
|
|
|
import 'package:visibility_detector/visibility_detector.dart';
|
2022-08-11 12:28:06 +00:00
|
|
|
|
2023-06-06 16:43:32 +00:00
|
|
|
class AlbumRowItemWidget extends StatelessWidget {
|
2023-06-19 17:07:03 +00:00
|
|
|
final Collection c;
|
2022-10-19 11:16:27 +00:00
|
|
|
final double sideOfThumbnail;
|
2023-01-17 07:48:14 +00:00
|
|
|
final bool shouldRender;
|
2023-03-07 09:25:23 +00:00
|
|
|
final bool showFileCount;
|
2023-06-19 17:07:03 +00:00
|
|
|
static const tagPrefix = "collection";
|
2022-10-19 11:16:27 +00:00
|
|
|
|
2023-06-06 16:43:32 +00:00
|
|
|
AlbumRowItemWidget(
|
2022-10-19 11:16:27 +00:00
|
|
|
this.c,
|
|
|
|
this.sideOfThumbnail, {
|
2023-01-17 07:48:14 +00:00
|
|
|
this.shouldRender = false,
|
2023-03-07 09:25:23 +00:00
|
|
|
this.showFileCount = true,
|
2022-10-19 09:01:14 +00:00
|
|
|
Key? key,
|
2023-06-19 17:07:03 +00:00
|
|
|
}) : super(key: Key(c.id.toString()));
|
2022-08-11 12:28:06 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-19 11:16:27 +00:00
|
|
|
final enteColorScheme = getEnteColorScheme(context);
|
|
|
|
final enteTextTheme = getEnteTextTheme(context);
|
2022-08-11 12:28:06 +00:00
|
|
|
return GestureDetector(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2022-11-17 05:32:24 +00:00
|
|
|
Stack(
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
2022-11-21 12:07:24 +00:00
|
|
|
borderRadius: BorderRadius.circular(1),
|
2022-11-17 05:32:24 +00:00
|
|
|
child: SizedBox(
|
|
|
|
height: sideOfThumbnail,
|
|
|
|
width: sideOfThumbnail,
|
2023-06-19 17:07:03 +00:00
|
|
|
child: FutureBuilder<File?>(
|
|
|
|
future: CollectionsService.instance.getCover(c),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
final thumbnail = snapshot.data!;
|
|
|
|
final String heroTag = tagPrefix + thumbnail.tag;
|
|
|
|
return Hero(
|
|
|
|
tag: heroTag,
|
|
|
|
child: CollectionItemThumbnailWidget(
|
|
|
|
c: CollectionWithThumbnail(c, thumbnail),
|
2023-01-17 07:48:14 +00:00
|
|
|
heroTag: heroTag,
|
2023-06-19 17:07:03 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const NoThumbnailWidget();
|
|
|
|
}
|
|
|
|
},
|
2022-11-17 05:32:24 +00:00
|
|
|
),
|
|
|
|
),
|
2022-08-11 12:28:06 +00:00
|
|
|
),
|
2022-11-17 05:32:24 +00:00
|
|
|
],
|
2022-08-11 12:28:06 +00:00
|
|
|
),
|
2022-10-19 11:16:27 +00:00
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2022-08-11 12:28:06 +00:00
|
|
|
children: [
|
2022-11-21 12:07:24 +00:00
|
|
|
const SizedBox(height: 2),
|
2022-10-19 11:16:27 +00:00
|
|
|
Text(
|
2023-06-19 17:07:03 +00:00
|
|
|
(c.displayName).trim(),
|
2022-10-19 11:16:27 +00:00
|
|
|
style: enteTextTheme.small,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
2022-08-11 12:28:06 +00:00
|
|
|
),
|
2023-03-07 09:25:23 +00:00
|
|
|
showFileCount
|
|
|
|
? FutureBuilder<int>(
|
2023-06-19 17:07:03 +00:00
|
|
|
future: FilesDB.instance.collectionFileCount(c.id),
|
2023-03-07 09:25:23 +00:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return Text(
|
2023-05-05 10:04:48 +00:00
|
|
|
NumberFormat().format(snapshot.data),
|
2023-03-07 09:25:23 +00:00
|
|
|
style: enteTextTheme.small.copyWith(
|
|
|
|
color: enteColorScheme.textMuted,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Text(
|
|
|
|
"",
|
|
|
|
style: enteTextTheme.small.copyWith(
|
|
|
|
color: enteColorScheme.textMuted,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink(),
|
2022-08-11 12:28:06 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-06-19 17:07:03 +00:00
|
|
|
onTap: () async {
|
|
|
|
final thumbnail = await CollectionsService.instance.getCover(c);
|
2022-12-15 11:24:51 +00:00
|
|
|
routeToPage(
|
|
|
|
context,
|
|
|
|
CollectionPage(
|
2023-06-19 17:07:03 +00:00
|
|
|
CollectionWithThumbnail(c, thumbnail),
|
|
|
|
tagPrefix: tagPrefix,
|
|
|
|
appBarType: (c.type == CollectionType.favorites
|
2022-12-15 11:24:51 +00:00
|
|
|
? GalleryType.favorite
|
|
|
|
: GalleryType.ownedCollection),
|
|
|
|
),
|
|
|
|
);
|
2022-08-11 12:28:06 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 07:48:14 +00:00
|
|
|
|
|
|
|
class CollectionItemThumbnailWidget extends StatefulWidget {
|
|
|
|
const CollectionItemThumbnailWidget({
|
|
|
|
Key? key,
|
|
|
|
required this.c,
|
|
|
|
required this.heroTag,
|
|
|
|
this.shouldRender = false,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final CollectionWithThumbnail c;
|
|
|
|
final String heroTag;
|
|
|
|
final bool shouldRender;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<CollectionItemThumbnailWidget> createState() =>
|
|
|
|
_CollectionItemThumbnailWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CollectionItemThumbnailWidgetState
|
|
|
|
extends State<CollectionItemThumbnailWidget> {
|
|
|
|
bool _shouldRender = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_shouldRender = widget.shouldRender;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return VisibilityDetector(
|
|
|
|
key: Key("collection_item" + widget.c.thumbnail!.tag),
|
|
|
|
onVisibilityChanged: (visibility) {
|
|
|
|
final shouldRender = visibility.visibleFraction > 0;
|
|
|
|
if (mounted && shouldRender && !_shouldRender) {
|
|
|
|
setState(() {
|
|
|
|
_shouldRender = shouldRender;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: _shouldRender
|
|
|
|
? ThumbnailWidget(
|
|
|
|
widget.c.thumbnail,
|
|
|
|
shouldShowArchiveStatus: widget.c.collection.isArchived(),
|
|
|
|
showFavForAlbumOnly: true,
|
|
|
|
key: Key(widget.heroTag),
|
|
|
|
)
|
2023-01-17 08:30:33 +00:00
|
|
|
: const ThumbnailPlaceHolder(),
|
2023-01-17 07:48:14 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|