Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Support custom images and actions in album covers

r4khul3515310e2a51
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 f3230a8d8d..208009882d 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
@@ -23,7 +23,8 @@ class AlbumCoverAppBar extends StatefulWidget {
const AlbumCoverAppBar({
super.key,
this.collection,
- required this.cover,
+ this.cover,
+ this.coverWidget,
this.subtitle,
required this.title,
required this.actionsBuilder,
@@ -32,10 +33,11 @@ class AlbumCoverAppBar extends StatefulWidget {
required this.collapsedHeight,
this.heroTag,
this.bottom,
- });
+ }) : assert(cover != null || coverWidget != null);
final Collection? collection;
- final EnteFile cover;
+ final EnteFile? cover;
+ final Widget? coverWidget;
final String? subtitle;
final String title;
final List<Widget> Function(Color foregroundColor) actionsBuilder;
@@ -135,6 +137,7 @@ class _AlbumCoverAppBarState extends State<AlbumCoverAppBar> with RouteAware {
collapseOffset: collapseOffset,
imageBottomInset: _coverBottomInset(bottomHeight) - 1,
cover: widget.cover,
+ coverWidget: widget.coverWidget,
backgroundColor: widget.backgroundColor,
heroTag: widget.heroTag,
),
@@ -255,6 +258,7 @@ class _CoverPhoto extends StatelessWidget {
required this.collapseOffset,
required this.imageBottomInset,
required this.cover,
+ required this.coverWidget,
required this.backgroundColor,
this.heroTag,
});
@@ -264,7 +268,8 @@ class _CoverPhoto extends StatelessWidget {
final _CoverForegroundNotifier foregroundNotifier;
final double collapseOffset;
final double imageBottomInset;
- final EnteFile cover;
+ final EnteFile? cover;
+ final Widget? coverWidget;
final Color backgroundColor;
final String? heroTag;
@@ -279,13 +284,15 @@ class _CoverPhoto extends StatelessWidget {
),
);
foregroundNotifier.update(contextualForeground, context);
- final thumbnail = ThumbnailWidget(
- cover,
- rawThumbnail: true,
- thumbnailSize: thumbnailLargeSize,
- useRequestedThumbnailSizeForLocalCache: true,
- useCachedThumbnailAsPlaceholder: true,
- );
+ final thumbnail =
+ coverWidget ??
+ ThumbnailWidget(
+ cover!,
+ rawThumbnail: true,
+ thumbnailSize: thumbnailLargeSize,
+ useRequestedThumbnailSizeForLocalCache: true,
+ useCachedThumbnailAsPlaceholder: true,
+ );
final background = Stack(
key: photoKey,
fit: StackFit.expand,
@@ -345,9 +352,16 @@ class _CoverPhoto extends StatelessWidget {
card = card.child!;
}
final SmoothBorderRadius cardRadius;
+ BorderRadius? cardSuperellipseRadius;
if (card is ClipSmoothRect) {
cardRadius = card.radius;
card = card.child;
+ } else if (card is ClipRSuperellipse) {
+ cardSuperellipseRadius = card.borderRadius.resolve(
+ Directionality.of(cardContext),
+ );
+ cardRadius = SmoothBorderRadius.zero;
+ card = card.child!;
} else if (card is ClipRRect) {
final radius = card.borderRadius.resolve(
Directionality.of(cardContext),
@@ -386,8 +400,9 @@ class _CoverPhoto extends StatelessWidget {
coverSize: (coverContext.findRenderObject()! as RenderBox).size,
imageBottomInset: imageBottomInset,
card: card,
- showVideoIcon: cover.fileType == FileType.video,
+ showVideoIcon: cover?.fileType == FileType.video,
cardRadius: cardRadius,
+ cardSuperellipseRadius: cardSuperellipseRadius,
backgroundColor: backgroundColor,
);
},
@@ -423,6 +438,7 @@ class _CoverHeroFlight extends StatefulWidget {
required this.card,
required this.showVideoIcon,
required this.cardRadius,
+ this.cardSuperellipseRadius,
required this.backgroundColor,
});
@@ -434,6 +450,7 @@ class _CoverHeroFlight extends StatefulWidget {
final Widget card;
final bool showVideoIcon;
final SmoothBorderRadius cardRadius;
+ final BorderRadius? cardSuperellipseRadius;
final Color backgroundColor;
@override
@@ -491,13 +508,8 @@ class _CoverHeroFlightState extends State<_CoverHeroFlight> {
),
],
),
- builder: (context, child) => ClipSmoothRect(
- radius: SmoothBorderRadius.lerp(
- widget.cardRadius,
- SmoothBorderRadius.zero,
- widget.animation.value,
- )!,
- child: Stack(
+ builder: (context, child) {
+ final content = Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
@@ -518,8 +530,26 @@ class _CoverHeroFlightState extends State<_CoverHeroFlight> {
),
foreground,
],
- ),
- ),
+ );
+ if (widget.cardSuperellipseRadius != null) {
+ return ClipRSuperellipse(
+ borderRadius: BorderRadius.lerp(
+ widget.cardSuperellipseRadius,
+ BorderRadius.zero,
+ widget.animation.value,
+ )!,
+ child: content,
+ );
+ }
+ return ClipSmoothRect(
+ radius: SmoothBorderRadius.lerp(
+ widget.cardRadius,
+ SmoothBorderRadius.zero,
+ widget.animation.value,
+ )!,
+ child: content,
+ );
+ },
);
}
}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
index ede0df960b..557487eb06 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -78,6 +78,9 @@ class GalleryAppBarWidget extends StatefulWidget {
Future<void> Function()? onDisableDeviceFolderBackup,
Collection? collection,
EnteFile? cover,
+ Widget? coverWidget,
+ List<Widget> Function({required bool onCover, Color? foregroundColor})?
+ actionsBuilder,
String? coverHeroTag,
Key? coverAppBarKey,
List<EnteFile>? files,
@@ -91,7 +94,8 @@ class GalleryAppBarWidget extends StatefulWidget {
files != null,
);
return GalleryAppBarConfig(
- extendBodyForCollapse: cover != null && bottom == null,
+ extendBodyForCollapse:
+ (cover != null || coverWidget != null) && bottom == null,
sliverBuilder: (_) => GalleryAppBarWidget._(
type,
title,
@@ -102,6 +106,8 @@ class GalleryAppBarWidget extends StatefulWidget {
onDisableDeviceFolderBackup: onDisableDeviceFolderBackup,
collection: collection,
cover: cover,
+ coverWidget: coverWidget,
+ actionsBuilder: actionsBuilder,
coverHeroTag: coverHeroTag,
coverAppBarKey: coverAppBarKey,
files: files,
@@ -113,7 +119,7 @@ class GalleryAppBarWidget extends StatefulWidget {
subtitle: subtitle,
description: collection?.displayDescription,
bottomHeight: bottom?.preferredSize.height,
- hasCover: cover != null,
+ hasCover: cover != null || coverWidget != null,
),
);
}
@@ -181,6 +187,9 @@ class GalleryAppBarWidget extends StatefulWidget {
final Future<void> Function()? onDisableDeviceFolderBackup;
final Collection? collection;
final EnteFile? cover;
+ final Widget? coverWidget;
+ final List<Widget> Function({required bool onCover, Color? foregroundColor})?
+ actionsBuilder;
final String? coverHeroTag;
final Key? coverAppBarKey;
final List<EnteFile>? files;
@@ -197,6 +206,8 @@ class GalleryAppBarWidget extends StatefulWidget {
this.onDisableDeviceFolderBackup,
this.collection,
this.cover,
+ this.coverWidget,
+ this.actionsBuilder,
this.coverHeroTag,
this.coverAppBarKey,
this.files,
@@ -335,7 +346,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
preferredSize: Size.fromHeight(
AppBarFilterChips.preferredHeight(context),
),
- child: AppBarFilterChips(animateRecommendations: widget.cover != null),
+ child: AppBarFilterChips(
+ animateRecommendations:
+ widget.cover != null || widget.coverWidget != null,
+ ),
),
builder: (context, isSearching, child) => _buildHeader(
bottom: child as PreferredSizeWidget,
@@ -346,7 +360,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
Widget _buildHeader({PreferredSizeWidget? bottom, bool isSearching = false}) {
if (GalleryAppBarWidget._usesCoverHeader(
- hasCover: widget.cover != null,
+ hasCover: widget.cover != null || widget.coverWidget != null,
hasCustomBottom: widget.bottom != null,
isSearching: isSearching,
)) {
@@ -373,7 +387,8 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
return AlbumCoverAppBar(
key: widget.coverAppBarKey,
collection: widget.collection,
- cover: widget.cover!,
+ cover: widget.cover,
+ coverWidget: widget.coverWidget,
subtitle: widget.subtitle,
heroTag: widget.coverHeroTag,
title: _appBarTitle,
@@ -583,6 +598,12 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
required bool onCover,
Color? foregroundColor,
}) {
+ if (widget.actionsBuilder != null) {
+ return widget.actionsBuilder!(
+ onCover: onCover,
+ foregroundColor: foregroundColor,
+ );
+ }
final List<Widget> actions = <Widget>[];
final iconButtonVariant = onCover
? IconButtonComponentVariant.unfilled
@@ -1235,7 +1256,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
widget.deviceCollection?.name ??
widget.collection?.displayName ??
_appBarTitle,
- includeBackupExcludedFiles: widget.deviceCollection != null,
+ includeBackupExcludedFiles:
+ widget.deviceCollection != null ||
+ (galleryType == GalleryType.cluster && isLocalGalleryMode),
);
}
@@ -1340,6 +1363,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
if (widget.deviceCollection != null) {
return await _loadAllGalleryFiles() ?? [];
}
+ if (widget.files != null) return widget.files!;
return FilesDB.instance.getAllFilesCollection(
widget.collection!.id,
);