This commit is contained in:
Forrest 2026-08-04 16:08:51 -04:00
parent d558aba246
commit 3bd713d667
17 changed files with 1566 additions and 132 deletions

View file

@ -28,7 +28,9 @@ class _AddToPlaylistSheet extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final accent = Theme.of(context).colorScheme.primary;
final playlists = ref.watch(realPlaylistsProvider);
// Only your own playlists — the server rejects adding tracks to another
// user's shared playlist.
final playlists = ref.watch(myPlaylistsProvider);
final connected = ref.watch(subsonicClientProvider) != null;
return SafeArea(

View file

@ -0,0 +1,370 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../settings/settings_store.dart';
import '../state/providers.dart';
import '../theme/tokens.dart';
/// Filter/sort chip bar for the Albums browse grid. Sort is persisted; the
/// genre/year filters are session-only (see `state/providers.dart`).
class AlbumControlBar extends ConsumerWidget {
const AlbumControlBar({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final sort = ref.watch(settingsProvider.select((s) => s.albumSort));
final filter = ref.watch(albumFilterProvider);
final genres = ref.watch(albumGenresProvider);
final years = ref.watch(albumYearsProvider);
return _ControlBar(
children: [
_ControlChip(
label: 'Sort: ${AppSettings.albumSortLabel(sort)}',
onTap: () async {
final picked = await _showPicker<AlbumSort>(
context,
title: 'Sort albums',
current: sort,
options: [
for (final s in AlbumSort.values)
_Opt(AppSettings.albumSortLabel(s), s),
],
);
if (picked != null) {
ref.read(settingsProvider.notifier).setAlbumSort(picked.value);
}
},
),
_ControlChip(
label: filter.genre ?? 'Genre',
active: filter.genre != null,
onTap: genres.isEmpty
? null
: () async {
final picked = await _showPicker<String?>(
context,
title: 'Filter by genre',
current: filter.genre,
options: [
const _Opt('All genres', null),
for (final g in genres) _Opt(g, g),
],
);
if (picked != null) {
ref.read(albumFilterProvider.notifier).state =
filter.copyWith(genre: picked.value);
}
},
),
_ControlChip(
label: filter.year?.toString() ?? 'Year',
active: filter.year != null,
onTap: years.isEmpty
? null
: () async {
final picked = await _showPicker<int?>(
context,
title: 'Filter by year',
current: filter.year,
options: [
const _Opt('All years', null),
for (final y in years) _Opt('$y', y),
],
);
if (picked != null) {
ref.read(albumFilterProvider.notifier).state =
filter.copyWith(year: picked.value);
}
},
),
if (filter.isActive)
_ClearChip(onTap: () => ref.read(albumFilterProvider.notifier).state =
const BrowseFilter()),
],
);
}
}
/// Filter/sort chip bar for the Tracks browse list.
class TrackControlBar extends ConsumerWidget {
const TrackControlBar({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final sort = ref.watch(settingsProvider.select((s) => s.trackSort));
final filter = ref.watch(trackFilterProvider);
final genres = ref.watch(trackGenresProvider);
final years = ref.watch(trackYearsProvider);
return _ControlBar(
children: [
_ControlChip(
label: 'Sort: ${AppSettings.trackSortLabel(sort)}',
onTap: () async {
final picked = await _showPicker<TrackSort>(
context,
title: 'Sort tracks',
current: sort,
options: [
for (final s in TrackSort.values)
_Opt(AppSettings.trackSortLabel(s), s),
],
);
if (picked != null) {
ref.read(settingsProvider.notifier).setTrackSort(picked.value);
}
},
),
_ControlChip(
label: filter.genre ?? 'Genre',
active: filter.genre != null,
onTap: genres.isEmpty
? null
: () async {
final picked = await _showPicker<String?>(
context,
title: 'Filter by genre',
current: filter.genre,
options: [
const _Opt('All genres', null),
for (final g in genres) _Opt(g, g),
],
);
if (picked != null) {
ref.read(trackFilterProvider.notifier).state =
filter.copyWith(genre: picked.value);
}
},
),
_ControlChip(
label: filter.year?.toString() ?? 'Year',
active: filter.year != null,
onTap: years.isEmpty
? null
: () async {
final picked = await _showPicker<int?>(
context,
title: 'Filter by year',
current: filter.year,
options: [
const _Opt('All years', null),
for (final y in years) _Opt('$y', y),
],
);
if (picked != null) {
ref.read(trackFilterProvider.notifier).state =
filter.copyWith(year: picked.value);
}
},
),
if (filter.isActive)
_ClearChip(onTap: () => ref.read(trackFilterProvider.notifier).state =
const BrowseFilter()),
],
);
}
}
/// Horizontally-scrolling row of control chips.
class _ControlBar extends StatelessWidget {
const _ControlBar({required this.children});
final List<Widget> children;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: TimbreSpacing.md),
child: Row(
children: [
for (var i = 0; i < children.length; i++) ...[
if (i > 0) const SizedBox(width: TimbreSpacing.sm),
children[i],
],
],
),
);
}
}
/// A bordered dropdown-style chip; tints toward accent when [active] (a filter
/// is applied). A null [onTap] renders it disabled/dimmed.
class _ControlChip extends StatelessWidget {
const _ControlChip({
required this.label,
required this.onTap,
this.active = false,
});
final String label;
final VoidCallback? onTap;
final bool active;
@override
Widget build(BuildContext context) {
final accent = Theme.of(context).colorScheme.primary;
final enabled = onTap != null;
final fg = !enabled
? TimbreColors.dimmed
: (active ? accent : TimbreColors.foreground);
return InkWell(
onTap: onTap,
child: Container(
constraints:
const BoxConstraints(minHeight: TimbreSpacing.minTouchTarget),
padding: const EdgeInsets.symmetric(
horizontal: TimbreSpacing.md,
vertical: TimbreSpacing.sm,
),
decoration: BoxDecoration(
border: Border.all(color: active ? accent : TimbreColors.border),
color:
active ? accent.withValues(alpha: 0.12) : TimbreColors.surface,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(label,
style: TextStyle(
color: fg,
fontWeight: active ? FontWeight.w700 : FontWeight.w400)),
Icon(Icons.arrow_drop_down, size: 18, color: fg),
],
),
),
);
}
}
class _ClearChip extends StatelessWidget {
const _ClearChip({required this.onTap});
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Container(
constraints:
const BoxConstraints(minHeight: TimbreSpacing.minTouchTarget),
padding: const EdgeInsets.symmetric(horizontal: TimbreSpacing.md),
alignment: Alignment.center,
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.close, size: 14, color: TimbreColors.dimmed),
SizedBox(width: TimbreSpacing.xs),
Text('Clear', style: TextStyle(color: TimbreColors.dimmed)),
],
),
),
);
}
}
/// One option in a picker sheet.
class _Opt<T> {
const _Opt(this.label, this.value);
final String label;
final T value;
}
/// Wraps the picked value so a chosen `null` ("All") is distinguishable from a
/// dismissed sheet (which resolves to a bare `null`).
class _Picked<T> {
const _Picked(this.value);
final T value;
}
/// A titled bottom-sheet list picker. Returns the wrapped selection, or null if
/// the sheet was dismissed without a choice.
Future<_Picked<T>?> _showPicker<T>(
BuildContext context, {
required String title,
required List<_Opt<T>> options,
required T current,
}) {
final accent = Theme.of(context).colorScheme.primary;
return showModalBottomSheet<_Picked<T>>(
context: context,
backgroundColor: TimbreColors.background,
isScrollControlled: true,
builder: (ctx) => SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: TimbreSpacing.lg),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: TimbreSpacing.xl),
child: Text(title,
style:
TextStyle(color: accent, fontWeight: FontWeight.w700)),
),
const SizedBox(height: TimbreSpacing.md),
Flexible(
child: ListView(
shrinkWrap: true,
children: [
for (final o in options)
_PickerTile(
label: o.label,
selected: o.value == current,
accent: accent,
onTap: () => Navigator.pop(ctx, _Picked<T>(o.value)),
),
],
),
),
],
),
),
),
);
}
class _PickerTile extends StatelessWidget {
const _PickerTile({
required this.label,
required this.selected,
required this.accent,
required this.onTap,
});
final String label;
final bool selected;
final Color accent;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Container(
constraints:
const BoxConstraints(minHeight: TimbreSpacing.minTouchTarget),
padding: const EdgeInsets.symmetric(
horizontal: TimbreSpacing.xl,
vertical: TimbreSpacing.md,
),
child: Row(
children: [
Expanded(
child: Text(
label,
style: TextStyle(
color: selected ? accent : TimbreColors.foreground,
fontWeight: selected ? FontWeight.w700 : FontWeight.w400,
),
),
),
if (selected) Icon(Icons.check, size: 16, color: accent),
],
),
),
);
}
}

View file

@ -9,6 +9,7 @@ import '../widgets/hairline_panel.dart';
import '../widgets/toast.dart';
import 'add_tag_sheet.dart';
import 'add_to_playlist_sheet.dart';
import 'browse_controls.dart';
import 'downloads_screen.dart';
import 'favorites_screen.dart';
import 'playlists_screen.dart';
@ -188,7 +189,8 @@ class _AlbumsPanel extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final albums = ref.watch(albumsProvider);
final albums = ref.watch(visibleAlbumsProvider);
final filter = ref.watch(albumFilterProvider);
final client = ref.watch(subsonicClientProvider);
return HairlinePanel(
title: 'Albums',
@ -200,34 +202,56 @@ class _AlbumsPanel extends ConsumerWidget {
child: albums.when(
loading: () => const _Centered(child: _Loading()),
error: (e, _) => _Centered(child: _ErrorText('$e')),
data: (list) => list.isEmpty
? const _Centered(child: _ErrorText('No albums on this server.'))
: LayoutBuilder(
builder: (context, constraints) {
final cols = (constraints.maxWidth / 180).floor().clamp(2, 6);
return GridView.builder(
padding: EdgeInsets.zero,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: cols,
mainAxisSpacing: TimbreSpacing.md,
crossAxisSpacing: TimbreSpacing.md,
// Square art + two caption lines; extra vertical slack so
// the tile never sub-pixel-overflows.
childAspectRatio: 0.68,
),
itemCount: list.length,
itemBuilder: (context, i) => _AlbumTile(
album: list[i],
artUri: (client != null && list[i].coverArt != null)
? client
.coverArtUri(list[i].coverArt!, size: 300)
.toString()
: null,
),
);
},
data: (list) {
// Hide the control bar only on a genuinely empty server (nothing to
// filter); keep it visible if a filter is what emptied the list.
final showControls = list.isNotEmpty || filter.isActive;
return Column(
children: [
if (showControls) ...[
const AlbumControlBar(),
const SizedBox(height: TimbreSpacing.md),
],
Expanded(
child: list.isEmpty
? _Centered(
child: _ErrorText(filter.isActive
? 'No albums match these filters.'
: 'No albums on this server.'),
)
: LayoutBuilder(
builder: (context, constraints) {
final cols =
(constraints.maxWidth / 180).floor().clamp(2, 6);
return GridView.builder(
padding: EdgeInsets.zero,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: cols,
mainAxisSpacing: TimbreSpacing.md,
crossAxisSpacing: TimbreSpacing.md,
// Square art + two caption lines; extra vertical
// slack so the tile never sub-pixel-overflows.
childAspectRatio: 0.68,
),
itemCount: list.length,
itemBuilder: (context, i) => _AlbumTile(
album: list[i],
artUri:
(client != null && list[i].coverArt != null)
? client
.coverArtUri(list[i].coverArt!,
size: 300)
.toString()
: null,
),
);
},
),
),
],
);
},
),
);
}
@ -314,6 +338,7 @@ class _TracksPanelState extends ConsumerState<_TracksPanel> {
@override
Widget build(BuildContext context) {
final index = ref.watch(libraryIndexProvider);
final visible = ref.watch(visibleTracksProvider);
final playback = ref.read(playbackProvider.notifier);
final client = ref.watch(subsonicClientProvider);
@ -341,61 +366,132 @@ class _TracksPanelState extends ConsumerState<_TracksPanel> {
);
} else {
final downloads = ref.watch(downloadManagerProvider);
body = ListView.builder(
padding: EdgeInsets.zero,
itemCount: index.songs.length,
itemBuilder: (context, i) {
final song = index.songs[i];
final artUri = (client != null && song.coverArt != null)
? client.coverArtUri(song.coverArt!, size: 128).toString()
: null;
return BrowseRow(
title: song.title ?? 'Untitled',
subtitle: song.artist,
artUri: artUri,
downloadStatus: downloads.byId[song.id]?.status,
onTap: () => playback.playSongs(index.songs, startIndex: i),
onPlayNext: () => playback.playNext(song),
onAddToQueue: () => playback.addToQueue(song),
onAddToPlaylist: () =>
showAddToPlaylistSheet(context, songs: [song]),
onAddToTag: () => showAddTagSheet(context, songs: [song]),
onDownload: () =>
ref.read(downloadManagerProvider.notifier).download(song),
onRemoveDownload: () =>
ref.read(downloadManagerProvider.notifier).remove(song.id),
);
},
body = Column(
children: [
const TrackControlBar(),
const SizedBox(height: TimbreSpacing.md),
Expanded(
child: visible.isEmpty
? const _Centered(
child: _ErrorText('No tracks match these filters.'))
: ListView.builder(
padding: EdgeInsets.zero,
itemCount: visible.length,
itemBuilder: (context, i) {
final song = visible[i];
final artUri = (client != null && song.coverArt != null)
? client
.coverArtUri(song.coverArt!, size: 128)
.toString()
: null;
return BrowseRow(
title: song.title ?? 'Untitled',
subtitle: song.artist,
artUri: artUri,
downloadStatus: downloads.byId[song.id]?.status,
onTap: () =>
playback.playSongs(visible, startIndex: i),
onPlayNext: () => playback.playNext(song),
onAddToQueue: () => playback.addToQueue(song),
onAddToPlaylist: () =>
showAddToPlaylistSheet(context, songs: [song]),
onAddToTag: () =>
showAddTagSheet(context, songs: [song]),
onDownload: () => ref
.read(downloadManagerProvider.notifier)
.download(song),
onRemoveDownload: () => ref
.read(downloadManagerProvider.notifier)
.remove(song.id),
);
},
),
),
],
);
}
return HairlinePanel(
title: 'Tracks',
active: true,
trailing: index.songs.isNotEmpty ? '(${index.songs.length})' : null,
trailing: index.songs.isNotEmpty ? '(${visible.length})' : null,
padding: const EdgeInsets.symmetric(vertical: TimbreSpacing.md),
child: Column(
action: Row(
mainAxisSize: MainAxisSize.min,
children: [
Align(
alignment: Alignment.centerRight,
child: InkWell(
onTap: index.building
? null
: () => ref.read(libraryIndexProvider.notifier).refresh(),
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: TimbreSpacing.lg,
vertical: TimbreSpacing.sm,
),
child: Text('↻ refresh',
style: TextStyle(color: TimbreColors.dimmed)),
),
InkWell(
onTap: index.building
? null
: () => ref.read(libraryIndexProvider.notifier).refresh(),
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: TimbreSpacing.xs),
child: Text('↻ refresh',
style: TextStyle(color: TimbreColors.dimmed, fontSize: 12)),
),
),
Expanded(child: body),
if (visible.isNotEmpty)
PopupMenuButton<String>(
tooltip: 'More',
color: TimbreColors.surface,
padding: EdgeInsets.zero,
onSelected: (value) {
if (value == 'download-all') {
_confirmDownloadAll(context, visible);
}
},
itemBuilder: (_) => const [
PopupMenuItem<String>(
value: 'download-all',
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.download,
size: 16, color: TimbreColors.foreground),
SizedBox(width: TimbreSpacing.sm),
Text('Download all',
style: TextStyle(color: TimbreColors.foreground)),
],
),
),
],
child: const Padding(
padding: EdgeInsets.all(TimbreSpacing.xs),
child: Icon(Icons.more_vert,
size: 18, color: TimbreColors.dimmed),
),
),
],
),
child: body,
);
}
/// Confirm before enqueueing a large batch of tracks — this can be the whole
/// library, so it's gated behind a dialog unlike per-album download-all.
/// [songs] is the currently-visible (filtered/sorted) set.
Future<void> _confirmDownloadAll(
BuildContext context, List<Song> songs) async {
final ok = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: TimbreColors.surface,
title: const Text('Download these tracks?'),
content: Text(
'This queues all ${songs.length} listed tracks for offline '
'download. It may use significant storage and data.'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: const Text('Cancel')),
TextButton(
onPressed: () => Navigator.pop(ctx, true),
child: const Text('Download all')),
],
),
);
if (ok != true || !context.mounted) return;
ref.read(downloadManagerProvider.notifier).downloadAll(songs);
showToast(context, 'Downloading tracks…');
}
}

View file

@ -293,11 +293,16 @@ class _QueuePanelState extends ConsumerState<_QueuePanel> {
title: 'Queue',
trailing: '(${state.queue.length})',
padding: const EdgeInsets.symmetric(vertical: TimbreSpacing.md),
child: ListView.builder(
controller: _controller,
child: ReorderableListView.builder(
scrollController: _controller,
padding: EdgeInsets.zero,
itemExtent: _rowExtent,
itemCount: state.queue.length,
// onReorderItem already reports newIndex as the post-removal target
// index — exactly the convention reorderQueue (and just_audio's
// moveAudioSource) expects — so no off-by-one adjustment is needed.
onReorderItem: (oldIndex, newIndex) =>
ref.read(playbackProvider.notifier).reorderQueue(oldIndex, newIndex),
itemBuilder: (context, i) {
final song = state.queue[i];
final current = state.currentIndex;
@ -307,6 +312,11 @@ class _QueuePanelState extends ConsumerState<_QueuePanel> {
? accent
: (isPast ? TimbreColors.dimmed : TimbreColors.foreground);
return InkWell(
// Position-based key: the same Song instance can legitimately sit in
// the queue twice (e.g. added twice), so an identity key would
// collide and ReorderableListView requires unique keys. These rows
// are stateless, so keying by index leaks no state.
key: ValueKey(i),
onTap: () => ref.read(playbackProvider.notifier).jumpTo(i),
child: Padding(
padding: const EdgeInsets.symmetric(

View file

@ -17,10 +17,15 @@ class PlaylistsScreen extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final playlists = ref.watch(realPlaylistsProvider);
final mine = ref.watch(myPlaylistsProvider);
final shared = ref.watch(sharedPlaylistsProvider);
final controller = ref.read(playlistsProvider.notifier);
final connected = ref.watch(subsonicClientProvider) != null;
void open(Playlist p) => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => PlaylistDetailScreen(id: p.id)),
);
return Scaffold(
appBar: AppBar(
title: const Text('Playlists',
@ -34,54 +39,73 @@ class PlaylistsScreen extends ConsumerWidget {
],
),
body: SafeArea(
child: Padding(
child: ListView(
padding: const EdgeInsets.all(TimbreSpacing.lg),
child: HairlinePanel(
title: 'Playlists',
active: true,
trailing: playlists.isEmpty ? null : '(${playlists.length})',
padding: const EdgeInsets.symmetric(vertical: TimbreSpacing.md),
child: playlists.isEmpty
? Center(
child: Text(
connected
? 'No playlists yet. Tap + to create one.'
: 'Connect to a server to see playlists.',
textAlign: TextAlign.center,
style: const TextStyle(color: TimbreColors.dimmed),
),
)
: ListView.builder(
padding: EdgeInsets.zero,
itemCount: playlists.length,
itemBuilder: (context, i) {
final p = playlists[i];
return _PlaylistRow(
name: p.name,
subtitle: p.songCount != null
? '${p.songCount} tracks'
: null,
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => PlaylistDetailScreen(id: p.id),
children: [
HairlinePanel(
title: 'Playlists',
active: true,
trailing: mine.isEmpty ? null : '(${mine.length})',
padding: const EdgeInsets.symmetric(vertical: TimbreSpacing.md),
child: mine.isEmpty
? Padding(
padding: const EdgeInsets.all(TimbreSpacing.lg),
child: Text(
connected
? 'No playlists yet. Tap + to create one.'
: 'Connect to a server to see playlists.',
textAlign: TextAlign.center,
style: const TextStyle(color: TimbreColors.dimmed),
),
)
: Column(
children: [
for (final p in mine)
_PlaylistRow(
name: p.name,
subtitle: p.songCount != null
? '${p.songCount} tracks'
: null,
badge: (p.public ?? false) ? 'Public' : null,
isPublic: p.public ?? false,
onTap: () => open(p),
onToggleShare: connected
? () => _toggleShare(context, controller, p)
: null,
onRename: connected
? () => _rename(context, controller, p)
: null,
onDelete: connected
? () => _confirmDelete(context, controller, p)
: null,
),
),
onRename: connected
? () async {
final name = await promptPlaylistName(context,
title: 'Rename playlist', initial: p.name);
if (name != null && name.isNotEmpty) {
controller.rename(p.id, name);
}
}
],
),
),
if (shared.isNotEmpty) ...[
const SizedBox(height: TimbreSpacing.xl),
HairlinePanel(
title: 'Shared',
active: true,
trailing: '(${shared.length})',
padding:
const EdgeInsets.symmetric(vertical: TimbreSpacing.md),
child: Column(
children: [
for (final p in shared)
_PlaylistRow(
name: p.name,
subtitle: p.owner != null ? 'by ${p.owner}' : null,
onTap: () => open(p),
onSaveCopy: connected
? () => _saveCopy(context, controller, p)
: null,
onDelete: connected
? () => _confirmDelete(context, controller, p)
: null,
);
},
),
),
),
],
),
),
],
],
),
),
);
@ -94,6 +118,32 @@ class PlaylistsScreen extends ConsumerWidget {
}
}
Future<void> _rename(
BuildContext context, PlaylistsController controller, Playlist p) async {
final name = await promptPlaylistName(context,
title: 'Rename playlist', initial: p.name);
if (name != null && name.isNotEmpty) controller.rename(p.id, name);
}
Future<void> _toggleShare(
BuildContext context, PlaylistsController controller, Playlist p) async {
final next = !(p.public ?? false);
await controller.setPublic(p.id, next);
if (context.mounted) {
showToast(context,
next ? 'Shared — now public' : 'No longer shared',
icon: Icons.check);
}
}
Future<void> _saveCopy(
BuildContext context, PlaylistsController controller, Playlist p) async {
final id = await controller.saveCopy(p);
if (!context.mounted) return;
showToast(context, id != null ? 'Saved a copy' : 'Could not save copy',
icon: id != null ? Icons.check : null);
}
Future<void> _confirmDelete(
BuildContext context, PlaylistsController controller, Playlist p) async {
final ok = await showDialog<bool>(
@ -120,18 +170,34 @@ class _PlaylistRow extends StatelessWidget {
required this.name,
required this.onTap,
this.subtitle,
this.badge,
this.isPublic = false,
this.onRename,
this.onDelete,
this.onToggleShare,
this.onSaveCopy,
});
final String name;
final String? subtitle;
/// Optional pill after the name, e.g. "Public".
final String? badge;
/// Current share state, so the toggle can label itself correctly.
final bool isPublic;
final VoidCallback onTap;
final VoidCallback? onRename;
final VoidCallback? onDelete;
final VoidCallback? onToggleShare;
final VoidCallback? onSaveCopy;
@override
Widget build(BuildContext context) {
final hasMenu = onRename != null ||
onDelete != null ||
onToggleShare != null ||
onSaveCopy != null;
return InkWell(
onTap: onTap,
child: Container(
@ -147,10 +213,21 @@ class _PlaylistRow extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(color: TimbreColors.foreground)),
Row(
children: [
Flexible(
child: Text(name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: TimbreColors.foreground)),
),
if (badge != null) ...[
const SizedBox(width: TimbreSpacing.sm),
_Pill(badge!),
],
],
),
if (subtitle != null)
Text(subtitle!,
style: const TextStyle(
@ -158,16 +235,32 @@ class _PlaylistRow extends StatelessWidget {
],
),
),
if (onRename != null || onDelete != null)
if (hasMenu)
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert,
size: 20, color: TimbreColors.dimmed),
color: TimbreColors.surface,
onSelected: (v) {
if (v == 'rename') onRename?.call();
if (v == 'delete') onDelete?.call();
switch (v) {
case 'share':
onToggleShare?.call();
case 'copy':
onSaveCopy?.call();
case 'rename':
onRename?.call();
case 'delete':
onDelete?.call();
}
},
itemBuilder: (_) => [
if (onToggleShare != null)
PopupMenuItem(
value: 'share',
child:
Text(isPublic ? 'Make private' : 'Make public')),
if (onSaveCopy != null)
const PopupMenuItem(
value: 'copy', child: Text('Save a copy')),
if (onRename != null)
const PopupMenuItem(value: 'rename', child: Text('Rename')),
if (onDelete != null)
@ -181,6 +274,28 @@ class _PlaylistRow extends StatelessWidget {
}
}
/// A small accent-outlined label — used to flag a playlist as "Public".
class _Pill extends StatelessWidget {
const _Pill(this.text);
final String text;
@override
Widget build(BuildContext context) {
final accent = Theme.of(context).colorScheme.primary;
return Container(
padding: const EdgeInsets.symmetric(
horizontal: TimbreSpacing.sm, vertical: 1),
decoration: BoxDecoration(
border: Border.all(color: accent),
color: accent.withValues(alpha: 0.12),
),
child: Text(text,
style: TextStyle(
color: accent, fontSize: 11, fontWeight: FontWeight.w700)),
);
}
}
/// One playlist's tracks: play all / download all from the app bar, remove a
/// track via its trailing control.
class PlaylistDetailScreen extends ConsumerStatefulWidget {
@ -209,9 +324,15 @@ class _PlaylistDetailScreenState extends ConsumerState<PlaylistDetailScreen> {
final summary = ref.watch(playlistsProvider.select((s) =>
s.playlists.where((p) => p.id == widget.id).firstOrNull));
final connected = ref.watch(subsonicClientProvider) != null;
final me = ref.watch(currentUsernameProvider);
final playback = ref.read(playbackProvider.notifier);
final songs = detail?.songs ?? const <Song>[];
// Ownership drives which sharing affordance shows: owner → share toggle;
// someone else's shared playlist → save-a-copy.
final isMine = summary == null || isOwnedBy(summary, me);
final isPublic = summary?.public ?? false;
return Scaffold(
appBar: AppBar(
title: Text(detail?.name ?? summary?.name ?? 'Playlist',
@ -237,6 +358,19 @@ class _PlaylistDetailScreenState extends ConsumerState<PlaylistDetailScreen> {
},
icon: const Icon(Icons.download),
),
if (connected && summary != null)
if (isMine)
IconButton(
tooltip: isPublic ? 'Make private' : 'Make public',
onPressed: () => _toggleShare(summary, isPublic),
icon: Icon(isPublic ? Icons.public : Icons.public_off),
)
else
IconButton(
tooltip: 'Save a copy',
onPressed: () => _saveCopy(summary),
icon: const Icon(Icons.save_alt),
),
],
),
body: SafeArea(
@ -273,6 +407,21 @@ class _PlaylistDetailScreenState extends ConsumerState<PlaylistDetailScreen> {
),
);
}
Future<void> _toggleShare(Playlist p, bool isPublic) async {
await ref.read(playlistsProvider.notifier).setPublic(p.id, !isPublic);
if (mounted) {
showToast(context, !isPublic ? 'Shared — now public' : 'No longer shared',
icon: Icons.check);
}
}
Future<void> _saveCopy(Playlist p) async {
final id = await ref.read(playlistsProvider.notifier).saveCopy(p);
if (!mounted) return;
showToast(context, id != null ? 'Saved a copy' : 'Could not save copy',
icon: id != null ? Icons.check : null);
}
}
class _TrackRow extends StatelessWidget {

View file

@ -73,6 +73,18 @@ class SettingsScreen extends ConsumerWidget {
labelFor: AppSettings.formatLabel,
onSelect: controller.setDownloadFormat,
),
const SizedBox(height: TimbreSpacing.lg),
const _Caption(
'How many tracks download at once. Higher is faster on '
'a strong connection; lower is gentler on the server.'),
const SizedBox(height: TimbreSpacing.md),
_Stepper(
label: 'Simultaneous downloads',
value: settings.maxConcurrentDownloads,
min: AppSettings.minConcurrentDownloads,
max: AppSettings.maxConcurrentDownloadsCap,
onChanged: controller.setMaxConcurrentDownloads,
),
],
),
),
@ -380,6 +392,101 @@ class _Chip extends StatelessWidget {
}
}
/// A labelled −/value/+ stepper bounded to [[min], [max]], styled to match the
/// bordered-chip language of [_ChoiceChips].
class _Stepper extends StatelessWidget {
const _Stepper({
required this.label,
required this.value,
required this.min,
required this.max,
required this.onChanged,
});
final String label;
final int value;
final int min;
final int max;
final ValueChanged<int> onChanged;
@override
Widget build(BuildContext context) {
final accent = Theme.of(context).colorScheme.primary;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: const TextStyle(color: TimbreColors.foreground)),
const SizedBox(height: TimbreSpacing.sm),
Row(
children: [
_StepButton(
icon: Icons.remove,
accent: accent,
enabled: value > min,
onTap: () => onChanged(value - 1),
),
Container(
constraints: const BoxConstraints(
minWidth: TimbreSpacing.minTouchTarget,
minHeight: TimbreSpacing.minTouchTarget),
alignment: Alignment.center,
child: Text(
'$value',
style: const TextStyle(
color: TimbreColors.foreground,
fontWeight: FontWeight.w700,
),
),
),
_StepButton(
icon: Icons.add,
accent: accent,
enabled: value < max,
onTap: () => onChanged(value + 1),
),
],
),
],
);
}
}
class _StepButton extends StatelessWidget {
const _StepButton({
required this.icon,
required this.accent,
required this.enabled,
required this.onTap,
});
final IconData icon;
final Color accent;
final bool enabled;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: enabled ? onTap : null,
child: Container(
constraints: const BoxConstraints(
minWidth: TimbreSpacing.minTouchTarget,
minHeight: TimbreSpacing.minTouchTarget),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: TimbreColors.border),
color: TimbreColors.surface,
),
child: Icon(
icon,
size: 18,
color: enabled ? accent : TimbreColors.dimmed,
),
),
);
}
}
/// A row of accent-color chips — like [_ChoiceChips] but each chip shows a
/// color swatch and the color's own hue drives the active border/fill.
class _ColorChips extends StatelessWidget {