From 13a2d9c733ea9df0e1373483b25f17202cda04e9 Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:52:21 +0700 Subject: [PATCH] feat(metadata): rebuild track details on the collection header for both styles Track details kept a hand-built hero for Material and a separate page for Mornye, with Play and Delete as a bottom bar and one long card of facts. - Both styles and desktop now use the collection header: cover, title, artist with the album below, and the meta row (quality, length, explicit badge, source). The header takes its colours from the artwork. - Play is the one wide filled button in the header, between a round Edit metadata and a round Add to queue. Delete stays in the More menu only. - The facts are split into Metadata, Release, Audio and File Info, built once for both styles, on tokens and text roles instead of literals. Identifiers copy on a tap; a long press still offers the copy sheet. - A missing file shows the shared error card above the sections. - The song change transition follows the app's motion settings. - The service pill and its per-service icons are gone; the service is a row of File Info. Tests follow the new layout. The sidecar export test also scrolls the desktop menu to its row, which sat below the menu's fold. --- lib/l10n/arb/app_en.arb | 8 + lib/screens/track_metadata_actions.dart | 13 - lib/screens/track_metadata_cards.dart | 981 +++++++----------- lib/screens/track_metadata_header.dart | 285 +++++ lib/screens/track_metadata_lyrics.dart | 10 +- lib/screens/track_metadata_mornye.dart | 199 ---- lib/screens/track_metadata_screen.dart | 194 +--- test/track_metadata_header_contrast_test.dart | 29 +- test/track_metadata_playback_test.dart | 74 +- test/track_metadata_sidecar_export_test.dart | 3 + test/track_metadata_wide_layout_test.dart | 5 +- 11 files changed, 783 insertions(+), 1018 deletions(-) create mode 100644 lib/screens/track_metadata_header.dart delete mode 100644 lib/screens/track_metadata_mornye.dart diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index 43bfbb96c..d4e08de52 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -2400,6 +2400,14 @@ "@trackFileInfo": { "description": "Tab title - file information" }, + "trackSectionRelease": "Release", + "@trackSectionRelease": { + "description": "Section title on the track details page: facts about the release the song belongs to (label, copyright, ISRC, barcode)" + }, + "trackSectionAudio": "Audio", + "@trackSectionAudio": { + "description": "Section title on the track details page: facts about the sound (duration, quality, tempo, ReplayGain)" + }, "trackLyrics": "Lyrics", "@trackLyrics": { "description": "Tab title - lyrics" diff --git a/lib/screens/track_metadata_actions.dart b/lib/screens/track_metadata_actions.dart index 3e09bc9be..5ec0364c8 100644 --- a/lib/screens/track_metadata_actions.dart +++ b/lib/screens/track_metadata_actions.dart @@ -308,17 +308,4 @@ extension _TrackMetadataFileActions on _TrackMetadataScreenState { '${date.hour.toString().padLeft(2, '0')}:' '${date.minute.toString().padLeft(2, '0')}'; } - - IconData _getServiceIcon(String service) { - switch (service.toLowerCase()) { - case MusicServices.tidal: - return Icons.waves; - case MusicServices.qobuz: - return Icons.album; - case MusicServices.amazon: - return Icons.shopping_cart; - default: - return Icons.cloud_download; - } - } } diff --git a/lib/screens/track_metadata_cards.dart b/lib/screens/track_metadata_cards.dart index f27ba286c..5e6be1da7 100644 --- a/lib/screens/track_metadata_cards.dart +++ b/lib/screens/track_metadata_cards.dart @@ -1,11 +1,5 @@ part of 'track_metadata_screen.dart'; -const _trackMetadataHeroScheme = ColorScheme.dark( - surface: Colors.black, - onSurface: Colors.white, - onSurfaceVariant: Colors.white70, -); - /// Content width, inside the page padding, at which the cards split into two /// columns of about 470 or more each. const double _trackMetadataTwoColumnMinWidth = 960; @@ -17,36 +11,39 @@ double _trackMetadataContentMaxWidth(double width) => ? math.min(width, desktopMaterialContentMaxWidth) : adaptiveContentMaxWidth(width); -final ImageFilter _trackMetadataBackdropBlur = ImageFilter.blur( - sigmaX: 32, - sigmaY: 32, -); +/// Inner padding of a section, the same as the analysis cards below them. +const double _trackMetadataSectionPadding = 20; + +/// The song's facts by the section that shows them. [all] keeps them in +/// reading order for Copy all. +typedef _MetadataFacts = ({ + List<_MetadataItem> tags, + List<_MetadataItem> release, + List<_MetadataItem> audio, + List<_MetadataItem> file, + List<_MetadataItem> all, +}); extension _TrackMetadataCards on _TrackMetadataScreenState { - List _headerMetadataItems(BuildContext context) => [ - if (_displayAudioQuality != null && _displayAudioQuality!.isNotEmpty) - HeaderMetaItem(_displayAudioQuality!), - if (duration != null) HeaderMetaItem(formatClock(duration!)), - if (_service == 'local') - HeaderMetaItem( - context.l10n.librarySourceLocal, - icon: context.isMornye ? CupertinoIcons.folder : Icons.folder, - ) - else if (_service.isNotEmpty) - HeaderMetaItem(_service[0].toUpperCase() + _service.substring(1)), - ]; - Widget _buildAnimatedTrackContent( BuildContext context, WidgetRef ref, ColorScheme colorScheme, ) { final currentKey = ValueKey('metadata_content_$_itemId'); + final incoming = AppMotion.effects( + context, + AppMotionSpec(context.tokens.motionMedium, Curves.easeOutCubic), + ); + final outgoing = AppMotion.effectsFast( + context, + AppMotionSpec(context.tokens.motionFast, Curves.easeInCubic), + ); return AnimatedSwitcher( - duration: const Duration(milliseconds: 240), - reverseDuration: const Duration(milliseconds: 180), - switchInCurve: Curves.easeOutCubic, - switchOutCurve: Curves.easeInCubic, + duration: incoming.duration, + reverseDuration: outgoing.duration, + switchInCurve: incoming.curve, + switchOutCurve: outgoing.curve, layoutBuilder: (currentChild, previousChildren) { return Stack( alignment: Alignment.topCenter, @@ -63,91 +60,107 @@ extension _TrackMetadataCards on _TrackMetadataScreenState { isIncoming ? 0.18 * direction : -0.18 * direction, 0, ); - final curved = CurvedAnimation( - parent: animation, - curve: Curves.easeOutCubic, - reverseCurve: Curves.easeInCubic, - ); return ClipRect( child: SlideTransition( position: Tween( begin: begin, end: Offset.zero, - ).animate(curved), + ).animate(animation), child: FadeTransition(opacity: animation, child: child), ), ); }, child: Padding( key: currentKey, - padding: const EdgeInsets.all(16), + padding: EdgeInsets.all(context.tokens.gapLg), child: LayoutBuilder( builder: (context, constraints) { + final gap = SizedBox(height: context.tokens.gapLg); + final facts = _metadataFacts(context); final details = [ - _buildMetadataCard(context, colorScheme, _fileSize), - const SizedBox(height: 16), - _buildFileInfoCard(context, colorScheme, _fileExists, _fileSize), + _buildFactsSection( + context, + colorScheme, + title: context.l10n.trackMetadata, + items: facts.tags, + all: facts.all, + ), + if (facts.release.isNotEmpty || upc != null || _hasServiceLink) + _buildFactsSection( + context, + colorScheme, + title: context.l10n.trackSectionRelease, + items: facts.release, + all: facts.all, + footer: [ + if (upc case final barcodeValue?) + MetadataBarcode( + value: barcodeValue, + label: context.l10n.editMetadataFieldUpc, + onCopy: () => _copyToClipboard(context, barcodeValue), + ), + if (_hasServiceLink) _buildOpenServiceButton(context), + ], + ), + if (facts.audio.isNotEmpty) + _buildFactsSection( + context, + colorScheme, + title: context.l10n.trackSectionAudio, + items: facts.audio, + all: facts.all, + ), + _buildFileInfoCard(context, colorScheme, facts), ]; final media = [ _buildLyricsCard(context, colorScheme), if (_fileExists) ...[ - const SizedBox(height: 16), AudioAnalysisCard( filePath: _filePath, codecHint: _storedAudioFormat, exportName: _buildSaveBaseName(), ), - if (HiResCheckCard.isCandidate( - _filePath, - _storedAudioFormat, - )) ...[ - const SizedBox(height: 16), + if (HiResCheckCard.isCandidate(_filePath, _storedAudioFormat)) HiResCheckCard( filePath: _filePath, formatHint: _storedAudioFormat, name: '$artistName - $trackName', ), - ], ], ]; Widget column(List children) => Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: children, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (final (index, child) in children.indexed) ...[ + if (index > 0) gap, + child, + ], + ], ); final twoColumns = constraints.maxWidth >= _trackMetadataTwoColumnMinWidth; return Column( - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - if (_fileAccessMessage(context) case final message? - when !context.isMornye) + if (_fileAccessMessage(context) case final message?) Padding( - padding: const EdgeInsets.only(bottom: 16), - child: Text( - message, - style: TextStyle(color: colorScheme.error), - ), + padding: EdgeInsets.only(bottom: context.tokens.gapLg), + child: ErrorCard(error: message, colorScheme: colorScheme), ), // Wide windows put the tags and file facts beside lyrics and // analysis instead of one long column of stretched rows. if (twoColumns) Row( crossAxisAlignment: CrossAxisAlignment.start, + spacing: context.tokens.gapLg, children: [ Expanded(child: column(details)), - const SizedBox(width: 16), Expanded(child: column(media)), ], ) else - column([...details, const SizedBox(height: 16), ...media]), - - if (!context.isMornye) ...[ - const SizedBox(height: 24), - _buildActionButtons(context, ref, colorScheme, _fileExists), - ], - - const SizedBox(height: 32), + column([...details, ...media]), + SizedBox(height: context.tokens.gapLg * 2), ], ); }, @@ -156,286 +169,148 @@ extension _TrackMetadataCards on _TrackMetadataScreenState { ); } - Widget _buildHeaderBackground( - BuildContext context, - ColorScheme colorScheme, - double expandedHeight, - bool showContent, - ) { - final coverCacheWidth = coverCacheWidthForViewport(context); - final backdropCacheWidth = metadataBackdropCacheExtent(context); - // Downloaded-item entry points must await resolveOrExtract before pushing - // this route. That precondition keeps the Hero, foreground, and backdrop - // on one source from the first frame; this synchronous lookup also covers - // cached rebuilds and in-screen swipe navigation. - final sharedEmbeddedCoverPath = _hasPath(_embeddedCoverPreviewPath) - ? _embeddedCoverPreviewPath - : DownloadedEmbeddedCoverResolver.resolve(_filePath); - final artworkSource = resolveMetadataArtworkSource( - embeddedCoverPath: sharedEmbeddedCoverPath, - localCoverPath: _localCoverPath, - remoteCoverUrl: _coverUrl, - ); + bool get _hasServiceLink => _spotifyId != null && _spotifyId!.isNotEmpty; - Widget artworkImage({required int cacheWidth, int? cacheHeight}) { - final source = artworkSource; - if (source == null) { - return Container( - color: colorScheme.surfaceContainerHighest, - child: Icon( - Icons.music_note, - size: 80, - color: colorScheme.onSurfaceVariant, - ), - ); - } + /// The service this song's catalog ID belongs to. + String get _linkedService => + _serviceForTrackId(_spotifyId!, fallbackService: _service.toLowerCase()); - if (isHttpCoverUrl(source)) { - return CachedCoverImage( - imageUrl: source, - fit: BoxFit.cover, - memCacheWidth: cacheWidth, - memCacheHeight: cacheHeight, - placeholder: (_, _) => Container(color: colorScheme.surface), - errorWidget: (_, _, _) => Container(color: colorScheme.surface), - ); - } + _MetadataFacts _metadataFacts(BuildContext context) { + final l10n = context.l10n; + String? edited(String key) => + normalizeOptionalString(_editedMetadata?[key]?.toString()); + final replayGainTrackGain = edited('replaygain_track_gain'); + final replayGainTrackPeak = edited('replaygain_track_peak'); + final replayGainAlbumGain = edited('replaygain_album_gain'); + final replayGainAlbumPeak = edited('replaygain_album_peak'); - final filePath = coverFilePath(source); - if (filePath == null) return Container(color: colorScheme.surface); - return Image.file( - File(filePath), - fit: BoxFit.cover, - cacheWidth: cacheWidth, - cacheHeight: cacheHeight, - gaplessPlayback: true, - filterQuality: FilterQuality.low, - errorBuilder: (_, _, _) => Container(color: colorScheme.surface), - ); - } + final tags = <_MetadataItem>[ + _MetadataItem(l10n.trackTrackName, trackName), + _MetadataItem(l10n.trackArtist, artistName), + if (albumArtist != null && albumArtist != artistName) + _MetadataItem(l10n.trackAlbumArtist, albumArtist!), + _MetadataItem(l10n.trackAlbum, albumName), + if (trackNumber != null && trackNumber! > 0) + _MetadataItem(l10n.trackTrackNumber, trackNumber.toString()), + if (totalTracks != null && totalTracks! > 0) + _MetadataItem(l10n.editMetadataFieldTrackTotal, totalTracks.toString()), + if (discNumber != null && discNumber! > 0) + _MetadataItem(l10n.trackDiscNumber, discNumber.toString()), + if (totalDiscs != null && totalDiscs! > 0) + _MetadataItem(l10n.editMetadataFieldDiscTotal, totalDiscs.toString()), + if (releaseDate != null && releaseDate!.isNotEmpty) + _MetadataItem(l10n.trackReleaseDate, releaseDate!), + if (genre != null && genre!.isNotEmpty) + _MetadataItem(l10n.trackGenre, genre!), + if (edited('mood') case final String mood) + _MetadataItem(l10n.trackMood, mood), + if (composer != null && composer!.isNotEmpty) + _MetadataItem(l10n.editMetadataFieldComposer, composer!), + if (comment != null) + _MetadataItem(l10n.editMetadataFieldComment, comment!), + ]; - Widget coverImage() => artworkImage(cacheWidth: coverCacheWidth); - Widget backdropImage() => artworkImage( - cacheWidth: backdropCacheWidth, - cacheHeight: backdropCacheWidth, - ); - - // Centered square cover over a blurred backdrop (same layout as the album - // header) so the Hero flight from a list thumbnail keeps its square shape. - // Landscape headers are short: the cover also yields to the height left - // below the toolbar after the title block, so nothing rises into it. - final toolbarBottom = MediaQuery.paddingOf(context).top + kToolbarHeight; - const textBlockHeight = 190.0; - // Desktop allows up to 260, close to the desktop album header's cover. - final coverSize = math.min( - (MediaQuery.sizeOf(context).width * 0.5).clamp( - 150.0, - isDesktopPlatform ? 260.0 : 210.0, - ), - math.max(96.0, expandedHeight - toolbarBottom - textBlockHeight), - ); - - return Stack( - fit: StackFit.expand, - children: [ - RepaintBoundary( - key: ValueKey('metadata_backdrop_$_itemId'), - child: ImageFiltered( - imageFilter: _trackMetadataBackdropBlur, - child: backdropImage(), - ), + final release = <_MetadataItem>[ + if (albumType != null) _MetadataItem(l10n.trackAlbumType, albumType!), + if (label != null && label!.isNotEmpty) + _MetadataItem(l10n.trackLabel, label!), + if (copyright != null && copyright!.isNotEmpty) + _MetadataItem(l10n.trackCopyright, copyright!), + if (isrc != null && isrc!.isNotEmpty) + _MetadataItem( + 'ISRC', + formatIsrcForDisplay(isrc), + rawValue: canonicalIsrcForCopy(isrc), + copyable: true, ), - Container(color: Colors.black.withValues(alpha: 0.35)), - Positioned( - left: 0, - right: 0, - bottom: 0, - height: expandedHeight * 0.65, - child: Container( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - Colors.transparent, - Colors.black.withValues(alpha: 0.85), - ], - ), - ), - ), + if (!_isLocalItem && _hasServiceLink) + _MetadataItem( + switch (_linkedService) { + MusicServices.deezer => 'Deezer ID', + MusicServices.amazon => 'Amazon ASIN', + MusicServices.tidal => 'Tidal ID', + MusicServices.qobuz => 'Qobuz ID', + _ => 'Spotify ID', + }, + _displayServiceTrackId(_spotifyId!), + copyable: true, ), - Positioned( - left: 20, - right: 20, - bottom: 40, - child: AnimatedOpacity( - duration: const Duration(milliseconds: 150), - opacity: showContent ? 1.0 : 0.0, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - children: [ - Hero( - tag: _coverHeroTag, - child: Container( - width: coverSize, - height: coverSize, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(16), - boxShadow: [ - BoxShadow( - color: Colors.black.withValues(alpha: 0.45), - blurRadius: 24, - offset: const Offset(0, 8), - ), - ], - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(16), - child: SizedBox( - width: coverSize, - height: coverSize, - child: coverImage(), - ), - ), - ), - ), - const SizedBox(height: 20), - ExplicitTrackTitle( - title: trackName, - explicit: isExplicit, - style: const TextStyle( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.bold, - height: 1.2, - ), - textAlign: TextAlign.center, - maxLines: 3, - overflow: TextOverflow.ellipsis, - colorScheme: _trackMetadataHeroScheme, - ), - const SizedBox(height: 6), - Text( - artistName, - style: const TextStyle( - color: Colors.white70, - fontSize: 16, - fontWeight: FontWeight.w600, - ), - textAlign: TextAlign.center, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - const SizedBox(height: 4), - Text( - albumName, - style: const TextStyle(color: Colors.white54, fontSize: 14), - textAlign: TextAlign.center, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - const SizedBox(height: 12), - HeaderPalette( - scheme: _trackMetadataHeroScheme, - child: HeaderMetaRow(items: _headerMetadataItems(context)), - ), - ], - ), - ), + ]; + + final audio = <_MetadataItem>[ + if (duration != null) + _MetadataItem(l10n.trackDuration, formatClock(duration!)), + if (_displayAudioQuality case final quality?) + _MetadataItem(l10n.trackAudioQuality, quality), + if (_editedMetadata?['bpm'] case final int bpm when bpm > 0) + _MetadataItem(l10n.trackBpm, bpm.toString()), + if (replayGainTrackGain != null) + _MetadataItem(l10n.trackReplayGainTrackGain, replayGainTrackGain), + if (replayGainTrackPeak != null) + _MetadataItem(l10n.trackReplayGainTrackPeak, replayGainTrackPeak), + if (replayGainAlbumGain != null) + _MetadataItem(l10n.trackReplayGainAlbumGain, replayGainAlbumGain), + if (replayGainAlbumPeak != null) + _MetadataItem(l10n.trackReplayGainAlbumPeak, replayGainAlbumPeak), + ]; + + final file = <_MetadataItem>[ + if (_embeddedCoverDimensions case final dimensions?) + _MetadataItem( + l10n.trackCoverResolution, + '${dimensions.width} × ${dimensions.height} px', ), - ], + _MetadataItem(l10n.trackMetadataService, _service.toUpperCase()), + _MetadataItem(l10n.trackDownloaded, _formatFullDate(_addedAt)), + ]; + + return ( + tags: tags, + release: release, + audio: audio, + file: file, + all: [...tags, ...release, ...audio, ...file], ); } - RoundedRectangleBorder _sectionCardShape(ColorScheme colorScheme) { - return RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20), - side: BorderSide( - color: colorScheme.outlineVariant.withValues(alpha: 0.5), - ), - ); - } + Widget _buildSectionTitle(BuildContext context, String title) => Text( + title, + style: Theme.of( + context, + ).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600), + ); - Widget _buildMetadataCard( + /// One titled section of facts, with [footer] widgets under its rows. + Widget _buildFactsSection( BuildContext context, - ColorScheme colorScheme, - int? fileSize, - ) { + ColorScheme colorScheme, { + required String title, + required List<_MetadataItem> items, + required List<_MetadataItem> all, + List footer = const [], + }) { + final tokens = context.tokens; return _metadataSectionSurface( context, colorScheme, child: Padding( - padding: const EdgeInsets.all(20), + padding: const EdgeInsets.all(_trackMetadataSectionPadding), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - context.l10n.trackMetadata, - style: Theme.of(context).textTheme.titleMedium?.copyWith( - fontWeight: FontWeight.w600, - color: colorScheme.onSurface, - ), - ), - const SizedBox(height: 16), - - _buildMetadataGrid(context, colorScheme), - - if (upc case final barcodeValue?) ...[ - const SizedBox(height: 16), - MetadataBarcode( - value: barcodeValue, - label: context.l10n.editMetadataFieldUpc, - onCopy: () => _copyToClipboard(context, barcodeValue), - ), - ], - - if (_spotifyId != null && _spotifyId!.isNotEmpty) ...[ - const SizedBox(height: 8), - Builder( - builder: (context) { - final openService = _serviceForTrackId( - _spotifyId!, - fallbackService: _service.toLowerCase(), - ); - String buttonLabel; - if (openService == MusicServices.deezer) { - buttonLabel = context.l10n.trackOpenInDeezer; - } else if (openService == MusicServices.amazon) { - buttonLabel = context.l10n.trackOpenInService( - 'Amazon Music', - ); - } else if (openService == MusicServices.tidal) { - buttonLabel = context.l10n.trackOpenInService('Tidal'); - } else if (openService == MusicServices.qobuz) { - buttonLabel = context.l10n.trackOpenInService('Qobuz'); - } else { - buttonLabel = context.l10n.trackOpenInSpotify; - } - if (context.isMornye) { - return HeaderFilledButton( - icon: CupertinoIcons.arrow_up_right_square, - label: buttonLabel, - onPressed: () => _openServiceUrl(context), - ); - } - return ExpressiveButton( - outlined: true, - onPressed: () => _openServiceUrl(context), - icon: const Icon(Icons.open_in_new, size: 18), - style: OutlinedButton.styleFrom( - padding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 10, - ), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - ), - child: Text(buttonLabel), - ); - }, + _buildSectionTitle(context, title), + SizedBox(height: tokens.gapSm), + for (final (index, item) in items.indexed) + _buildFactRow( + context, + colorScheme, + item, + all: all, + showDivider: index != items.length - 1, ), + for (final widget in footer) ...[ + SizedBox(height: tokens.gapMd), + widget, ], ], ), @@ -443,16 +318,106 @@ extension _TrackMetadataCards on _TrackMetadataScreenState { ); } + /// A label and its value. A tap copies a [_MetadataItem.copyable] value; + /// a long press offers to copy the value, the field or every fact. + Widget _buildFactRow( + BuildContext context, + ColorScheme colorScheme, + _MetadataItem item, { + required List<_MetadataItem> all, + required bool showDivider, + }) { + final tokens = context.tokens; + final textTheme = Theme.of(context).textTheme; + final onTap = item.copyable + ? () => _copyToClipboard(context, item.rawValue) + : null; + void onLongPress() => + _showMetadataCopySheet(context, metadata: item, allMetadata: all); + final copy = item.copyable + ? AppIcon.adaptive( + Icons.copy, + size: 16, + color: colorScheme.onSurfaceVariant, + ) + : null; + if (context.isMornye) { + return MornyeMetadataRow( + label: item.label, + value: item.value, + showDivider: showDivider, + trailing: copy, + onTap: onTap, + onLongPress: onLongPress, + ); + } + return InkWell( + onTap: onTap, + onLongPress: onLongPress, + borderRadius: tokens.borderRadiusThumb, + // Every row keeps the minimum touch target for its long press. + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: tokens.minTouchTarget), + child: Padding( + padding: EdgeInsets.symmetric(vertical: tokens.gapSm), + child: Row( + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + spacing: tokens.gapMd, + children: [ + Expanded( + flex: 2, + child: Text( + item.label, + style: textTheme.bodyMedium?.copyWith( + color: colorScheme.onSurfaceVariant, + ), + ), + ), + Expanded( + flex: 3, + child: Text(item.value, style: textTheme.bodyLarge), + ), + ?copy, + ], + ), + ), + ), + ); + } + + /// Opens the song in the service its catalog ID belongs to. + Widget _buildOpenServiceButton(BuildContext context) { + final l10n = context.l10n; + final label = switch (_linkedService) { + MusicServices.deezer => l10n.trackOpenInDeezer, + MusicServices.amazon => l10n.trackOpenInService('Amazon Music'), + MusicServices.tidal => l10n.trackOpenInService('Tidal'), + MusicServices.qobuz => l10n.trackOpenInService('Qobuz'), + _ => l10n.trackOpenInSpotify, + }; + if (context.isMornye) { + return HeaderFilledButton( + icon: CupertinoIcons.arrow_up_right_square, + label: label, + tonal: true, + onPressed: () => _openServiceUrl(context), + ); + } + return ExpressiveButton( + outlined: true, + onPressed: () => _openServiceUrl(context), + icon: const AppIcon.adaptive(Icons.open_in_new, size: 18), + child: Text(label), + ); + } + Future _openServiceUrl(BuildContext context) async { if (_spotifyId == null) return; - final openService = _serviceForTrackId( - _spotifyId!, - fallbackService: _service.toLowerCase(), - ); // Unknown services open as Spotify, as this button always has. final link = ServiceTrackLink( - openService, + _linkedService, _displayServiceTrackId(_spotifyId!), ); final webUrl = link.webUrl; @@ -490,209 +455,6 @@ extension _TrackMetadataCards on _TrackMetadataScreenState { } } - Widget _buildMetadataGrid(BuildContext context, ColorScheme colorScheme) { - final audioQualityStr = _displayAudioQuality; - final replayGainTrackGain = normalizeOptionalString( - _editedMetadata?['replaygain_track_gain']?.toString(), - ); - final replayGainTrackPeak = normalizeOptionalString( - _editedMetadata?['replaygain_track_peak']?.toString(), - ); - final replayGainAlbumGain = normalizeOptionalString( - _editedMetadata?['replaygain_album_gain']?.toString(), - ); - final replayGainAlbumPeak = normalizeOptionalString( - _editedMetadata?['replaygain_album_peak']?.toString(), - ); - - final items = <_MetadataItem>[ - _MetadataItem(context.l10n.trackTrackName, trackName), - _MetadataItem(context.l10n.trackArtist, artistName), - if (albumArtist != null && albumArtist != artistName) - _MetadataItem(context.l10n.trackAlbumArtist, albumArtist!), - _MetadataItem(context.l10n.trackAlbum, albumName), - if (trackNumber != null && trackNumber! > 0) - _MetadataItem(context.l10n.trackTrackNumber, trackNumber.toString()), - if (totalTracks != null && totalTracks! > 0) - _MetadataItem( - context.l10n.editMetadataFieldTrackTotal, - totalTracks.toString(), - ), - if (discNumber != null && discNumber! > 0) - _MetadataItem(context.l10n.trackDiscNumber, discNumber.toString()), - if (totalDiscs != null && totalDiscs! > 0) - _MetadataItem( - context.l10n.editMetadataFieldDiscTotal, - totalDiscs.toString(), - ), - if (duration != null) - _MetadataItem(context.l10n.trackDuration, formatClock(duration!)), - if (audioQualityStr != null) - _MetadataItem(context.l10n.trackAudioQuality, audioQualityStr), - if (_editedMetadata?['bpm'] case final int bpm when bpm > 0) - _MetadataItem(context.l10n.trackBpm, bpm.toString()), - if (normalizeOptionalString(_editedMetadata?['mood']?.toString()) - case final String mood) - _MetadataItem(context.l10n.trackMood, mood), - if (replayGainTrackGain != null) - _MetadataItem( - context.l10n.trackReplayGainTrackGain, - replayGainTrackGain, - ), - if (replayGainTrackPeak != null) - _MetadataItem( - context.l10n.trackReplayGainTrackPeak, - replayGainTrackPeak, - ), - if (replayGainAlbumGain != null) - _MetadataItem( - context.l10n.trackReplayGainAlbumGain, - replayGainAlbumGain, - ), - if (replayGainAlbumPeak != null) - _MetadataItem( - context.l10n.trackReplayGainAlbumPeak, - replayGainAlbumPeak, - ), - if (_embeddedCoverDimensions case final dimensions?) - _MetadataItem( - context.l10n.trackCoverResolution, - '${dimensions.width} × ${dimensions.height} px', - ), - if (releaseDate != null && releaseDate!.isNotEmpty) - _MetadataItem(context.l10n.trackReleaseDate, releaseDate!), - if (genre != null && genre!.isNotEmpty) - _MetadataItem(context.l10n.trackGenre, genre!), - if (label != null && label!.isNotEmpty) - _MetadataItem(context.l10n.trackLabel, label!), - if (copyright != null && copyright!.isNotEmpty) - _MetadataItem(context.l10n.trackCopyright, copyright!), - if (composer != null && composer!.isNotEmpty) - _MetadataItem(context.l10n.editMetadataFieldComposer, composer!), - if (albumType != null) - _MetadataItem(context.l10n.trackAlbumType, albumType!), - if (comment != null) - _MetadataItem(context.l10n.editMetadataFieldComment, comment!), - if (isrc != null && isrc!.isNotEmpty) - _MetadataItem( - 'ISRC', - formatIsrcForDisplay(isrc), - rawValue: canonicalIsrcForCopy(isrc), - ), - ]; - - if (!_isLocalItem && _spotifyId != null && _spotifyId!.isNotEmpty) { - final idService = _serviceForTrackId( - _spotifyId!, - fallbackService: _service.toLowerCase(), - ); - final cleanId = _displayServiceTrackId(_spotifyId!); - String idLabel; - switch (idService) { - case MusicServices.deezer: - idLabel = 'Deezer ID'; - case MusicServices.amazon: - idLabel = 'Amazon ASIN'; - case MusicServices.tidal: - idLabel = 'Tidal ID'; - case MusicServices.qobuz: - idLabel = 'Qobuz ID'; - default: - idLabel = 'Spotify ID'; - } - items.add(_MetadataItem(idLabel, cleanId)); - } - - items.add( - _MetadataItem(context.l10n.trackMetadataService, _service.toUpperCase()), - ); - items.add( - _MetadataItem(context.l10n.trackDownloaded, _formatFullDate(_addedAt)), - ); - - return Column( - children: items.map((metadata) { - final isCopyable = - metadata.label == 'ISRC' || - metadata.label == 'Spotify ID' || - metadata.label == 'Deezer ID' || - metadata.label == 'Amazon ASIN' || - metadata.label == 'Tidal ID' || - metadata.label == 'Qobuz ID'; - if (context.isMornye) { - return MornyeMetadataRow( - label: metadata.label, - value: metadata.value, - showDivider: metadata != items.last, - trailing: isCopyable - ? Icon( - CupertinoIcons.doc_on_doc, - size: 16, - color: colorScheme.onSurfaceVariant, - ) - : null, - onTap: isCopyable - ? () => _copyToClipboard(context, metadata.rawValue) - : null, - onLongPress: () => _showMetadataCopySheet( - context, - metadata: metadata, - allMetadata: items, - ), - ); - } - return InkWell( - onTap: isCopyable - ? () => _copyToClipboard(context, metadata.rawValue) - : null, - onLongPress: () => _showMetadataCopySheet( - context, - metadata: metadata, - allMetadata: items, - ), - borderRadius: BorderRadius.circular(8), - // Copyable rows keep the 48dp minimum touch target. - child: Container( - constraints: BoxConstraints( - minHeight: context.tokens.minTouchTarget, - ), - alignment: AlignmentDirectional.centerStart, - padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 4), - child: Row( - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - SizedBox( - width: 100, - child: Text( - metadata.label, - style: Theme.of(context).textTheme.bodySmall?.copyWith( - color: colorScheme.onSurfaceVariant, - ), - ), - ), - Expanded( - child: Text( - metadata.value, - style: Theme.of(context).textTheme.bodyMedium?.copyWith( - color: colorScheme.onSurface, - ), - ), - ), - if (isCopyable) - Icon( - Icons.copy, - size: 14, - color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5), - ), - ], - ), - ), - ); - }).toList(), - ); - } - Future _showMetadataCopySheet( BuildContext context, { required _MetadataItem metadata, @@ -786,38 +548,33 @@ extension _TrackMetadataCards on _TrackMetadataScreenState { /// One file detail pill. Only the format is emphasized, so the group keeps /// a single strong container; the others stay neutral. Widget _fileInfoPill( + BuildContext context, ColorScheme colorScheme, String label, { bool emphasized = false, - IconData? icon, }) { - final foreground = emphasized - ? colorScheme.onPrimaryContainer - : colorScheme.onSurfaceVariant; - return Container( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), - decoration: BoxDecoration( + final tokens = context.tokens; + return DecoratedBox( + decoration: ShapeDecoration( color: emphasized ? colorScheme.primaryContainer : colorScheme.surfaceContainerHighest, - borderRadius: BorderRadius.circular(20), + shape: const StadiumBorder(), ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - if (icon != null) ...[ - Icon(icon, size: 14, color: foreground), - const SizedBox(width: 4), - ], - Text( - label, - style: TextStyle( - color: foreground, - fontWeight: FontWeight.w600, - fontSize: 12, - ), + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: tokens.gapMd, + vertical: tokens.gapSm * 0.75, + ), + child: Text( + label, + style: Theme.of(context).textTheme.labelMedium?.copyWith( + color: emphasized + ? colorScheme.onPrimaryContainer + : colorScheme.onSurfaceVariant, + fontWeight: FontWeight.w600, ), - ], + ), ), ); } @@ -825,51 +582,45 @@ extension _TrackMetadataCards on _TrackMetadataScreenState { Widget _buildFileInfoCard( BuildContext context, ColorScheme colorScheme, - bool fileExists, - int? fileSize, + _MetadataFacts facts, ) { + final tokens = context.tokens; + final fileSize = _fileSize; final displayFilePath = _formatPathForDisplay(rawFilePath); final fileName = _extractFileNameFromPathOrUri(rawFilePath); final fileExtension = _displayFormatLabelForFile(fileName); final resolvedQuality = _displayAudioQuality; final lossyBitrateLabel = _extractLossyBitrateLabel(resolvedQuality); + Widget pill(String label, {bool emphasized = false}) => + _fileInfoPill(context, colorScheme, label, emphasized: emphasized); return _metadataSectionSurface( context, colorScheme, child: Padding( - padding: const EdgeInsets.all(20), + padding: const EdgeInsets.all(_trackMetadataSectionPadding), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - context.l10n.trackFileInfo, - style: Theme.of(context).textTheme.titleMedium?.copyWith( - fontWeight: FontWeight.w600, - color: colorScheme.onSurface, - ), - ), - const SizedBox(height: 16), - + _buildSectionTitle(context, context.l10n.trackFileInfo), + SizedBox(height: tokens.gapLg), Wrap( - spacing: 8, - runSpacing: 8, + spacing: tokens.gapSm, + runSpacing: tokens.gapSm, children: [ - _fileInfoPill(colorScheme, fileExtension, emphasized: true), - if (fileSize != null) - _fileInfoPill(colorScheme, formatBytes(fileSize)), + pill(fileExtension, emphasized: true), + if (fileSize != null) pill(formatBytes(fileSize)), if (_isBitrateFormatLabel(fileExtension) && lossyBitrateLabel != null) - _fileInfoPill(colorScheme, lossyBitrateLabel) + pill(lossyBitrateLabel) else if (_audioBitrate != null && _audioBitrate! > 0 && _isBitrateFormatLabel(fileExtension)) - _fileInfoPill(colorScheme, '${_audioBitrate}kbps') + pill('${_audioBitrate}kbps') else if (bitDepth != null && bitDepth! > 0 && sampleRate != null) - _fileInfoPill( - colorScheme, + pill( buildDisplayAudioQuality( bitDepth: bitDepth, sampleRate: sampleRate, @@ -879,55 +630,49 @@ extension _TrackMetadataCards on _TrackMetadataScreenState { if (!_isBitrateFormatLabel(fileExtension) && _audioBitrate != null && _audioBitrate! > 0) - _fileInfoPill(colorScheme, '${_audioBitrate}kbps'), - _fileInfoPill( - colorScheme, - _service.toUpperCase(), - icon: _getServiceIcon(_service), - ), + pill('${_audioBitrate}kbps'), ], ), - - const SizedBox(height: 16), - + SizedBox(height: tokens.gapSm), + for (final item in facts.file) + _buildFactRow( + context, + colorScheme, + item, + all: facts.all, + showDivider: true, + ), + // The path is a flat copy row like the facts above it, in both + // styles, instead of a filled box inside the card. InkWell( onTap: () => _copyToClipboard(context, cleanFilePath), - borderRadius: BorderRadius.circular(12), - // Material keeps the path as a flat copy row like the metadata - // rows above, instead of a filled box inside the card. - child: Container( - constraints: BoxConstraints( - minHeight: context.tokens.minTouchTarget, - ), - padding: context.isMornye - ? const EdgeInsets.all(12) - : const EdgeInsets.symmetric(vertical: 6, horizontal: 4), - decoration: context.isMornye - ? BoxDecoration( - color: colorScheme.surfaceContainerHighest, - borderRadius: BorderRadius.circular(12), - ) - : null, - child: Row( - children: [ - Expanded( - child: Text( - displayFilePath, - style: Theme.of(context).textTheme.bodySmall?.copyWith( - fontFamily: 'monospace', - color: colorScheme.onSurfaceVariant, + borderRadius: tokens.borderRadiusThumb, + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: tokens.minTouchTarget), + child: Padding( + padding: EdgeInsets.symmetric(vertical: tokens.gapSm), + child: Row( + spacing: tokens.gapSm, + children: [ + Expanded( + child: Text( + displayFilePath, + style: Theme.of(context).textTheme.bodySmall + ?.copyWith( + fontFamily: 'monospace', + color: colorScheme.onSurfaceVariant, + ), + maxLines: 3, + overflow: TextOverflow.ellipsis, ), - maxLines: 3, - overflow: TextOverflow.ellipsis, ), - ), - const SizedBox(width: 8), - Icon( - context.isMornye ? CupertinoIcons.doc_on_doc : Icons.copy, - size: 18, - color: colorScheme.onSurfaceVariant, - ), - ], + AppIcon.adaptive( + Icons.copy, + size: 18, + color: colorScheme.onSurfaceVariant, + ), + ], + ), ), ), ), diff --git a/lib/screens/track_metadata_header.dart b/lib/screens/track_metadata_header.dart new file mode 100644 index 000000000..3405fb56e --- /dev/null +++ b/lib/screens/track_metadata_header.dart @@ -0,0 +1,285 @@ +part of 'track_metadata_screen.dart'; + +extension _TrackMetadataHeader on _TrackMetadataScreenState { + List _headerMetadataItems(BuildContext context) => [ + if (_displayAudioQuality != null && _displayAudioQuality!.isNotEmpty) + HeaderMetaItem(_displayAudioQuality!), + if (duration != null) HeaderMetaItem(formatClock(duration!)), + // The header's title is plain text, so the badge sits with the details. + if (isExplicit) + Builder( + builder: (header) => + ExplicitBadge(colorScheme: HeaderPalette.of(header)), + ), + if (_service == 'local') + HeaderMetaItem( + context.l10n.librarySourceLocal, + icon: context.isMornye ? CupertinoIcons.folder : Icons.folder, + ) + else if (_service.isNotEmpty) + HeaderMetaItem(_service[0].toUpperCase() + _service.substring(1)), + ]; + + /// The header albums and playlists have, for one song: its cover, title, + /// artist and album, the file's quality and the song's main actions. The + /// rest of the actions stay in the More menu. + /// + /// The slivers go straight into the page's scroll view, so the toolbar + /// stays pinned once the cover and details have scrolled away. + List _buildHeader(BuildContext context, ColorScheme colorScheme) { + final coverCacheWidth = coverCacheWidthForViewport(context); + final backdropCacheWidth = metadataBackdropCacheExtent(context); + // Downloaded-item entry points must await resolveOrExtract before pushing + // this route. That precondition keeps the Hero, foreground, and backdrop + // on one source from the first frame; this synchronous lookup also covers + // cached rebuilds and in-screen swipe navigation. + final sharedEmbeddedCoverPath = _hasPath(_embeddedCoverPreviewPath) + ? _embeddedCoverPreviewPath + : DownloadedEmbeddedCoverResolver.resolve(_filePath); + final artworkSource = resolveMetadataArtworkSource( + embeddedCoverPath: sharedEmbeddedCoverPath, + localCoverPath: _localCoverPath, + remoteCoverUrl: _coverUrl, + ); + + Widget placeholder(double iconSize) => ColoredBox( + color: colorScheme.surfaceContainerHighest, + child: Center( + child: AppIcon.adaptive( + Icons.music_note, + size: iconSize, + color: colorScheme.onSurfaceVariant, + ), + ), + ); + + Widget artworkImage({ + required int cacheWidth, + int? cacheHeight, + required double iconSize, + }) { + final source = artworkSource; + if (source == null) return placeholder(iconSize); + if (isHttpCoverUrl(source)) { + return CachedCoverImage( + imageUrl: source, + fit: BoxFit.cover, + memCacheWidth: cacheWidth, + memCacheHeight: cacheHeight, + placeholder: (_, _) => ColoredBox(color: colorScheme.surface), + errorWidget: (_, _, _) => placeholder(iconSize), + ); + } + final filePath = coverFilePath(source); + if (filePath == null) return placeholder(iconSize); + return Image.file( + File(filePath), + fit: BoxFit.cover, + cacheWidth: cacheWidth, + cacheHeight: cacheHeight, + gaplessPlayback: true, + filterQuality: FilterQuality.low, + errorBuilder: (_, _, _) => placeholder(iconSize), + ); + } + + // Watched here: the header builds its actions outside this build. + final showPlayer = ref.watch(playerUiEnabledProvider); + final back = HeaderCircleButton( + icon: context.isMornye ? CupertinoIcons.back : Icons.arrow_back, + tooltip: MaterialLocalizations.of(context).backButtonTooltip, + onPressed: _popWithMetadataResult, + ); + return AlbumDetailHeader( + title: trackName, + expandedHeight: calculateExpandedHeight(context), + showTitleInAppBar: false, + showTitleListenable: showTitleNotifier, + background: RepaintBoundary( + key: ValueKey('metadata_backdrop_$_itemId'), + child: artworkImage( + cacheWidth: backdropCacheWidth, + cacheHeight: backdropCacheWidth, + iconSize: 80, + ), + ), + paletteSource: artworkSource == null || isHttpCoverUrl(artworkSource) + ? artworkSource + : coverFilePath(artworkSource), + blurAndScrimBackground: artworkSource != null, + // The square cover keeps the Hero flight from a list thumbnail square. + coverBuilder: (context, coverSize) => Hero( + tag: _coverHeroTag, + child: SizedBox.square( + dimension: coverSize, + child: artworkImage(cacheWidth: coverCacheWidth, iconSize: 48), + ), + ), + // Built inside the header, so it reads the header's artwork scheme. + subtitle: Builder(builder: _buildHeaderSubtitle), + meta: HeaderMetaRow(items: _headerMetadataItems(context)), + actions: Builder( + builder: (header) => _buildHeaderActions(header, showPlayer), + ), + appBarActions: [ + Builder( + builder: (buttonContext) => HeaderCircleButton( + icon: context.isMornye ? CupertinoIcons.ellipsis : Icons.more_vert, + tooltip: MaterialLocalizations.of(context).showMenuTooltip, + onPressed: () => _showOptionsMenu( + context, + ref, + colorScheme, + anchor: mornyeMenuAnchor(buttonContext), + ), + ), + ), + ], + // Centered so the tight leading slot of Material cannot stretch it. + leading: context.isMornye || isDesktopPlatform + ? back + : Center(child: back), + ).buildSlivers(context); + } + + /// The artist with the album on a line below it, each cut short on its + /// own so a long artist does not push the album out. + Widget _buildHeaderSubtitle(BuildContext header) { + final scheme = HeaderPalette.of(header); + final mornye = header.isMornye; + final artistStyle = isDesktopPlatform + ? desktopDetailSubtitleStyle(header) + : Theme.of(header).textTheme.titleMedium?.copyWith( + color: mornye + ? Theme.of(header).colorScheme.primary + : scheme.onSurfaceVariant, + fontWeight: mornye ? FontWeight.w400 : FontWeight.w600, + ); + final album = albumName.trim(); + Text line(String text, {TextStyle? style}) => Text( + text, + style: style, + maxLines: 1, + overflow: TextOverflow.ellipsis, + textAlign: isDesktopPlatform ? TextAlign.start : TextAlign.center, + ); + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: isDesktopPlatform + ? CrossAxisAlignment.start + : CrossAxisAlignment.center, + children: [ + line(artistName, style: artistStyle), + if (album.isNotEmpty) + line( + album, + style: Theme.of( + header, + ).textTheme.bodyMedium?.copyWith(color: scheme.onSurfaceVariant), + ), + ], + ); + } + + /// Play as the one wide filled button, between a round Edit and a round + /// Add to queue. A round button is left out where the song cannot take + /// its action; Play stays, disabled, while the file is missing. + Widget _buildHeaderActions(BuildContext header, bool showPlayer) { + final tokens = header.tokens; + final l10n = header.l10n; + final play = HeaderFilledButton( + icon: Icons.play_arrow, + label: l10n.trackMetadataPlay, + onPressed: _fileExists ? () => _openFile(context, rawFilePath) : null, + ); + final edit = _canEditMetadataFile + ? HeaderCircleButton( + icon: Icons.edit_outlined, + tooltip: l10n.trackEditMetadata, + tonal: true, + onPressed: () => _showEditMetadataSheet( + context, + ref, + Theme.of(context).colorScheme, + ), + ) + : null; + final queue = _fileExists && showPlayer + ? HeaderCircleButton( + icon: Icons.playlist_add, + tooltip: l10n.trackAddToQueue, + tonal: true, + onPressed: () => _enqueueThis(ref, playNext: false), + ) + : null; + if (isDesktopPlatform) { + return Row( + mainAxisSize: MainAxisSize.min, + spacing: tokens.gapSm, + children: [play, ?edit, ?queue], + ); + } + if (header.isMornye) { + return Row( + spacing: tokens.gapMd, + children: [ + ?edit, + Expanded(child: play), + ?queue, + ], + ); + } + // Tablets keep the row the width it has on a phone. + return Center( + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 460), + child: ExpressiveButtonGroup( + flexible: {edit == null ? 0 : 1}, + spacing: tokens.gapMd, + slotWidth: tokens.minTouchTarget, + children: [?edit, play, ?queue], + ), + ), + ); + } + + RoundedRectangleBorder _sectionCardShape( + BuildContext context, + ColorScheme colorScheme, + ) { + return RoundedRectangleBorder( + borderRadius: context.tokens.borderRadiusCard, + side: BorderSide( + color: colorScheme.outlineVariant.withValues(alpha: 0.5), + ), + ); + } + + /// The surface of one section of the page, shared by both styles. + Widget _metadataSectionSurface( + BuildContext context, + ColorScheme scheme, { + required Widget child, + }) { + if (context.isMornye) { + return Material( + color: MornyeTheme.controlFill(context), + // The radius of Mornye's grouped lists (see SettingsGroup). + borderRadius: BorderRadius.circular(28), + clipBehavior: Clip.antiAlias, + child: DividerTheme( + data: DividerTheme.of( + context, + ).copyWith(color: MornyeTheme.metadataDividerColor(context)), + child: child, + ), + ); + } + return Card( + elevation: 0, + color: settingsGroupColor(context), + shape: _sectionCardShape(context, scheme), + child: child, + ); + } +} diff --git a/lib/screens/track_metadata_lyrics.dart b/lib/screens/track_metadata_lyrics.dart index 7abb1ca82..3169344d3 100644 --- a/lib/screens/track_metadata_lyrics.dart +++ b/lib/screens/track_metadata_lyrics.dart @@ -10,20 +10,14 @@ extension _TrackMetadataLyricsAndSaving on _TrackMetadataScreenState { context, colorScheme, child: Padding( - padding: const EdgeInsets.all(20), + padding: const EdgeInsets.all(_trackMetadataSectionPadding), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Expanded( - child: Text( - context.l10n.trackLyrics, - style: Theme.of(context).textTheme.titleMedium?.copyWith( - fontWeight: FontWeight.w600, - color: colorScheme.onSurface, - ), - ), + child: _buildSectionTitle(context, context.l10n.trackLyrics), ), if (hasDisplayLyrics) AppIconButton( diff --git a/lib/screens/track_metadata_mornye.dart b/lib/screens/track_metadata_mornye.dart deleted file mode 100644 index 2584bd0a6..000000000 --- a/lib/screens/track_metadata_mornye.dart +++ /dev/null @@ -1,199 +0,0 @@ -part of 'track_metadata_screen.dart'; - -extension _TrackMetadataMornye on _TrackMetadataScreenState { - Widget _buildMornyePage(BuildContext context) { - final theme = Theme.of(context); - final scheme = theme.colorScheme; - final artwork = resolveMetadataArtworkSource( - embeddedCoverPath: - _embeddedCoverPreviewPath ?? - DownloadedEmbeddedCoverResolver.resolve(_filePath), - localCoverPath: _localCoverPath, - remoteCoverUrl: _coverUrl, - ); - return GestureDetector( - behavior: HitTestBehavior.translucent, - onHorizontalDragEnd: _handleHorizontalDragEnd, - child: Scaffold( - body: CustomScrollView( - controller: scrollController, - slivers: [ - SliverAppBar( - pinned: true, - centerTitle: true, - title: Text(context.l10n.trackMetadata), - leadingWidth: 64, - leading: Padding( - padding: const EdgeInsetsDirectional.only(start: 16), - child: HeaderCircleButton( - icon: CupertinoIcons.back, - tooltip: MaterialLocalizations.of(context).backButtonTooltip, - onPressed: _popWithMetadataResult, - ), - ), - actionsPadding: const EdgeInsetsDirectional.only(end: 16), - actions: [ - Builder( - builder: (buttonContext) => HeaderCircleButton( - icon: CupertinoIcons.ellipsis, - tooltip: MaterialLocalizations.of(context).showMenuTooltip, - onPressed: () => _showOptionsMenu( - context, - ref, - scheme, - anchor: mornyeMenuAnchor(buttonContext), - ), - ), - ), - ], - ), - SliverToBoxAdapter( - child: Center( - child: ConstrainedBox( - constraints: BoxConstraints( - maxWidth: adaptiveContentMaxWidth( - MediaQuery.sizeOf(context).width, - ), - ), - child: Padding( - padding: const EdgeInsets.fromLTRB(24, 24, 24, 8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Center( - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 320), - child: AspectRatio( - aspectRatio: 1, - child: Hero( - tag: _coverHeroTag, - child: ClipRRect( - borderRadius: BorderRadius.circular(16), - child: PlayerArtwork( - artUri: artwork, - colorScheme: scheme, - iconSize: 80, - cacheWidth: - (320 * - MediaQuery.devicePixelRatioOf( - context, - )) - .round() - .clamp(320, 1280), - ), - ), - ), - ), - ), - ), - const SizedBox(height: 20), - ExplicitTrackTitle( - title: trackName, - explicit: isExplicit, - style: theme.textTheme.titleLarge, - textAlign: TextAlign.center, - maxLines: 2, - overflow: TextOverflow.ellipsis, - ), - const SizedBox(height: 5), - Text( - artistName, - textAlign: TextAlign.center, - style: theme.textTheme.bodyLarge?.copyWith( - color: scheme.onSurfaceVariant, - ), - ), - if (albumName.trim().isNotEmpty) - Text( - albumName, - textAlign: TextAlign.center, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: theme.textTheme.bodyMedium?.copyWith( - color: scheme.onSurfaceVariant, - ), - ), - const SizedBox(height: 12), - // Centered under the title; desktop detail headers - // start the row at the leading edge instead. - Center( - child: HeaderMetaRow( - items: _headerMetadataItems(context), - ), - ), - const SizedBox(height: 16), - // Keep header buttons within the title column. - Center( - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 400), - child: _buildActionButtons( - context, - ref, - scheme, - _fileExists, - ), - ), - ), - if (_fileAccessMessage(context) case final message?) - Padding( - padding: const EdgeInsets.only(top: 16), - child: Text( - message, - style: theme.textTheme.bodyMedium?.copyWith( - color: scheme.error, - ), - ), - ), - ], - ), - ), - ), - ), - ), - SliverToBoxAdapter( - child: Center( - child: ConstrainedBox( - constraints: BoxConstraints( - maxWidth: _trackMetadataContentMaxWidth( - MediaQuery.sizeOf(context).width, - ), - ), - child: _buildAnimatedTrackContent(context, ref, scheme), - ), - ), - ), - SliverToBoxAdapter( - child: SizedBox(height: context.navBarBottomInset), - ), - ], - ), - ), - ); - } - - Widget _metadataSectionSurface( - BuildContext context, - ColorScheme scheme, { - required Widget child, - }) { - if (context.isMornye) { - return Material( - color: MornyeTheme.controlFill(context), - borderRadius: BorderRadius.circular(28), - clipBehavior: Clip.antiAlias, - child: DividerTheme( - data: DividerTheme.of( - context, - ).copyWith(color: MornyeTheme.metadataDividerColor(context)), - child: child, - ), - ); - } - return Card( - elevation: 0, - color: settingsGroupColor(context), - shape: _sectionCardShape(scheme), - child: child, - ); - } -} diff --git a/lib/screens/track_metadata_screen.dart b/lib/screens/track_metadata_screen.dart index e9b16d151..5cf974273 100644 --- a/lib/screens/track_metadata_screen.dart +++ b/lib/screens/track_metadata_screen.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:io'; import 'dart:math' as math; -import 'dart:ui' show ImageFilter; import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart' show defaultTargetPlatform; import 'package:material_ui/material_ui.dart'; @@ -10,6 +9,8 @@ import 'package:mornye/widgets/app_alert_dialog.dart'; import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoButton, CupertinoIcons; import 'package:mornye/widgets/app_bottom_sheet.dart'; +import 'package:mornye/theme/app_motion.dart'; +import 'package:mornye/widgets/app_icon.dart'; import 'package:mornye/widgets/app_icon_button.dart'; import 'package:mornye/widgets/app_loading_indicator.dart'; import 'package:mornye/widgets/app_snack_bar.dart'; @@ -82,8 +83,17 @@ import 'package:mornye/theme/cover_palette.dart' show HeaderPalette; import 'package:mornye/theme/mornye_theme.dart'; import 'package:mornye/theme/mornye_icons.dart'; import 'package:mornye/widgets/album_detail_header.dart' - show HeaderMetaRow, HeaderMetaItem, HeaderCircleButton, HeaderFilledButton; + show + AlbumDetailHeader, + HeaderMetaRow, + HeaderMetaItem, + HeaderCircleButton, + HeaderFilledButton; import 'package:mornye/widgets/desktop/context_menu.dart'; +import 'package:mornye/widgets/desktop/detail_header.dart' + show desktopDetailSubtitleStyle; +import 'package:mornye/widgets/error_card.dart'; +import 'package:mornye/widgets/expressive_button_group.dart'; import 'package:mornye/widgets/link/link_actions.dart'; import 'package:mornye/widgets/link/link_library_actions.dart'; import 'package:mornye/services/link/features/link_track_refs.dart'; @@ -91,10 +101,9 @@ import 'package:mornye/services/link/link_library_jobs.dart'; import 'package:mornye/services/link/link_protocol.dart'; import 'package:mornye/widgets/mornye_context_menu.dart'; import 'package:mornye/widgets/mornye_metadata_row.dart'; -import 'package:mornye/widgets/player_artwork.dart'; import 'package:mornye/widgets/audio_analysis_widget.dart'; +import 'package:mornye/widgets/audio_quality_badges.dart' show ExplicitBadge; import 'package:mornye/widgets/hires_check_card.dart'; -import 'package:mornye/widgets/audio_quality_badges.dart'; import 'package:mornye/widgets/batch_convert_sheet.dart'; import 'package:mornye/widgets/cached_cover_image.dart'; import 'package:mornye/widgets/open_on_platform_sheet.dart'; @@ -115,7 +124,7 @@ import 'package:mornye/screens/track_metadata_edit_sheet.dart'; part 'track_metadata_screen_cover.dart'; part 'track_metadata_screen_display.dart'; part 'track_metadata_screen_menu.dart'; -part 'track_metadata_mornye.dart'; +part 'track_metadata_header.dart'; part 'track_metadata_cards.dart'; part 'track_metadata_lyrics.dart'; @@ -129,8 +138,15 @@ class _MetadataItem { final String value; final String rawValue; - _MetadataItem(this.label, this.value, {String? rawValue}) - : rawValue = rawValue ?? value; + /// Whether a tap copies the value, for identifiers people paste elsewhere. + final bool copyable; + + _MetadataItem( + this.label, + this.value, { + String? rawValue, + this.copyable = false, + }) : rawValue = rawValue ?? value; } class _EmbeddedCoverPreviewCacheEntry { @@ -308,13 +324,8 @@ class _TrackMetadataScreenState extends ConsumerState @override double calculateExpandedHeight(BuildContext context) { - final mediaSize = MediaQuery.sizeOf(context); - // Desktop windows are wide and short, so the header takes more of the - // height to leave the cover room (see _buildHeaderBackground). - if (isDesktopPlatform) { - return (mediaSize.height * 0.62).clamp(440.0, 640.0); - } - return (mediaSize.height * 0.55).clamp(360.0, 520.0); + // The header of an album, plus the line that names the song's album. + return collectionHeaderExpandedHeight(context) + 20; } Future _checkFile() async { @@ -793,11 +804,8 @@ class _TrackMetadataScreenState extends ConsumerState @override Widget build(BuildContext context) { - if (context.isMornye) return _buildMornyePage(context); final colorScheme = Theme.of(context).colorScheme; - final expandedHeight = calculateExpandedHeight(context); final bottomInset = context.navBarBottomInset; - final edgeInset = detailHeaderEdgeInset(context); return GestureDetector( behavior: HitTestBehavior.translucent, @@ -806,81 +814,7 @@ class _TrackMetadataScreenState extends ConsumerState body: CustomScrollView( controller: scrollController, slivers: [ - SliverAppBar( - expandedHeight: expandedHeight, - pinned: true, - stretch: true, - backgroundColor: colorScheme.surface, - surfaceTintColor: Colors.transparent, - title: ValueListenableBuilder( - valueListenable: showTitleNotifier, - builder: (_, showTitle, title) => AnimatedOpacity( - duration: const Duration(milliseconds: 200), - opacity: showTitle ? 1.0 : 0.0, - child: title, - ), - child: ExplicitTrackTitle( - title: trackName, - explicit: isExplicit, - style: TextStyle( - color: colorScheme.onSurface, - fontWeight: FontWeight.w600, - fontSize: 16, - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - flexibleSpace: LayoutBuilder( - builder: (context, constraints) { - final collapseRatio = - (constraints.maxHeight - kToolbarHeight) / - (expandedHeight - kToolbarHeight); - final showContent = collapseRatio > 0.3; - - return FlexibleSpaceBar( - collapseMode: CollapseMode.pin, - background: _buildHeaderBackground( - context, - colorScheme, - expandedHeight, - showContent, - ), - stretchModes: const [StretchMode.zoomBackground], - ); - }, - ), - leadingWidth: kToolbarHeight + edgeInset, - leading: Padding( - padding: EdgeInsetsDirectional.only(start: edgeInset), - // Centered so the tight leading slot cannot stretch it. - child: Center( - child: HeaderCircleButton( - icon: Icons.arrow_back, - tooltip: MaterialLocalizations.of( - context, - ).backButtonTooltip, - onPressed: _popWithMetadataResult, - ), - ), - ), - actionsPadding: EdgeInsetsDirectional.only(end: edgeInset), - actions: [ - Builder( - builder: (buttonContext) => HeaderCircleButton( - icon: Icons.more_vert, - tooltip: MaterialLocalizations.of(context).showMenuTooltip, - onPressed: () => _showOptionsMenu( - context, - ref, - colorScheme, - anchor: mornyeMenuAnchor(buttonContext), - ), - ), - ), - ], - ), - + ..._buildHeader(context, colorScheme), SliverToBoxAdapter( child: Center( child: ConstrainedBox( @@ -928,82 +862,6 @@ class _TrackMetadataScreenState extends ConsumerState ), ); } - - Widget _buildActionButtons( - BuildContext context, - WidgetRef ref, - ColorScheme colorScheme, - bool fileExists, - ) { - if (context.isMornye) { - return Row( - children: [ - Expanded( - child: HeaderFilledButton( - icon: CupertinoIcons.play_fill, - label: context.l10n.trackMetadataPlay, - onPressed: fileExists - ? () => _openFile(context, rawFilePath) - : null, - ), - ), - if (_canDeleteFile) ...[ - const SizedBox(width: 12), - Expanded( - child: HeaderFilledButton( - icon: CupertinoIcons.trash, - label: context.l10n.trackMetadataDelete, - onPressed: () => _confirmDelete(context, ref, colorScheme), - ), - ), - ], - ], - ); - } - return Row( - children: [ - Expanded( - flex: 2, - child: ExpressiveButton( - onPressed: fileExists - ? () => _openFile(context, rawFilePath) - : null, - icon: const Icon(Icons.play_arrow), - style: FilledButton.styleFrom( - padding: const EdgeInsets.symmetric(vertical: 16), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - ), - ), - child: Text(context.l10n.trackMetadataPlay), - ), - ), - if (_canDeleteFile) ...[ - const SizedBox(width: 12), - Expanded( - child: ExpressiveButton( - outlined: true, - onPressed: () => _confirmDelete(context, ref, colorScheme), - icon: Icon(Icons.delete_outline, color: colorScheme.error), - style: OutlinedButton.styleFrom( - padding: const EdgeInsets.symmetric(vertical: 16), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - ), - side: BorderSide( - color: colorScheme.error.withValues(alpha: 0.5), - ), - ), - child: Text( - context.l10n.trackMetadataDelete, - style: TextStyle(color: colorScheme.error), - ), - ), - ), - ], - ], - ); - } } class _MetadataOption { diff --git a/test/track_metadata_header_contrast_test.dart b/test/track_metadata_header_contrast_test.dart index 54a2f0a0d..13bc04fd9 100644 --- a/test/track_metadata_header_contrast_test.dart +++ b/test/track_metadata_header_contrast_test.dart @@ -9,6 +9,7 @@ import 'package:mornye/l10n/l10n.dart'; import 'package:mornye/providers/download_history_provider.dart'; import 'package:mornye/screens/track_metadata_screen.dart'; import 'package:mornye/services/library_database.dart'; +import 'package:mornye/theme/cover_palette.dart' show HeaderPalette; import 'package:mornye/widgets/album_detail_header.dart'; import 'package:mornye/widgets/audio_quality_badges.dart'; import 'package:mornye/theme/mornye_theme.dart'; @@ -115,6 +116,13 @@ void main() { expect(find.byIcon(CupertinoIcons.back), findsOneWidget); expect(find.byIcon(CupertinoIcons.ellipsis), findsOneWidget); expect(find.byType(Card), findsNothing); + // The sections are built as they scroll in, below the header. + await tester.scrollUntilVisible( + find.text('Track name'), + 300, + scrollable: find.byType(Scrollable).first, + ); + await tester.pumpAndSettle(); final row = find.widgetWithText(MornyeMetadataRow, 'Track name'); expect( find.ancestor(of: row, matching: find.byType(MornyeGlass)), @@ -187,13 +195,23 @@ void main() { final headerMeta = find.byType(HeaderMetaRow); expect(headerMeta, findsOneWidget); - expect(find.byType(ExplicitBadge), findsNWidgets(2)); + expect( + find.descendant(of: headerMeta, matching: find.byType(ExplicitBadge)), + findsOneWidget, + ); expect(find.text('Explicit'), findsNothing); + // The header takes its colors from the artwork over the theme's surface, + // so the details are dark on light here instead of white on a scrim. + final scheme = HeaderPalette.of(tester.element(headerMeta)); + expect( + scheme.surface.computeLuminance() - scheme.onSurface.computeLuminance(), + greaterThan(0.5), + ); for (final label in const ['16-bit/44.1kHz', '4:10', 'Provider-a']) { final text = tester.widget( find.descendant(of: headerMeta, matching: find.text(label)), ); - expect(text.style?.color, Colors.white); + expect(text.style?.color, scheme.onSurface); } final separators = tester.widgetList( @@ -201,10 +219,15 @@ void main() { ); expect(separators, isNotEmpty); expect( - separators.every((text) => text.style?.color == Colors.white70), + separators.every((text) => text.style?.color == scheme.onSurfaceVariant), isTrue, ); + await tester.scrollUntilVisible( + find.text('Duration'), + 300, + scrollable: find.byType(Scrollable).first, + ); final durationLabel = find.text('Duration'); final metadataRow = find .ancestor(of: durationLabel, matching: find.byType(Row)) diff --git a/test/track_metadata_playback_test.dart b/test/track_metadata_playback_test.dart index 2362bad1f..3e4f42f0e 100644 --- a/test/track_metadata_playback_test.dart +++ b/test/track_metadata_playback_test.dart @@ -35,6 +35,11 @@ class _Player extends MusicPlayerController { @override Future playSingle(PlayableMedia item) async => played.add(item); + + final queued = []; + + @override + Future addToQueue(PlayableMedia item) async => queued.add(item); } void main() { @@ -136,12 +141,7 @@ void main() { ), ); } else { - await tester.scrollUntilVisible( - find.text('Play').hitTestable(), - 300, - scrollable: find.byType(Scrollable).first, - ); - await tester.pumpAndSettle(); + // Play is in the header, on the first screen. await tester.tap(find.text('Play')); } await tester.pumpAndSettle(); @@ -181,5 +181,67 @@ void main() { } } } + + for (final exists in [true, false]) { + testWidgets('metadata header holds the song actions ' + '(Mornye=$mornye, file exists=$exists)', (tester) async { + await tester.binding.setSurfaceSize(const Size(393, 852)); + addTearDown(() => tester.binding.setSurfaceSize(null)); + if (!exists) { + messenger.setMockMethodCallHandler(channel, (call) async { + return switch (call.method) { + 'safStat' => jsonEncode({'exists': false}), + _ => null, + }; + }); + } + final player = _Player(); + await tester.pumpWidget( + ProviderScope( + overrides: [ + settingsProvider.overrideWith(_Settings.new), + musicPlayerControllerProvider.overrideWithValue(player), + ], + child: MaterialApp( + theme: mornye + ? MornyeTheme.build(Brightness.dark) + : AppTheme.dark(), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: TrackMetadataScreen( + localItem: LocalLibraryItem( + id: 'local-song', + trackName: 'Song', + artistName: 'Artist', + albumName: 'Album', + filePath: 'content://library/document/song.flac', + scannedAt: DateTime(2026), + format: 'flac', + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + + // Play stays where it is; the round actions need the file. + expect(find.text('Play'), findsOneWidget); + final round = exists ? findsOneWidget : findsNothing; + expect(findByTooltip('Edit Metadata'), round); + expect(findByTooltip('Add to queue'), round); + // Delete is kept to the More menu. + expect(find.text('Delete'), findsNothing); + + await tester.tap(find.text('Play')); + await tester.pumpAndSettle(); + expect(player.played, hasLength(exists ? 1 : 0)); + if (exists) { + await tester.tap(findByTooltip('Add to queue')); + await tester.pumpAndSettle(); + expect(player.queued.single.title, 'Song'); + } + expect(tester.takeException(), isNull); + }); + } } } diff --git a/test/track_metadata_sidecar_export_test.dart b/test/track_metadata_sidecar_export_test.dart index 39227617b..403bbe165 100644 --- a/test/track_metadata_sidecar_export_test.dart +++ b/test/track_metadata_sidecar_export_test.dart @@ -225,6 +225,9 @@ void main() { ); await tester.pumpAndSettle(); expect(find.text(label), findsOneWidget); + // A long menu scrolls, and these rows start below its fold. + await tester.ensureVisible(find.text(label)); + await tester.pumpAndSettle(); await tester.tap(find.text(label)); await _settleIo(tester); expect( diff --git a/test/track_metadata_wide_layout_test.dart b/test/track_metadata_wide_layout_test.dart index 39ca7f62c..dd5471ab8 100644 --- a/test/track_metadata_wide_layout_test.dart +++ b/test/track_metadata_wide_layout_test.dart @@ -39,9 +39,8 @@ void main() { await tester.pump(); await tester.pump(const Duration(milliseconds: 300)); - // Mornye also names the page "Metadata" in its navigation bar. - final metadata = tester.getTopLeft(find.text('Metadata').last); - final lyrics = tester.getTopLeft(find.text('Lyrics').last); + final metadata = tester.getTopLeft(find.text('Metadata')); + final lyrics = tester.getTopLeft(find.text('Lyrics')); if (twoColumns) { expect(lyrics.dx, greaterThan(metadata.dx + 400)); expect(lyrics.dy, moreOrLessEquals(metadata.dy, epsilon: 1));