Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Fix album covers and align the cover design

r4khula69fe4a5ef16
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
index f665f14cc1..581c3a6f9d 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart
@@ -4,6 +4,7 @@ import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
import 'package:flutter/material.dart';
import "package:hugeicons/hugeicons.dart";
+import "package:logging/logging.dart";
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
@@ -52,6 +53,7 @@ class CollectionPage extends StatefulWidget {
}
class _CollectionPageState extends State<CollectionPage> {
+ final _logger = Logger("CollectionPage");
final _selectedFiles = SelectedFiles();
late final _searchFilterDataProvider = SearchFilterDataProvider(
initialGalleryFilter: AlbumFilter(
@@ -63,6 +65,9 @@ class _CollectionPageState extends State<CollectionPage> {
late final StreamSubscription<CollectionUpdatedEvent>
_collectionUpdatedSubscription;
EnteFile? _cover;
+ EnteFile? _defaultCover;
+ int _coverLoadGeneration = 0;
+ int _galleryLoadGeneration = 0;
@override
void initState() {
@@ -71,7 +76,10 @@ class _CollectionPageState extends State<CollectionPage> {
_cover =
widget.c.thumbnail ??
CollectionsService.instance.getCoverCache(collection);
- _loadCover();
+ _defaultCover = _cover;
+ if (collection.hasCover) {
+ unawaited(_loadCover());
+ }
_collectionUpdatedSubscription = Bus.instance
.on<CollectionUpdatedEvent>()
.where((event) => event.collectionID == collection.id)
@@ -85,10 +93,22 @@ class _CollectionPageState extends State<CollectionPage> {
}
Future<void> _loadCover() async {
- final cover = await CollectionsService.instance.getCover(
- widget.c.collection,
- );
- if (mounted && cover != _cover) {
+ final generation = ++_coverLoadGeneration;
+ final collection = widget.c.collection;
+ var cover = _defaultCover;
+ if (collection.hasCover) {
+ try {
+ cover =
+ await FilesDB.instance.getUploadedFile(
+ collection.pubMagicMetadata.coverID!,
+ collection.id,
+ ) ??
+ _defaultCover;
+ } catch (e, s) {
+ _logger.warning("Failed to load album cover", e, s);
+ }
+ }
+ if (mounted && generation == _coverLoadGeneration) {
setState(() => _cover = cover);
}
}
@@ -118,6 +138,7 @@ class _CollectionPageState extends State<CollectionPage> {
final gallery = Gallery(
appBar: appBar,
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {
+ final generation = ++_galleryLoadGeneration;
final FileLoadResult result = await FilesDB.instance
.getFilesInCollection(
c.collection.id,
@@ -133,6 +154,12 @@ class _CollectionPageState extends State<CollectionPage> {
f.uploadedFileID == null &&
IgnoredFilesService.instance.shouldSkipUpload(ignoredIDs, f),
);
+ if (mounted &&
+ generation == _galleryLoadGeneration &&
+ asc == (c.collection.pubMagicMetadata.asc ?? false)) {
+ _defaultCover = result.files.firstOrNull;
+ await _loadCover();
+ }
return result;
},
reloadEvent: Bus.instance.on<CollectionUpdatedEvent>().where(
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart
index 0efce913c2..d960bdb7be 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/album_cover_app_bar.dart
@@ -1,7 +1,7 @@
import "dart:math" as math;
+import "dart:ui" as ui;
import "package:ente_components/ente_components.dart";
-import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
import "package:flutter/rendering.dart";
import "package:flutter/services.dart";
@@ -11,10 +11,9 @@ import "package:photos/core/constants.dart";
import "package:photos/core/page_route_observer.dart";
import "package:photos/models/collection/collection.dart";
import "package:photos/models/file/file.dart";
-import "package:photos/services/collections_service.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
-// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=25285-293816&m=dev
class AlbumCoverAppBar extends StatefulWidget {
const AlbumCoverAppBar({
super.key,
@@ -71,8 +70,6 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {
}
}
- // The page below stays painted, so its style region would keep applying
- // the cover's light style to the page above it.
@override
void didPushNext() {
setState(() => _isCovered = true);
@@ -86,7 +83,6 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {
@override
void dispose() {
pageRouteObserver.unsubscribe(this);
- // Pages without their own overlay style would keep the cover's light one.
SystemChrome.setSystemUIOverlayStyle(_pinnedOverlayStyle);
WidgetsBinding.instance.scheduleFrame();
super.dispose();
@@ -122,74 +118,49 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {
),
content: SizedBox(
width: MediaQuery.sizeOf(context).width - Spacing.lg * 2,
- child: Stack(
- clipBehavior: Clip.none,
- alignment: Alignment.center,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
children: [
- const Positioned(
- left: -_contentScrimOutset,
- right: -_contentScrimOutset,
- top: -_contentScrimOutset,
- bottom: -_contentScrimOutset,
- child: IgnorePointer(
- child: FittedBox(
- fit: BoxFit.fill,
- child: SizedBox.square(
- dimension: 1,
- child: DecoratedBox(
- decoration: BoxDecoration(
- gradient: RadialGradient(
- colors: [_scrimColor, _transparentScrimColor],
- ),
- ),
- ),
- ),
+ _CoverCaption(
+ GalleryFilesState.maybeOf(context)?.galleryFilesOrNull,
+ ),
+ Semantics(
+ header: true,
+ child: Text(
+ widget.title,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: TextStyles.display1.copyWith(
+ color: colors.specialWhite,
),
),
),
- Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- _CoverCaption(widget.collection),
- Semantics(
- header: true,
- child: Text(
- widget.title,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- style: TextStyles.display1.copyWith(
- color: colors.specialWhite,
- ),
- ),
+ if (description != null) ...[
+ const SizedBox(height: Spacing.sm),
+ Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: _descriptionHorizontalInset,
),
- if (description != null) ...[
- const SizedBox(height: Spacing.sm),
- Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: Spacing.lg,
- ),
- child: Text(
- description,
- maxLines: _descriptionMaxLines,
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- style: TextStyles.mini.copyWith(
- color: colors.specialWhite.withValues(alpha: 0.92),
- ),
- ),
- ),
- ],
- if (widget.coverActions.isNotEmpty) ...[
- const SizedBox(height: Spacing.md),
- Row(
- mainAxisSize: MainAxisSize.min,
- spacing: Spacing.md,
- children: widget.coverActions,
+ child: Text(
+ description,
+ maxLines: _descriptionMaxLines,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: TextStyles.mini.copyWith(
+ color: colors.specialWhite.withValues(alpha: 0.92),
),
- ],
- ],
- ),
+ ),
+ ),
+ ],
+ if (widget.coverActions.isNotEmpty) ...[
+ const SizedBox(height: _contentSpacing),
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ spacing: Spacing.md,
+ children: widget.coverActions,
+ ),
+ ],
],
),
),
@@ -260,23 +231,32 @@ class _CoverPhoto extends StatelessWidget {
useRequestedThumbnailSizeForLocalCache: true,
),
const ColoredBox(color: _photoScrimColor),
- // Overshoots the photo so its antialiased edge cannot show through.
Positioned(
left: 0,
right: 0,
- bottom: -_coverDissolveOvershoot,
- height: _coverDissolveHeight + _coverDissolveOvershoot,
- child: DecoratedBox(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [backgroundColor.withValues(alpha: 0), backgroundColor],
- stops: const [
- 0,
- _coverDissolveHeight /
- (_coverDissolveHeight + _coverDissolveOvershoot),
- ],
+ bottom: 0,
+ height: _coverDissolveHeight,
+ child: CustomPaint(painter: _CoverDissolvePainter(backgroundColor)),
+ ),
+ Positioned(
+ top:
+ MediaQuery.paddingOf(context).top +
+ _contentScrimTop -
+ _contentScrimBlur * 2,
+ left:
+ (MediaQuery.sizeOf(context).width - _contentScrimWidth) / 2 -
+ 0.5 -
+ _contentScrimBlur * 2,
+ width: _contentScrimWidth + _contentScrimBlur * 4,
+ height: _contentScrimHeight + _contentScrimBlur * 4,
+ child: IgnorePointer(
+ child: ClipRect(
+ child: ImageFiltered(
+ imageFilter: ui.ImageFilter.blur(
+ sigmaX: _contentScrimBlur,
+ sigmaY: _contentScrimBlur,
+ ),
+ child: const CustomPaint(painter: _CoverContentScrimPainter()),
),
),
),
@@ -286,62 +266,163 @@ class _CoverPhoto extends StatelessWidget {
}
}
-class _CoverCaption extends StatelessWidget {
- const _CoverCaption(this.collection);
+class _CoverContentScrimPainter extends CustomPainter {
+ const _CoverContentScrimPainter();
- final Collection collection;
+ @override
+ void paint(Canvas canvas, Size size) {
+ canvas.save();
+ canvas.translate(size.width / 2, size.height / 2);
+ canvas.scale(_contentScrimWidth / 2, _contentScrimHeight / 2);
+ canvas.drawCircle(
+ Offset.zero,
+ 1,
+ Paint()
+ ..shader = ui.Gradient.radial(Offset.zero, 1, const [
+ Color.from(
+ alpha: 0.24,
+ red: 0.0585186,
+ green: 0.0585186,
+ blue: 0.0585186,
+ ),
+ Color.from(
+ alpha: 0.096,
+ red: 0.0224357,
+ green: 0.0224357,
+ blue: 0.0224357,
+ ),
+ ]),
+ );
+ canvas.restore();
+ }
+
+ @override
+ bool shouldRepaint(_CoverContentScrimPainter oldDelegate) => false;
+}
+
+class _CoverDissolvePainter extends CustomPainter {
+ const _CoverDissolvePainter(this.backgroundColor);
+
+ final Color backgroundColor;
- Future<({int count, int? newestFileTime})> _loadSummary() async {
- final collectionsService = CollectionsService.instance;
- final count = await collectionsService.getFileCount(collection);
- final newestFileTimes = await collectionsService
- .getCollectionIDToNewestFileTime();
- return (count: count, newestFileTime: newestFileTimes[collection.id]);
+ @override
+ void paint(Canvas canvas, Size size) {
+ final direction = Offset(
+ 0.0221519917 / size.width,
+ 0.9999704361 / size.height,
+ );
+ final center = size.center(Offset.zero);
+ const centerPosition = 0.0221519917 / 2 + 0.9999704361 / 2 - 0.0110464599;
+ final vector = direction / direction.distanceSquared;
+ canvas.drawRect(
+ Offset.zero & size,
+ Paint()
+ ..shader = ui.Gradient.linear(
+ center - vector * centerPosition,
+ center + vector * (1 - centerPosition),
+ [backgroundColor.withValues(alpha: 0), backgroundColor],
+ ),
+ );
}
+ @override
+ bool shouldRepaint(_CoverDissolvePainter oldDelegate) =>
+ oldDelegate.backgroundColor != backgroundColor;
+}
+
+class _CoverCaption extends StatelessWidget {
+ const _CoverCaption(this.files);
+
+ final List<EnteFile>? files;
+
@override
Widget build(BuildContext context) {
- return FutureBuilder(
- future: _loadSummary(),
- builder: (context, snapshot) {
- final summary = snapshot.data;
- if (summary == null) {
- return const SizedBox.shrink();
- }
-
- final newestFileTime = summary.newestFileTime;
- final caption = [
- context.strings.memoryCount(
- count: summary.count,
- formattedCount: NumberFormat().format(summary.count),
- ),
- if (newestFileTime != null)
- DateFormat.yMMM(
- Localizations.localeOf(context).languageCode,
- ).format(DateTime.fromMicrosecondsSinceEpoch(newestFileTime)),
- ].join(" Β· ");
+ final files = this.files;
+ if (files == null) {
+ return const SizedBox.shrink();
+ }
+ int? oldestFileTime;
+ int? newestFileTime;
+ for (final file in files) {
+ final creationTime = file.creationTime;
+ if (creationTime != null && creationTime != 0) {
+ oldestFileTime = math.min(oldestFileTime ?? creationTime, creationTime);
+ newestFileTime = math.max(newestFileTime ?? creationTime, creationTime);
+ }
+ }
+ if (oldestFileTime == null || newestFileTime == null) {
+ return const SizedBox.shrink();
+ }
+ final start = DateTime.fromMicrosecondsSinceEpoch(oldestFileTime);
+ final end = DateTime.fromMicrosecondsSinceEpoch(newestFileTime);
+ final locale = Localizations.localeOf(context).toString();
+ final dayPattern = locale == "en"
+ ? "d MMM y"
+ : DateFormat.yMMMd(locale).pattern!;
+ final monthDayPattern = locale == "en"
+ ? "d MMM"
+ : DateFormat.MMMd(locale).pattern!;
+ final yearRange =
+ "${DateFormat.y(locale).format(start)} – ${DateFormat.y(locale).format(end)}";
+ final monthRange = start.year == end.year
+ ? start.month == end.month
+ ? DateFormat.yMMM(locale).format(end)
+ : "${DateFormat.MMM(locale).format(start)} – ${DateFormat.yMMM(locale).format(end)}"
+ : "${DateFormat.yMMM(locale).format(start)} – ${DateFormat.yMMM(locale).format(end)}";
+ final String dayRange;
+ if (start.year != end.year) {
+ dayRange =
+ "${DateFormat(dayPattern, locale).format(start)} – ${DateFormat(dayPattern, locale).format(end)}";
+ } else if (start.month != end.month) {
+ dayRange =
+ "${DateFormat(monthDayPattern, locale).format(start)} – ${DateFormat(dayPattern, locale).format(end)}";
+ } else if (start.day != end.day) {
+ final days =
+ "${NumberFormat("0", locale).format(start.day)}–${NumberFormat("0", locale).format(end.day)}";
+ dayRange = DateFormat(
+ dayPattern.replaceAllMapped(
+ RegExp("('(?:[^']|'')*')|d+"),
+ (match) => match.group(1) ?? "'$days'",
+ ),
+ locale,
+ ).format(end);
+ } else {
+ dayRange = DateFormat(dayPattern, locale).format(end);
+ }
+ final captions = end.year - start.year >= 2
+ ? [yearRange]
+ : [dayRange, monthRange, yearRange];
+ final style = TextStyles.tiny.copyWith(
+ color: context.componentColors.specialWhite.withValues(alpha: 0.82),
+ );
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final caption = captions.firstWhere((caption) {
+ final painter = TextPainter(
+ text: TextSpan(text: caption.toUpperCase(), style: style),
+ textDirection: Directionality.of(context),
+ textScaler: MediaQuery.textScalerOf(context),
+ maxLines: 1,
+ )..layout();
+ final fits = painter.width <= constraints.maxWidth - Spacing.md * 2;
+ painter.dispose();
+ return fits;
+ }, orElse: () => captions.last);
return Padding(
- padding: const EdgeInsets.only(bottom: Spacing.md),
- child: DecoratedBox(
- decoration: const ShapeDecoration(
- color: _captionFillColor,
- shape: StadiumBorder(),
- ),
- child: Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: Spacing.md,
- vertical: Spacing.sm,
+ padding: const EdgeInsets.only(bottom: _contentSpacing),
+ child: Center(
+ child: DecoratedBox(
+ decoration: const ShapeDecoration(
+ color: _captionFillColor,
+ shape: StadiumBorder(),
),
- child: Text(
- caption.toUpperCase(),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: TextStyles.tiny.copyWith(
- color: context.componentColors.specialWhite.withValues(
- alpha: 0.82,
- ),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: Spacing.md,
+ vertical: Spacing.sm,
),
+ child: Text(caption.toUpperCase(), maxLines: 1, style: style),
),
),
),
@@ -428,7 +509,7 @@ class _AlbumCoverDelegate extends SliverPersistentHeaderDelegate {
top: -collapseOffset,
left: 0,
right: 0,
- bottom: coverBottomInset,
+ bottom: coverBottomInset - 1,
child: photo,
),
Positioned(
@@ -470,12 +551,15 @@ class _AlbumCoverDelegate extends SliverPersistentHeaderDelegate {
),
),
Positioned(
- top: topPadding,
+ top:
+ topPadding +
+ (Spacing.lg - (collapsedHeight - _headerIconSize) / 2) *
+ (1 - pinnedProgress),
left: Spacing.lg,
right: Spacing.lg,
height: collapsedHeight,
child: Row(
- spacing: Spacing.sm,
+ spacing: Spacing.md,
children: [
IconButtonComponent(
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
@@ -503,7 +587,11 @@ class _AlbumCoverDelegate extends SliverPersistentHeaderDelegate {
),
),
),
- ...actionsBuilder(foregroundColor),
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ spacing: _headerActionSpacing,
+ children: actionsBuilder(foregroundColor),
+ ),
],
),
),
@@ -530,23 +618,29 @@ double _coverBottomInset(double bottomHeight) {
const _coverHeight = 441.0;
const _coverDissolveHeight = 100.0;
-const _coverDissolveOvershoot = 1.0;
const _topScrimHeight = 31.0;
const _bottomOverlap = 25.0;
-const _contentBottomGap = 108.0;
-const _contentScrimOutset = 56.0;
+const _contentBottomGap = 107.0;
+const _contentSpacing = 22.0;
+const _contentScrimTop = 146.0;
+const _contentScrimWidth = 308.0;
+const _contentScrimHeight = 157.0;
+const _contentScrimBlur = 54.25;
+const _headerIconSize = 38.0;
+const _headerActionSpacing = 6.0;
const _contentFadeExtent = 120.0;
const _pinnedFadeStart = 0.6;
const _foregroundSwitchStart = 0.4;
const _foregroundSwitchEnd = 0.6;
const _descriptionMaxLines = 3;
+const _descriptionHorizontalInset = 18.0;
const _coverActionSize = 42.0;
const _coverActionIconSize = 17.0;
-const _photoScrimColor = Color(0x3D000000);
+const _photoScrimColor = Color.from(alpha: 0.24, red: 0, green: 0, blue: 0);
const _scrimColor = Color(0x33000000);
const _transparentScrimColor = Color(0x00000000);
-const _captionFillColor = Color(0x52000000);
+const _captionFillColor = Color.from(alpha: 0.32, red: 0, green: 0, blue: 0);
const _coverActionFillColor = Color(0x66000000);
const _coverOverlayStyle = SystemUiOverlayStyle(
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart
index b18b0b2994..61ffc1a03c 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart
@@ -1,8 +1,6 @@
import "package:ente_components/ente_components.dart";
import "package:flutter/material.dart";
-import "package:photos/ui/components/bottom_action_bar/selection_action_button_widget.dart";
-// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=25316-7380&m=dev
Future<T?> showAlbumActionsSheet<T>(
BuildContext context,
List<EntePopupMenuOption<T>> options,
@@ -20,72 +18,135 @@ Future<T?> showAlbumActionsSheet<T>(
return showBottomSheetComponent<T>(
context: context,
+ barrierColor: context.componentColors.specialScrim.withValues(alpha: 0.4),
builder: (context) {
final colors = context.componentColors;
- return BottomSheetComponent(
- showCloseButton: false,
- backgroundColor: colors.fillLight,
- padding: const EdgeInsets.only(top: Spacing.lg, bottom: Spacing.sm),
- content: ConstrainedBox(
+ return DecoratedBox(
+ decoration: const BoxDecoration(
+ borderRadius: BorderRadius.vertical(
+ top: Radius.circular(Radii.bottomSheet),
+ ),
+ boxShadow: [
+ BoxShadow(
+ color: Color.from(alpha: 0.18, red: 0, green: 0, blue: 0),
+ offset: Offset(0, -2),
+ blurRadius: 80,
+ ),
+ ],
+ ),
+ child: BottomSheetComponent(
+ showCloseButton: false,
+ backgroundColor: colors.fillLight,
+ padding: const EdgeInsets.only(top: Spacing.lg, bottom: Spacing.sm),
+ content: ConstrainedBox(
+ constraints: BoxConstraints(
+ maxHeight: MediaQuery.sizeOf(context).height * _maxHeightFraction,
+ ),
+ child: SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Container(
+ width: 36,
+ height: 5,
+ decoration: BoxDecoration(
+ color: colors.textLightest,
+ borderRadius: BorderRadius.circular(3),
+ ),
+ ),
+ const SizedBox(height: Spacing.xxl),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.md),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ spacing: Spacing.xs,
+ children: [
+ for (final option in tiles)
+ Expanded(
+ child: _AlbumActionTile(
+ option: option,
+ onTap: () =>
+ Navigator.of(context).pop(option.value),
+ ),
+ ),
+ ],
+ ),
+ ),
+ if (rows.isNotEmpty)
+ const DividerComponent(
+ padding: EdgeInsets.fromLTRB(
+ Spacing.lg,
+ Spacing.lg,
+ Spacing.lg,
+ Spacing.xl,
+ ),
+ ),
+ for (final option in rows)
+ _AlbumActionRow(
+ option: option,
+ onTap: () => Navigator.of(context).pop(option.value),
+ ),
+ const SizedBox(height: Spacing.lg),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ },
+ );
+}
+
+class _AlbumActionTile<T> extends StatelessWidget {
+ const _AlbumActionTile({required this.option, required this.onTap});
+
+ final EntePopupMenuOption<T> option;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ final foreground = option.labelColor ?? colors.textLight;
+ return Semantics(
+ button: true,
+ child: InkWell(
+ onTap: onTap,
+ borderRadius: BorderRadius.circular(Radii.md),
+ child: ConstrainedBox(
constraints: BoxConstraints(
- maxHeight: MediaQuery.sizeOf(context).height * _maxHeightFraction,
+ minHeight: option.labelColor == null ? 0 : 64,
),
- child: SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: Spacing.xs),
child: Column(
mainAxisSize: MainAxisSize.min,
+ mainAxisAlignment: MainAxisAlignment.center,
children: [
- Container(
- width: 36,
- height: 5,
- decoration: BoxDecoration(
- color: colors.textLightest,
- borderRadius: BorderRadius.circular(3),
+ SizedBox.square(
+ dimension: 34,
+ child: Center(
+ child: IconTheme.merge(
+ data: IconThemeData(
+ color: foreground,
+ size: IconSizes.small,
+ ),
+ child: option.leadingWidget ?? const SizedBox.shrink(),
+ ),
),
),
- const SizedBox(height: Spacing.xxl),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: Spacing.md),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- spacing: Spacing.xs,
- children: [
- for (final option in tiles)
- Expanded(
- child: SelectionActionButton(
- labelText: option.label,
- iconWidget:
- option.leadingWidget ?? const SizedBox.shrink(),
- isCritical: option.labelColor != null,
- color: colors.textLight,
- onTap: () =>
- Navigator.of(context).pop(option.value),
- ),
- ),
- ],
- ),
+ const SizedBox(height: Spacing.xs),
+ Text(
+ option.label,
+ textAlign: TextAlign.center,
+ style: TextStyles.mini.copyWith(color: foreground),
),
- if (rows.isNotEmpty)
- const DividerComponent(
- padding: EdgeInsets.fromLTRB(
- Spacing.lg,
- Spacing.lg,
- Spacing.lg,
- Spacing.xl,
- ),
- ),
- for (final option in rows)
- _AlbumActionRow(
- option: option,
- onTap: () => Navigator.of(context).pop(option.value),
- ),
- const SizedBox(height: Spacing.lg),
],
),
),
),
- );
- },
- );
+ ),
+ );
+ }
}
class _AlbumActionRow<T> extends StatelessWidget {
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart
index b2a8048cf2..beaee38188 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart
@@ -3,7 +3,6 @@ import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
import "package:flutter_test/flutter_test.dart";
import "package:photos/ente_theme_data.dart";
-import "package:photos/ui/components/bottom_action_bar/selection_action_button_widget.dart";
import "package:photos/ui/viewer/gallery/hooks/album_actions_sheet.dart";
void main() {
@@ -14,10 +13,24 @@ void main() {
await _pumpLauncher(tester, (_) {});
await _openLauncher(tester);
- final tileLabels = tester
- .widgetList<SelectionActionButton>(find.byType(SelectionActionButton))
- .map((tile) => tile.labelText);
- expect(tileLabels, ["Edit", "Pin", "Archive", "Delete"]);
+ final tilePositions = [
+ "Edit",
+ "Pin",
+ "Archive",
+ "Delete",
+ ].map((label) => tester.getTopLeft(find.text(label))).toList();
+ expect(
+ tilePositions.map((position) => position.dx),
+ orderedEquals(
+ [...tilePositions.map((position) => position.dx)]..sort(),
+ ),
+ );
+ expect(
+ tilePositions.every(
+ (position) => position.dy < tester.getTopLeft(find.text("Hide")).dy,
+ ),
+ isTrue,
+ );
expect(find.text("Hide"), findsOneWidget);
expect(find.text("Cast"), findsOneWidget);
});
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart
index 8566c3dffa..3b76937c91 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/album_cover_app_bar_test.dart
@@ -5,6 +5,8 @@ import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_test/flutter_test.dart";
+import "package:flutter_localizations/flutter_localizations.dart";
+import "package:intl/date_symbol_data_local.dart";
import "package:photos/core/cache/thumbnail_in_memory_cache.dart";
import "package:photos/core/page_route_observer.dart";
import "package:photos/ente_theme_data.dart";
@@ -12,6 +14,7 @@ import "package:photos/models/api/collection/user.dart";
import "package:photos/models/collection/collection.dart";
import "package:photos/models/file/file.dart";
import "package:photos/ui/viewer/gallery/component/album_cover_app_bar.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
void main() {
testWidgets("resets the status bar style only when a page covers it", (
@@ -102,6 +105,103 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump(const Duration(seconds: 1));
});
+ testWidgets(
+ "shows a sort-independent date range and hides undated captions",
+ (tester) async {
+ await initializeDateFormatting();
+ final cover = EnteFile()
+ ..uploadedFileID = 2
+ ..generatedID = 2;
+ ThumbnailInMemoryLruCache.put(cover, base64Decode(_onePixelPng));
+ final cases = <(DateTime?, DateTime?, String?, String)>[
+ (DateTime(2021, 6, 24), DateTime(2021, 6, 24), "24 JUN 2021", "en"),
+ (DateTime(2024, 6, 2), DateTime(2024, 6, 18), "2–18 JUN 2024", "en"),
+ (
+ DateTime(2024, 1, 2),
+ DateTime(2024, 6, 18),
+ "2 JAN – 18 JUN 2024",
+ "en",
+ ),
+ (
+ DateTime(2023, 12, 28),
+ DateTime(2024, 1, 3),
+ "28 DEC 2023 – 3 JAN 2024",
+ "en",
+ ),
+ (DateTime(2019, 1, 1), DateTime(2024, 1, 1), "2019 – 2024", "en"),
+ (null, DateTime(2030, 1, 1), "1 JAN 2030", "en"),
+ (null, null, null, "en"),
+ (DateTime.fromMicrosecondsSinceEpoch(0), null, null, "en"),
+ (
+ DateTime(2024, 6, 2),
+ DateTime(2024, 6, 18),
+ "2–18 DE JUN. DE 2024",
+ "pt",
+ ),
+ (DateTime(2024, 6, 2), DateTime(2024, 6, 18), "2024εΉ΄6月2–18ζ—₯", "zh"),
+ ];
+ for (final (start, end, caption, language) in cases) {
+ final files = [
+ EnteFile()..creationTime = end?.microsecondsSinceEpoch,
+ EnteFile()..creationTime = start?.microsecondsSinceEpoch,
+ ];
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ locale: Locale(language),
+ supportedLocales: const [Locale("en"), Locale("pt"), Locale("zh")],
+ localizationsDelegates: GlobalMaterialLocalizations.delegates,
+ home: GalleryFilesState(
+ child: Scaffold(
+ body: CustomScrollView(
+ slivers: [
+ AlbumCoverAppBar(
+ collection: Collection(
+ 1,
+ User(id: 1, email: "[email protected]"),
+ "",
+ null,
+ "Album",
+ null,
+ null,
+ CollectionType.album,
+ CollectionAttributes(),
+ [],
+ [],
+ 0,
+ ),
+ cover: cover,
+ title: "Album",
+ backgroundColor: Colors.white,
+ collapsedHeight: kToolbarHeight,
+ actionsBuilder: (_) => const [],
+ coverActions: const [],
+ ),
+ ],
+ ),
+ ),
+ )..setGalleryFiles = files,
+ ),
+ );
+ await tester.pump();
+ if (caption == null) {
+ expect(find.textContaining(RegExp(r"\d")), findsNothing);
+ } else {
+ expect(
+ find.text(caption),
+ findsOneWidget,
+ reason: tester
+ .widgetList<Text>(find.byType(Text))
+ .map((w) => w.data)
+ .join(" | "),
+ );
+ }
+ expect(tester.takeException(), isNull);
+ }
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(seconds: 1));
+ },
+ );
}
const _onePixelPng =
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
new file mode 100644
index 0000000000..42730e69e5
--- /dev/null
+++ b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
@@ -0,0 +1,262 @@
+import "dart:convert";
+import "dart:io";
+
+import "package:dio/dio.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/material.dart";
+import "package:flutter_test/flutter_test.dart";
+import "package:package_info_plus/package_info_plus.dart";
+import "package:path_provider_platform_interface/path_provider_platform_interface.dart";
+import "package:photos/core/cache/thumbnail_in_memory_cache.dart";
+import "package:photos/core/configuration.dart";
+import "package:photos/core/constants.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/db/files_db.dart";
+import "package:photos/ente_theme_data.dart";
+import "package:photos/events/collection_meta_event.dart";
+import "package:photos/events/collection_updated_event.dart";
+import "package:photos/models/api/collection/user.dart";
+import "package:photos/models/collection/collection.dart";
+import "package:photos/models/collection/collection_items.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/file/file_type.dart";
+import "package:photos/models/ignored_file.dart";
+import "package:photos/models/metadata/collection_magic.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/services/collections_service.dart";
+import "package:photos/services/favorites_service.dart";
+import "package:photos/services/ignored_files_service.dart";
+import "package:photos/ui/viewer/gallery/collection_page.dart";
+import "package:photos/ui/viewer/gallery/component/album_cover_app_bar.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
+import "package:shared_preferences/shared_preferences.dart";
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+ late Directory tempDir;
+ late PathProviderPlatform previousPathProvider;
+
+ setUpAll(() async {
+ tempDir = await Directory.systemTemp.createTemp("collection_page_cover_");
+ previousPathProvider = PathProviderPlatform.instance;
+ PathProviderPlatform.instance = _FakePathProvider(tempDir.path);
+ SharedPreferences.setMockInitialValues({});
+ final preferences = await SharedPreferences.getInstance();
+ ServiceLocator.instance.init(
+ preferences,
+ Dio(),
+ Dio(),
+ Dio(),
+ PackageInfo(
+ appName: "Photos",
+ packageName: "photos",
+ version: "1.0.0",
+ buildNumber: "1",
+ ),
+ );
+ try {
+ await Configuration.instance.init(preferences);
+ } catch (_) {}
+ await Configuration.instance.setUserID(1);
+ await CollectionsService.instance.init(preferences);
+ await FavoritesService.instance.initFav();
+ expect(flagService.internalUser, isTrue);
+ });
+
+ setUp(() async {
+ await FilesDB.instance.clearTable();
+ await IgnoredFilesService.instance.reset();
+ });
+
+ tearDownAll(() async {
+ PathProviderPlatform.instance = previousPathProvider;
+ await tempDir.delete(recursive: true);
+ });
+
+ testWidgets("uses a pending local photo and excludes ignored photos", (
+ tester,
+ ) async {
+ final collection = _collection();
+ final files = List.generate(
+ 101,
+ (index) => _file(index + 1, uploaded: false),
+ );
+ final cover = files[99];
+ final ignored = files.last;
+ await tester.runAsync(() async {
+ await FilesDB.instance.insertMultiple(files);
+ await IgnoredFilesService.instance.cacheAndInsert([
+ IgnoredFile(
+ ignored.localID,
+ ignored.title,
+ ignored.deviceFolder,
+ "ignored",
+ ),
+ ]);
+ });
+
+ await _pumpAlbum(tester, collection);
+ await _expectCover(tester, cover, count: 100);
+ expect(find.text("1 JAN – 10 APR 2026"), findsOneWidget);
+ await _disposeAlbum(tester);
+ });
+
+ testWidgets(
+ "refreshes sorted covers and preserves an explicitly selected cover",
+ (tester) async {
+ final collection = _collection();
+ final oldest = _file(1);
+ final newest = _file(3);
+ await tester.runAsync(() async {
+ await FilesDB.instance.insertMultiple([oldest, newest]);
+ expect(await CollectionsService.instance.getCover(collection), newest);
+ });
+ await _pumpAlbum(tester, collection);
+ await _expectCover(tester, newest, count: 2);
+
+ collection.pubMagicMetadata = CollectionPubMagicMetadata(asc: true);
+ Bus.instance.fire(
+ CollectionMetaEvent(collection.id, CollectionMetaEventType.sortChanged),
+ );
+ await _expectCover(tester, oldest, count: 2);
+ expect(find.text("1–3 JAN 2026"), findsOneWidget);
+
+ final middle = _file(2);
+ await tester.runAsync(() => FilesDB.instance.insertMultiple([middle]));
+ Bus.instance.fire(
+ CollectionUpdatedEvent(collection.id, [middle], "added"),
+ );
+ await _expectCover(tester, oldest, count: 3);
+
+ collection.pubMagicMetadata = CollectionPubMagicMetadata(
+ asc: true,
+ coverID: 3,
+ );
+ Bus.instance.fire(
+ CollectionUpdatedEvent(collection.id, [], "cover_change"),
+ );
+ await _expectCover(tester, newest);
+
+ collection.pubMagicMetadata = CollectionPubMagicMetadata(asc: true);
+ Bus.instance.fire(
+ CollectionUpdatedEvent(collection.id, [], "cover_change"),
+ );
+ await _expectCover(tester, oldest);
+
+ await tester.runAsync(
+ () => FilesDB.instance.deleteCollection(collection.id),
+ );
+ Bus.instance.fire(CollectionUpdatedEvent(collection.id, [], "removed"));
+ await _expectCover(tester, null);
+ await _disposeAlbum(tester);
+ },
+ );
+}
+
+Collection _collection() => Collection(
+ 1,
+ User(id: 1, email: "[email protected]"),
+ "",
+ null,
+ "Album",
+ null,
+ null,
+ CollectionType.album,
+ CollectionAttributes(),
+ [],
+ [],
+ 0,
+);
+
+EnteFile _file(int id, {bool uploaded = true}) {
+ final file = EnteFile()
+ ..generatedID = id
+ ..uploadedFileID = uploaded ? id : null
+ ..ownerID = 1
+ ..collectionID = 1
+ ..localID = "local-$id"
+ ..title = "$id.jpg"
+ ..deviceFolder = "Camera"
+ ..fileType = FileType.image
+ ..creationTime = DateTime(2026, 1, id).microsecondsSinceEpoch
+ ..modificationTime = DateTime(2026, 1, id).microsecondsSinceEpoch;
+ final bytes = base64Decode(_onePixelPng);
+ ThumbnailInMemoryLruCache.put(file, bytes, thumbnailSmallSize);
+ ThumbnailInMemoryLruCache.put(file, bytes, thumbnailLargeSize);
+ return file;
+}
+
+Future<void> _pumpAlbum(WidgetTester tester, Collection collection) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: CollectionPage(CollectionWithThumbnail(collection, null)),
+ ),
+ );
+}
+
+Future<void> _expectCover(
+ WidgetTester tester,
+ EnteFile? file, {
+ int? count,
+}) async {
+ await tester.runAsync(() async {
+ for (var i = 0; i < 100; i++) {
+ await tester.pump(const Duration(milliseconds: 100));
+ final covers = tester.widgetList<AlbumCoverAppBar>(
+ find.byType(AlbumCoverAppBar),
+ );
+ final hasExpectedCover = file == null
+ ? covers.isEmpty
+ : covers.singleOrNull?.cover == file;
+ final hasExpectedCount =
+ count == null ||
+ tester
+ .widget<GalleryFilesState>(find.byType(GalleryFilesState))
+ .galleryFilesOrNull
+ ?.length ==
+ count;
+ if (hasExpectedCover && hasExpectedCount) {
+ await tester.pump(const Duration(seconds: 1));
+ return;
+ }
+ await Future<void>.delayed(const Duration(milliseconds: 10));
+ }
+ });
+ final covers = tester.widgetList<AlbumCoverAppBar>(
+ find.byType(AlbumCoverAppBar),
+ );
+ expect(covers.map((cover) => cover.cover), file == null ? isEmpty : [file]);
+ if (count != null) {
+ expect(
+ tester
+ .widget<GalleryFilesState>(find.byType(GalleryFilesState))
+ .galleryFilesOrNull
+ ?.length,
+ count,
+ );
+ }
+ expect(tester.takeException(), isNull);
+}
+
+Future<void> _disposeAlbum(WidgetTester tester) async {
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(seconds: 1));
+}
+
+class _FakePathProvider extends PathProviderPlatform {
+ _FakePathProvider(this.path);
+
+ final String path;
+
+ @override
+ Future<String?> getApplicationDocumentsPath() async => path;
+
+ @override
+ Future<String?> getApplicationSupportPath() async => path;
+}
+
+const _onePixelPng =
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";