updates
This commit is contained in:
parent
d558aba246
commit
3bd713d667
17 changed files with 1566 additions and 132 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue