diff --git a/lib/controllers/collapsing_header_scroll_mixin.dart b/lib/controllers/collapsing_header_scroll_mixin.dart index bf3636fc2..5eb435724 100644 --- a/lib/controllers/collapsing_header_scroll_mixin.dart +++ b/lib/controllers/collapsing_header_scroll_mixin.dart @@ -13,6 +13,7 @@ double collectionHeaderExpandedHeight(BuildContext context) { mixin CollapsingHeaderScrollMixin on State { final ScrollController scrollController = ScrollController(); final ValueNotifier showTitleNotifier = ValueNotifier(false); + double? _cachedExpandedHeight; @override void initState() { @@ -20,6 +21,12 @@ mixin CollapsingHeaderScrollMixin on State { scrollController.addListener(_onHeaderScroll); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _cachedExpandedHeight = calculateExpandedHeight(context); + } + @override void dispose() { scrollController.removeListener(_onHeaderScroll); @@ -32,7 +39,8 @@ mixin CollapsingHeaderScrollMixin on State { collectionHeaderExpandedHeight(context); void _onHeaderScroll() { - final expandedHeight = calculateExpandedHeight(context); + final expandedHeight = + _cachedExpandedHeight ?? calculateExpandedHeight(context); showTitleNotifier.value = scrollController.offset > (expandedHeight - kToolbarHeight - 20); } diff --git a/lib/screens/album_screen.dart b/lib/screens/album_screen.dart index f5169a725..ce45980cd 100644 --- a/lib/screens/album_screen.dart +++ b/lib/screens/album_screen.dart @@ -39,6 +39,7 @@ import 'package:mornye/widgets/desktop/detail_header.dart'; import 'package:mornye/widgets/desktop/desktop_selection.dart'; import 'package:mornye/widgets/desktop/track_list_table.dart'; import 'package:mornye/widgets/audio_quality_badges.dart'; +import 'package:mornye/widgets/cached_cover_image.dart'; import 'package:mornye/widgets/motion_header_banner.dart'; import 'package:mornye/widgets/track_detail_actions.dart'; import 'package:mornye/widgets/selection_action_button.dart'; @@ -107,6 +108,8 @@ class _AlbumScreenState extends ConsumerState String? _headerImageUrl; List _audioTraits = const []; String? _description; + List? _commonQualitySource; + Track? _commonQualityCache; /// Double click and Enter actions of the desktop table rows, by row id. final Map _desktopActivations = {}; @@ -297,6 +300,9 @@ class _AlbumScreenState extends ConsumerState ); Track? _commonQualityTrack(List tracks) { + if (identical(_commonQualitySource, tracks)) { + return _commonQualityCache; + } final counts = <(String, bool?), int>{}; for (final track in tracks) { final signature = _qualitySignature(track); @@ -305,12 +311,16 @@ class _AlbumScreenState extends ConsumerState } // A strict majority avoids choosing an arbitrary baseline for mixed albums. // Unknown metadata counts towards the total, but never implies a quality. + Track? result; for (final track in tracks) { if ((counts[_qualitySignature(track)] ?? 0) > tracks.length / 2) { - return track; + result = track; + break; } } - return null; + _commonQualitySource = tracks; + _commonQualityCache = result; + return result; } List _audioTraitInline({Track? commonQualityTrack}) { @@ -558,13 +568,16 @@ class _AlbumScreenState extends ConsumerState final showSquareCover = context.isMornye || !hasMotion; final expandedHeight = calculateExpandedHeight(context); final cacheWidth = coverCacheWidthForViewport(context); + final bgCacheWidth = !context.isMornye && showSquareCover + ? metadataBackdropCacheExtent(context) + : cacheWidth; final headerBgUrl = _headerImageUrl ?? widget.headerImageUrl ?? widget.coverUrl; Widget headerBgImage() => headerBgUrl != null ? CachedNetworkImage( imageUrl: highResCoverUrl(headerBgUrl) ?? headerBgUrl, fit: BoxFit.cover, - memCacheWidth: cacheWidth, + memCacheWidth: bgCacheWidth, cacheManager: CoverCacheManager.instance, placeholder: (_, _) => Container(color: colorScheme.surface), errorWidget: (_, _, _) => Container(color: colorScheme.surface), diff --git a/lib/screens/downloaded_album_screen.dart b/lib/screens/downloaded_album_screen.dart index 91c97ba90..576cda256 100644 --- a/lib/screens/downloaded_album_screen.dart +++ b/lib/screens/downloaded_album_screen.dart @@ -408,17 +408,20 @@ class _DownloadedAlbumScreenState extends ConsumerState : null; final cacheWidth = coverCacheWidthForViewport(context); + final bgCacheWidth = !context.isMornye + ? metadataBackdropCacheExtent(context) + : cacheWidth; final Widget background = embeddedCoverPath != null ? LocalOrNetworkCoverImage( url: embeddedCoverPath, - localCacheWidth: cacheWidth, + localCacheWidth: bgCacheWidth, placeholder: (_) => Container(color: colorScheme.surface), ) : widget.coverUrl != null ? CachedNetworkImage( imageUrl: highResCoverUrl(widget.coverUrl) ?? widget.coverUrl!, fit: BoxFit.cover, - memCacheWidth: cacheWidth, + memCacheWidth: bgCacheWidth, cacheManager: CoverCacheManager.instance, placeholder: (_, _) => Container(color: colorScheme.surface), errorWidget: (_, _, _) => Container(color: colorScheme.surface), diff --git a/lib/screens/local_album_screen.dart b/lib/screens/local_album_screen.dart index ff5eb70b8..57e7225c8 100644 --- a/lib/screens/local_album_screen.dart +++ b/lib/screens/local_album_screen.dart @@ -409,10 +409,13 @@ class _LocalAlbumScreenState extends ConsumerState : null; final cacheWidth = coverCacheWidthForViewport(context); + final bgCacheWidth = !context.isMornye + ? metadataBackdropCacheExtent(context) + : cacheWidth; final Widget background = coverPath != null ? LocalOrNetworkCoverImage( url: coverPath, - localCacheWidth: cacheWidth, + localCacheWidth: bgCacheWidth, placeholder: (_) => Container(color: colorScheme.surface), ) : Container( @@ -972,6 +975,7 @@ class _LocalAlbumScreenState extends ConsumerState ) { final allSelected = selectedIds.length == tracks.length && tracks.isNotEmpty; + final selectedUnified = _selectedUnifiedItems(tracks); return LibraryTrackSelectionBar( selectedCount: selectedIds.length, @@ -983,7 +987,7 @@ class _LocalAlbumScreenState extends ConsumerState bottomPadding: bottomPadding, albumDelete: true, playbackActions: LibrarySelectionPlaybackActions( - items: _selectedUnifiedItems(tracks), + items: selectedUnified, onClose: exitSelectionMode, ), flacEligibleCount: _selectedFlacEligibleItems(tracks).length, @@ -992,12 +996,12 @@ class _LocalAlbumScreenState extends ConsumerState onConvert: () => showBatchConvertSheet( context, ref, - _selectedUnifiedItems(tracks), + selectedUnified, onExitSelectionMode: exitSelectionMode, ), onReplayGain: ({required remove}) => runBatchReplayGain( context, - _selectedUnifiedItems(tracks), + selectedUnified, onExitSelectionMode: exitSelectionMode, remove: remove, ), diff --git a/lib/screens/playlist_screen.dart b/lib/screens/playlist_screen.dart index b52d7c59d..e8db414de 100644 --- a/lib/screens/playlist_screen.dart +++ b/lib/screens/playlist_screen.dart @@ -317,6 +317,9 @@ class _PlaylistScreenState extends ConsumerState motionUrl != null && motionUrl.trim().isNotEmpty && Uri.tryParse(motionUrl)?.hasAuthority == true; + final bgCacheWidth = !context.isMornye && !hasMotion + ? metadataBackdropCacheExtent(context) + : cacheWidth; Widget playlistPlaceholder({double? size}) { return Container( color: colorScheme.surfaceContainerHighest, @@ -332,7 +335,7 @@ class _PlaylistScreenState extends ConsumerState ? CachedCoverImage( imageUrl: highResCoverUrl(_coverUrl) ?? _coverUrl!, fit: BoxFit.cover, - memCacheWidth: cacheWidth, + memCacheWidth: bgCacheWidth, placeholder: (_, _) => Container(color: colorScheme.surface), errorWidget: (_, _, _) => Container(color: colorScheme.surface), ) @@ -500,7 +503,7 @@ class _PlaylistScreenState extends ConsumerState final isInHistory = existingHistoryKeys.contains(historyKeys[index]); // Material joins the rows into one connected list. return TrackCardSegment.at( - key: ValueKey(track.id), + key: ValueKey(selectionId), index: index, count: _tracks.length, child: slideSelectRow( diff --git a/lib/widgets/album_detail_header.dart b/lib/widgets/album_detail_header.dart index 294904bde..131a3efaa 100644 --- a/lib/widgets/album_detail_header.dart +++ b/lib/widgets/album_detail_header.dart @@ -655,40 +655,74 @@ class MornyeActionCapsule extends ConsumerWidget { } } -class _AlbumStretchArtwork extends StatelessWidget { +class _AlbumStretchArtwork extends StatefulWidget { const _AlbumStretchArtwork({required this.child}); final Widget child; + @override + State<_AlbumStretchArtwork> createState() => _AlbumStretchArtworkState(); +} + +class _AlbumStretchArtworkState extends State<_AlbumStretchArtwork> { + final GlobalKey _artworkKey = GlobalKey(); + ScrollPosition? _position; + double _overscroll = 0; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final next = MediaQuery.disableAnimationsOf(context) + ? null + : Scrollable.maybeOf(context)?.position; + if (next == _position) return; + _position?.removeListener(_onScroll); + _position = next; + _position?.addListener(_onScroll); + _overscroll = _readOverscroll(); + } + + double _readOverscroll() { + final position = _position; + if (position == null || !position.hasContentDimensions) return 0; + return (position.minScrollExtent - position.pixels).clamp( + 0.0, + double.infinity, + ); + } + + void _onScroll() { + final next = _readOverscroll(); + if (next != _overscroll && mounted) { + setState(() => _overscroll = next); + } + } + + @override + void dispose() { + _position?.removeListener(_onScroll); + super.dispose(); + } + @override Widget build(BuildContext context) { - if (MediaQuery.disableAnimationsOf(context)) return child; - final position = Scrollable.of(context).position; + final artwork = RepaintBoundary(key: _artworkKey, child: widget.child); + if (_position == null || _overscroll <= 0) return artwork; return LayoutBuilder( - builder: (context, constraints) => AnimatedBuilder( - animation: position, - child: RepaintBoundary(child: child), - builder: (context, artwork) { - final overscroll = position.hasContentDimensions - ? (position.minScrollExtent - position.pixels).clamp( - 0.0, - double.infinity, - ) - : 0.0; - final height = constraints.maxHeight; - final scale = height > 0 ? 1 + overscroll / height : 1.0; - // The viewport moves the details down during a pull. Keep the image - // at the top and enlarge it without changing the scrollable layout. - return Transform.translate( - offset: Offset(0, -overscroll), - child: Transform.scale( - scale: scale, - alignment: Alignment.topCenter, - child: artwork, - ), - ); - }, - ), + builder: (context, constraints) { + final height = constraints.maxHeight; + final scale = height > 0 ? 1 + _overscroll / height : 1.0; + // The viewport moves the details down during a pull. Keep the image + // at the top and enlarge it without changing the scrollable layout. + return Transform.translate( + offset: Offset(0, -_overscroll), + child: Transform.scale( + scale: scale, + alignment: Alignment.topCenter, + child: artwork, + ), + ); + }, ); } } diff --git a/lib/widgets/app_sliver_header.dart b/lib/widgets/app_sliver_header.dart index 1cfc7102e..6d0b42570 100644 --- a/lib/widgets/app_sliver_header.dart +++ b/lib/widgets/app_sliver_header.dart @@ -68,6 +68,8 @@ class AppSliverHeader extends StatelessWidget { /// Square slot for [titleTrailing]: a 44pt avatar in a 56pt touch target. static const double _titleTrailingExtent = 56; + static final _titleLineHeightCache = {}; + /// Height of the title's line, which [titleTrailing] centers on. The title /// inherits the style [FlexibleSpaceBar] gives it under Material 3. static double _titleLineHeight( @@ -75,18 +77,26 @@ class AppSliverHeader extends StatelessWidget { String text, TextStyle style, ) { + final resolvedStyle = Theme.of(context).textTheme.titleLarge!.merge(style); + final direction = Directionality.of(context); + final scaler = MediaQuery.textScalerOf(context); + final locale = Localizations.maybeLocaleOf(context); + final key = (text, resolvedStyle, direction, scaler, locale); + final cached = _titleLineHeightCache[key]; + if (cached != null) return cached; final painter = TextPainter( - text: TextSpan( - text: text, - style: Theme.of(context).textTheme.titleLarge!.merge(style), - ), - textDirection: Directionality.of(context), - textScaler: MediaQuery.textScalerOf(context), - locale: Localizations.maybeLocaleOf(context), + text: TextSpan(text: text, style: resolvedStyle), + textDirection: direction, + textScaler: scaler, + locale: locale, maxLines: 1, )..layout(); final height = painter.height; painter.dispose(); + if (_titleLineHeightCache.length >= 32) { + _titleLineHeightCache.remove(_titleLineHeightCache.keys.first); + } + _titleLineHeightCache[key] = height; return height; }