From 015accd0ab8d8ec6da4ed2a606cda377bd89df29 Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:00:12 +0700 Subject: [PATCH] feat(library): mark the current song on Mornye rows and open CUE tracks on a tap Mornye rows marked the current song only through the play button's pause glyph, which the info button replaces when a tap plays. Show the current song's title in the accent on Mornye track rows instead, in the Library, search, playlists and catalog lists. A CUE virtual track cannot play before it is split, so its tap opens the details whatever the "Tapping a song" setting, and its button stays the play button. --- lib/screens/library_tracks_folder_screen.dart | 13 ++--- lib/screens/local_album_screen.dart | 1 + lib/screens/queue_tab_item_widgets.dart | 29 +++++----- lib/widgets/album_track_tile.dart | 7 ++- lib/widgets/library_directory_view.dart | 8 ++- lib/widgets/library_search_results.dart | 9 ++-- lib/widgets/song_row_tap.dart | 18 +++++-- lib/widgets/track_card.dart | 9 +++- lib/widgets/track_list_tile.dart | 13 ++--- test/library_song_tap_settings_test.dart | 54 +++++++++++++++++++ test/now_playing_catalog_rows_test.dart | 26 +++++++-- test/now_playing_rows_test.dart | 10 +++- 12 files changed, 148 insertions(+), 49 deletions(-) diff --git a/lib/screens/library_tracks_folder_screen.dart b/lib/screens/library_tracks_folder_screen.dart index 9ea84b8e5..738365474 100644 --- a/lib/screens/library_tracks_folder_screen.dart +++ b/lib/screens/library_tracks_folder_screen.dart @@ -18,7 +18,6 @@ import 'package:mornye/widgets/song_row_tap.dart'; import 'package:mornye/widgets/track_card.dart'; import 'package:mornye/widgets/queue_swipe.dart'; import 'package:mornye/widgets/app_snack_bar.dart'; -import 'package:mornye/theme/mornye_theme.dart'; import 'package:share_plus/share_plus.dart' show ShareParams, SharePlus, XFile; import 'package:mornye/widgets/album_detail_header.dart'; import 'package:mornye/widgets/cached_cover_image.dart'; @@ -1356,13 +1355,11 @@ class _CollectionTrackTile extends ConsumerWidget { final heroTag = inMemoryHistoryItem != null ? 'cover_${inMemoryHistoryItem.id}' : null; - // Material rows mark the current track; Mornye rows show no - // current-track state. - final playback = context.isMornye - ? null - : ref.watch(catalogTrackPlaybackUiProvider(catalogTrackKey(track))); - final isCurrent = playback?.isCurrent ?? false; - final isPlaying = playback?.isPlaying ?? false; + final playback = ref.watch( + catalogTrackPlaybackUiProvider(catalogTrackKey(track)), + ); + final isCurrent = playback.isCurrent; + final isPlaying = playback.isPlaying; final hasFile = isInHistory || isInLocalLibrary; // Songs with a file queue as the selection bar queues them. final queueSwipe = hasFile diff --git a/lib/screens/local_album_screen.dart b/lib/screens/local_album_screen.dart index 7c76b7c26..22a71e253 100644 --- a/lib/screens/local_album_screen.dart +++ b/lib/screens/local_album_screen.dart @@ -859,6 +859,7 @@ class _LocalAlbumScreenState extends ConsumerState ); final isPlaying = isCurrent && ref.watch(playbackPlayingProvider); return AlbumTrackTile( + filePath: track.filePath, isCurrent: isCurrent, isPlaying: isPlaying, trackNumber: track.trackNumber, diff --git a/lib/screens/queue_tab_item_widgets.dart b/lib/screens/queue_tab_item_widgets.dart index f8f591b2a..5b1948cf6 100644 --- a/lib/screens/queue_tab_item_widgets.dart +++ b/lib/screens/queue_tab_item_widgets.dart @@ -983,6 +983,7 @@ extension _QueueTabItemWidgets on _QueueTabState { if (item == null) return; songRowTap( ref, + path: item.filePath, openDetails: openAction(item), play: () => _LibraryPlaybackButton.run( ref, @@ -1087,6 +1088,7 @@ extension _QueueTabItemWidgets on _QueueTabState { (_songTableByMode[filterMode]?.openAction ?? openAction)( item, )(), + path: item.filePath, ), ), playback: mediaItemPlaybackUiProvider(_libraryPlaybackKey(item)), @@ -1227,6 +1229,7 @@ extension _QueueTabItemWidgets on _QueueTabState { // A song whose file is missing has no play action and keeps opening. final tap = songRowTap( ref, + path: item.filePath, openDetails: open, play: () => fileExistsListenable.value ? _LibraryPlaybackButton.run(ref, playbackKey, play) @@ -1246,6 +1249,7 @@ extension _QueueTabItemWidgets on _QueueTabState { onPlay: play, ), onOpenDetails: open, + path: item.filePath, ); } return Tooltip( @@ -1292,21 +1296,14 @@ extension _QueueTabItemWidgets on _QueueTabState { return Semantics( label: context.l10n.a11yTrackByArtist(item.trackName, item.artistName), selected: isSelected, - // Material rows follow their own file, so a track change rebuilds only - // the rows involved. Mornye rows show no current-track state. - child: context.isMornye - ? card() - : Consumer( - builder: (context, ref, _) { - final playback = ref.watch( - mediaItemPlaybackUiProvider(playbackKey), - ); - return card( - current: playback.isCurrent, - playing: playback.isPlaying, - ); - }, - ), + // Rows follow their own file, so a track change rebuilds only the rows + // involved. + child: Consumer( + builder: (context, ref, _) { + final playback = ref.watch(mediaItemPlaybackUiProvider(playbackKey)); + return card(current: playback.isCurrent, playing: playback.isPlaying); + }, + ), ); } @@ -1338,6 +1335,7 @@ extension _QueueTabItemWidgets on _QueueTabState { // A song whose file is missing has no play action and keeps opening. final tap = songRowTap( ref, + path: item.filePath, openDetails: open, play: () => fileExistsListenable.value ? _LibraryPlaybackButton.run(ref, playbackKey, play) @@ -1421,6 +1419,7 @@ extension _QueueTabItemWidgets on _QueueTabState { ), onOpenDetails: open, size: SongRowButtonSize.grid, + path: item.filePath, ); } return Tooltip( diff --git a/lib/widgets/album_track_tile.dart b/lib/widgets/album_track_tile.dart index d97128284..56f1a300f 100644 --- a/lib/widgets/album_track_tile.dart +++ b/lib/widgets/album_track_tile.dart @@ -30,6 +30,7 @@ class AlbumTrackTile extends ConsumerWidget { this.isCurrent = false, this.isPlaying = false, this.queueSwipe, + this.filePath, }); final int? trackNumber; @@ -51,6 +52,9 @@ class AlbumTrackTile extends ConsumerWidget { /// See [TrackCard.queueSwipe]. final QueueSwipeActions? queueSwipe; + /// The track's file. A CUE virtual track's tap opens it ([songRowTap]). + final String? filePath; + @override Widget build(BuildContext context, WidgetRef ref) { return TrackCard( @@ -62,7 +66,7 @@ class AlbumTrackTile extends ConsumerWidget { isPlaying: isPlaying, onTap: isSelectionMode ? onToggleSelection - : songRowTap(ref, openDetails: onOpen, play: onPlay), + : songRowTap(ref, path: filePath, openDetails: onOpen, play: onPlay), onLongPress: isSelectionMode ? null : onEnterSelectionMode, leading: SizedBox( width: 24, @@ -78,6 +82,7 @@ class AlbumTrackTile extends ConsumerWidget { trailing: SongRowButton( playButton: AlbumTrackPlayButton(isPlaying: isPlaying, onPlay: onPlay), onOpenDetails: onOpen, + path: filePath, ), ); } diff --git a/lib/widgets/library_directory_view.dart b/lib/widgets/library_directory_view.dart index e91d61fc3..fa2dc386f 100644 --- a/lib/widgets/library_directory_view.dart +++ b/lib/widgets/library_directory_view.dart @@ -873,12 +873,18 @@ class _LibraryDirectoryViewState extends ConsumerState onPressed: play, ), onOpenDetails: openDetails, + path: item.filePath, ), isSelectionMode: isSelectionMode, isSelected: selectedIds.contains(item.id), onTap: isSelectionMode ? () => toggleSelection(item.id) - : songRowTap(ref, openDetails: openDetails, play: play), + : songRowTap( + ref, + path: item.filePath, + openDetails: openDetails, + play: play, + ), onLongPress: isSelectionMode ? () => toggleSelection(item.id) : () => enterSelectionMode(item.id), diff --git a/lib/widgets/library_search_results.dart b/lib/widgets/library_search_results.dart index fe515d938..29477878b 100644 --- a/lib/widgets/library_search_results.dart +++ b/lib/widgets/library_search_results.dart @@ -502,6 +502,7 @@ class _LibrarySearchResultsState extends ConsumerState { onPressed: play(playback), ), onOpenDetails: () => _open(hit), + path: hit.samplePath, ) : const Icon(Icons.chevron_right), // Long-press selects songs for the Library batch actions; while @@ -512,6 +513,7 @@ class _LibrarySearchResultsState extends ConsumerState { ? song ? songRowTap( ref, + path: hit.samplePath, openDetails: () => _open(hit), play: play(playback), ) @@ -523,10 +525,9 @@ class _LibrarySearchResultsState extends ConsumerState { onContextMenu: (position) => _showHitMenu(hit, position), queueSwipe: swipe, ); - if (!song || context.isMornye) return card(); - // Material song rows follow the file they play, so a track change - // rebuilds only the rows involved. Mornye rows show no current-track - // state. + if (!song) return card(); + // Song rows follow the file they play, so a track change rebuilds only + // the rows involved. return Consumer( key: key, builder: (context, ref, _) => card( diff --git a/lib/widgets/song_row_tap.dart b/lib/widgets/song_row_tap.dart index bc66069fb..2f1a8b99f 100644 --- a/lib/widgets/song_row_tap.dart +++ b/lib/widgets/song_row_tap.dart @@ -6,6 +6,7 @@ import 'package:mornye/providers/settings_provider.dart'; import 'package:mornye/theme/app_tokens.dart'; import 'package:mornye/theme/mornye_icons.dart'; import 'package:mornye/theme/mornye_theme.dart'; +import 'package:mornye/utils/file_access.dart'; import 'package:mornye/widgets/app_icon.dart'; import 'package:mornye/widgets/app_icon_button.dart'; import 'package:mornye/widgets/track_card.dart'; @@ -27,13 +28,17 @@ final librarySongTapPlaysProvider = Provider( /// read at the tap, so rows built before a change follow it. /// /// Rows without a play action keep their own tap, and selection mode stays -/// with the caller. +/// with the caller. A CUE virtual track at [path] cannot play before it is +/// split, so its tap always opens the details. VoidCallback songRowTap( WidgetRef ref, { required VoidCallback openDetails, required VoidCallback play, + String? path, }) => - () => ref.read(librarySongTapPlaysProvider) ? play() : openDetails(); + () => ref.read(librarySongTapPlaysProvider) && !isCueVirtualPath(path) + ? play() + : openDetails(); /// How a [SongRowButton] lays out its details button. enum SongRowButtonSize { @@ -49,22 +54,27 @@ enum SongRowButtonSize { /// The trailing button of a song row that has both a details page and a play /// button: [playButton], or a details button running [onOpenDetails] while a -/// tap on the row plays (see [songRowTap]). +/// tap on the row plays (see [songRowTap]). A CUE virtual track at [path] +/// keeps [playButton], because its tap opens the details. class SongRowButton extends ConsumerWidget { const SongRowButton({ super.key, required this.playButton, required this.onOpenDetails, this.size = SongRowButtonSize.list, + this.path, }); final Widget playButton; final VoidCallback onOpenDetails; final SongRowButtonSize size; + final String? path; @override Widget build(BuildContext context, WidgetRef ref) { - if (!ref.watch(librarySongTapPlaysProvider)) return playButton; + if (!ref.watch(librarySongTapPlaysProvider) || isCueVirtualPath(path)) { + return playButton; + } final tooltip = context.l10n.desktopMenuShowDetails; if (size == SongRowButtonSize.grid) { return TrackGridPlayButton( diff --git a/lib/widgets/track_card.dart b/lib/widgets/track_card.dart index 0308fdf2c..e748f58f6 100644 --- a/lib/widgets/track_card.dart +++ b/lib/widgets/track_card.dart @@ -152,7 +152,8 @@ class TrackCard extends StatelessWidget { /// The row is the player's current track. The Material style fills it with /// `primaryContainer` of the track's artwork scheme ([PlayerArtworkTheme]), /// rounds its ends into a pill and shows a [NowPlayingIndicator] before - /// [trailing]. Mornye ignores it. + /// [trailing]. Mornye keeps the row plain and shows the title in its + /// accent. final bool isCurrent; /// The current track is playing, so the indicator moves. @@ -352,7 +353,11 @@ class TrackCard extends StatelessWidget { fontWeight: current ? FontWeight.w700 : FontWeight.w500, - color: contentColor, + // The accent as status: Mornye's only sign of + // the current track. + color: isCurrent && !material + ? colorScheme.primary + : contentColor, ), ), if (subtitle != null) ...[ diff --git a/lib/widgets/track_list_tile.dart b/lib/widgets/track_list_tile.dart index 084e197e5..3ae69016f 100644 --- a/lib/widgets/track_list_tile.dart +++ b/lib/widgets/track_list_tile.dart @@ -5,7 +5,6 @@ import 'package:mornye/providers/download_queue_provider.dart'; import 'package:mornye/providers/local_library_provider.dart'; import 'package:mornye/providers/music_player_provider.dart'; import 'package:mornye/providers/settings_provider.dart'; -import 'package:mornye/theme/mornye_theme.dart'; import 'package:mornye/controllers/clickable_metadata.dart'; import 'package:mornye/controllers/local_playback.dart'; import 'package:mornye/widgets/audio_quality_badges.dart'; @@ -52,11 +51,9 @@ class TrackListTile extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final colorScheme = Theme.of(context).colorScheme; - // Material rows mark the current track; Mornye rows show no - // current-track state. - final playback = context.isMornye - ? null - : ref.watch(catalogTrackPlaybackUiProvider(catalogTrackKey(track))); + final playback = ref.watch( + catalogTrackPlaybackUiProvider(catalogTrackKey(track)), + ); final isQueued = ref.watch( downloadQueueLookupProvider.select( @@ -85,8 +82,8 @@ class TrackListTile extends ConsumerWidget { style: TrackCardStyle.flat, isSelectionMode: isSelectionMode, isSelected: isSelected, - isCurrent: playback?.isCurrent ?? false, - isPlaying: playback?.isPlaying ?? false, + isCurrent: playback.isCurrent, + isPlaying: playback.isPlaying, leadingArtwork: leadingArtwork, leading: leading, title: track.name, diff --git a/test/library_song_tap_settings_test.dart b/test/library_song_tap_settings_test.dart index 158d57d1e..96cfc5e90 100644 --- a/test/library_song_tap_settings_test.dart +++ b/test/library_song_tap_settings_test.dart @@ -190,4 +190,58 @@ void main() { ], contains(_title)); }); } + + testWidgets('a CUE virtual track opens its details on a tap and keeps its ' + 'play button', (tester) async { + SharedPreferences.setMockInitialValues({}); + final log = []; + Widget row(String name, String path) => Consumer( + builder: (context, ref, _) => Row( + children: [ + TextButton( + onPressed: songRowTap( + ref, + path: path, + openDetails: () => log.add('details $name'), + play: () => log.add('play $name'), + ), + child: Text('row $name'), + ), + SongRowButton( + path: path, + playButton: Text('play button $name'), + onOpenDetails: () {}, + ), + ], + ), + ); + await tester.pumpWidget( + ProviderScope( + overrides: [ + initialSettingsProvider.overrideWithValue(const AppSettings()), + ], + child: MaterialApp( + theme: AppTheme.light(), + localizationsDelegates: appLocalizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: Scaffold( + body: Column( + children: [ + row('song', '/music/song.flac'), + row('cue', '/music/album.cue#track02'), + ], + ), + ), + ), + ), + ); + await tester.pump(); + + await tester.tap(find.text('row song')); + await tester.tap(find.text('row cue')); + expect(log, ['play song', 'details cue']); + // The song's button opens the details; the CUE track's still plays. + expect(find.text('play button song'), findsNothing); + expect(find.text('play button cue'), findsOneWidget); + }); } diff --git a/test/now_playing_catalog_rows_test.dart b/test/now_playing_catalog_rows_test.dart index db5e56d4e..ce45ed911 100644 --- a/test/now_playing_catalog_rows_test.dart +++ b/test/now_playing_catalog_rows_test.dart @@ -164,6 +164,19 @@ TrackCard _card(WidgetTester tester, String title) => tester.widget( find.ancestor(of: find.text(title), matching: find.byType(TrackCard)), ); +/// Mornye marks the current row with its title's colour alone. +void _expectOnlyCurrentAccented(WidgetTester tester) { + Color? titleColor(String title) => + tester.widget(find.text(title)).style?.color; + final accent = Theme.of( + tester.element(find.text('Current song')), + ).colorScheme.primary; + expect(titleColor('Current song'), accent); + expect(titleColor('Other song'), isNot(accent)); + expect(titleColor('Same id song'), isNot(accent)); + expect(find.byType(NowPlayingIndicator), findsNothing); +} + void _expectOnlyCurrentMarked(WidgetTester tester) { expect(_card(tester, 'Current song').isCurrent, isTrue); expect(_card(tester, 'Other song').isCurrent, isFalse); @@ -205,11 +218,12 @@ void main() { expect(find.byType(NowPlayingIndicator), findsNothing); }); - testWidgets('Mornye rows show no current-track state', (tester) async { + testWidgets('Mornye rows show only the current title in the accent', ( + tester, + ) async { await tester.pumpWidget(_app(list(), mornye: true)); await _pumpFor(tester); - expect(_card(tester, 'Current song').isCurrent, isFalse); - expect(find.byType(NowPlayingIndicator), findsNothing); + _expectOnlyCurrentAccented(tester); }); }); @@ -370,7 +384,9 @@ void main() { }); } - testWidgets('Mornye rows show no current-track state', (tester) async { + testWidgets('Mornye rows show only the current title in the accent', ( + tester, + ) async { await tester.pumpWidget( _app( results(), @@ -380,7 +396,7 @@ void main() { ), ); await _pumpFor(tester); - expect(find.byType(NowPlayingIndicator), findsNothing); + _expectOnlyCurrentAccented(tester); }); }); } diff --git a/test/now_playing_rows_test.dart b/test/now_playing_rows_test.dart index 3c79f0e85..984e17008 100644 --- a/test/now_playing_rows_test.dart +++ b/test/now_playing_rows_test.dart @@ -578,7 +578,9 @@ void main() { expect(find.byType(NowPlayingIndicator), findsOneWidget); }); - testWidgets('Mornye ignores the current track', (tester) async { + testWidgets('Mornye shows the current track in its title colour alone', ( + tester, + ) async { await tester.pumpWidget(_app(card(current: true), mornye: true)); await tester.pump(); @@ -588,6 +590,12 @@ void main() { ); expect(surface.color, Colors.transparent); expect(_textStyle(tester, 'Song')?.fontWeight, FontWeight.w500); + final accent = _scheme(tester, find.text('Song')).primary; + expect(_textStyle(tester, 'Song')?.color, accent); + + await tester.pumpWidget(_app(card(), mornye: true)); + await tester.pump(); + expect(_textStyle(tester, 'Song')?.color, isNot(accent)); }); testWidgets('Mornye keeps its selection tint', (tester) async {