mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-14 02:37:20 +02:00
169 lines
5.2 KiB
Dart
169 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import '../../../core/database/hive_service.dart';
|
|
import '../../auth/providers/auth_provider.dart';
|
|
|
|
class PlaylistSelectionScreen extends ConsumerWidget {
|
|
const PlaylistSelectionScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final currentUser = ref.watch(authProvider).currentUser;
|
|
final playlistsBox = HiveService.playlistsBox;
|
|
|
|
// Filter playlists assigned to current user (or all if admin)
|
|
final availablePlaylists = playlistsBox.values.where((playlist) {
|
|
if (currentUser == null) return false;
|
|
if (currentUser.isAdmin) return playlist.isActive;
|
|
return currentUser.assignedPlaylistIds.contains(playlist.id) &&
|
|
playlist.isActive;
|
|
}).toList();
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(
|
|
'Select Playlist',
|
|
style: GoogleFonts.roboto(fontWeight: FontWeight.w600),
|
|
),
|
|
actions: [
|
|
if (currentUser?.isAdmin ?? false)
|
|
IconButton(
|
|
icon: const Icon(Icons.admin_panel_settings),
|
|
onPressed: () => context.go('/admin'),
|
|
tooltip: 'Admin Panel',
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.logout),
|
|
onPressed: () {
|
|
ref.read(authProvider.notifier).logout();
|
|
context.go('/login');
|
|
},
|
|
tooltip: 'Logout',
|
|
),
|
|
],
|
|
),
|
|
body: availablePlaylists.isEmpty
|
|
? Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.playlist_remove,
|
|
size: 64,
|
|
color: Colors.grey.shade400,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'No playlists available',
|
|
style: GoogleFonts.roboto(
|
|
fontSize: 18,
|
|
color: Colors.grey.shade600,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
currentUser?.isAdmin ?? false
|
|
? 'Add playlists in Admin Panel'
|
|
: 'Contact administrator',
|
|
style: GoogleFonts.roboto(
|
|
fontSize: 14,
|
|
color: Colors.grey.shade500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: GridView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 3,
|
|
crossAxisSpacing: 16,
|
|
mainAxisSpacing: 16,
|
|
childAspectRatio: 1.5,
|
|
),
|
|
itemCount: availablePlaylists.length,
|
|
itemBuilder: (context, index) {
|
|
final playlist = availablePlaylists[index];
|
|
return _PlaylistCard(
|
|
playlist: playlist,
|
|
onTap: () {
|
|
context.go('/dashboard', extra: playlist);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PlaylistCard extends StatelessWidget {
|
|
final dynamic playlist;
|
|
final VoidCallback onTap;
|
|
|
|
const _PlaylistCard({
|
|
required this.playlist,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
elevation: 4,
|
|
clipBehavior: Clip.antiAlias,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Colors.blue.shade700,
|
|
Colors.blue.shade900,
|
|
],
|
|
),
|
|
),
|
|
padding: const EdgeInsets.all(20),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(
|
|
Icons.playlist_play,
|
|
size: 48,
|
|
color: Colors.white.withOpacity(0.9),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
playlist.name,
|
|
style: GoogleFonts.roboto(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
Uri.parse(playlist.dns).host,
|
|
style: GoogleFonts.roboto(
|
|
fontSize: 12,
|
|
color: Colors.white.withOpacity(0.7),
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|