fix(epg): load filtered channels from playlist provider instead of manual channel ID input

This commit is contained in:
Michael committed 2026-03-09 08:36:41 +01:00
1 parent 47fff742e0
commit 3e0088ecf8
1 file changed
+195 -131
+195 -131
View File
@@ -1,9 +1,13 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import '../../../core/models/iptv_models.dart';
import '../../../core/theme/app_colors.dart'; import '../../../core/theme/app_colors.dart';
import '../../../core/widgets/glass_container.dart'; import '../../../core/widgets/glass_container.dart';
import '../providers/xtream_provider.dart';
import '../providers/settings_provider.dart';
/// Onglet "Enregistrements & Guide TV" — combine guide EPG, enregistrements actifs et season passes /// Onglet "Enregistrements & Guide TV" — combine guide EPG, enregistrements actifs et season passes
class RecordingsTab extends StatefulWidget { class RecordingsTab extends StatefulWidget {
@@ -95,36 +99,32 @@ class _RecordingsTabState extends State<RecordingsTab>
// ONGLET 1 — GUIDE TV (EPG) // ONGLET 1 — GUIDE TV (EPG)
// ═══════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════
class _EpgGuideView extends StatefulWidget { /// Guide TV EPG — charge les chaînes filtrées depuis les Settings (comme l'onglet TV)
class _EpgGuideView extends ConsumerStatefulWidget {
const _EpgGuideView(); const _EpgGuideView();
@override @override
State<_EpgGuideView> createState() => _EpgGuideViewState(); ConsumerState<_EpgGuideView> createState() => _EpgGuideViewState();
} }
class _EpgGuideViewState extends State<_EpgGuideView> { class _EpgGuideViewState extends ConsumerState<_EpgGuideView> {
List<dynamic> _channels = [];
bool _loadingChannels = true;
String? _selectedChannelId; String? _selectedChannelId;
String? _selectedChannelName; String? _selectedChannelName;
String? _selectedStreamUrl; String? _selectedStreamUrl;
List<dynamic> _programmes = []; List<dynamic> _programmes = [];
bool _loadingEpg = false; bool _loadingEpg = false;
String _searchQuery = '';
final TextEditingController _searchCtrl = TextEditingController();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_loadChannels(); _searchCtrl.addListener(() => setState(() => _searchQuery = _searchCtrl.text.toLowerCase()));
} }
Future<void> _loadChannels() async { @override
try { void dispose() {
final response = await http.get(Uri.parse('/api/recordings')); // On utilise les enregistrements pour avoir les chaînes _searchCtrl.dispose();
// On charge la liste depuis l'API xtream directement si disponible super.dispose();
setState(() => _loadingChannels = false);
} catch (_) {
setState(() => _loadingChannels = false);
}
} }
Future<void> _loadEpg(String channelId) async { Future<void> _loadEpg(String channelId) async {
@@ -145,151 +145,215 @@ class _EpgGuideViewState extends State<_EpgGuideView> {
} }
} }
void _showChannelInput() { void _selectChannel(Channel ch) {
final idController = TextEditingController(); setState(() {
final nameController = TextEditingController(); _selectedChannelId = ch.streamId.toString();
final urlController = TextEditingController(); _selectedChannelName = ch.name;
_selectedStreamUrl = '/api/live/${ch.streamId}.ts';
showDialog( _programmes = [];
context: context, });
builder: (ctx) => AlertDialog( _loadEpg(ch.streamId.toString());
backgroundColor: const Color(0xFF1E1E2E),
title: Text('Sélectionner une chaîne', style: GoogleFonts.outfit(color: Colors.white)),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: idController,
style: const TextStyle(color: Colors.white),
decoration: const InputDecoration(
labelText: 'Channel ID (ex: 554021)',
labelStyle: TextStyle(color: Colors.white54),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.white24)),
),
),
const SizedBox(height: 8),
TextField(
controller: nameController,
style: const TextStyle(color: Colors.white),
decoration: const InputDecoration(
labelText: 'Nom de la chaîne',
labelStyle: TextStyle(color: Colors.white54),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.white24)),
),
),
const SizedBox(height: 8),
TextField(
controller: urlController,
style: const TextStyle(color: Colors.white),
decoration: const InputDecoration(
labelText: 'stream_url (ex: /api/live/554021.ts)',
labelStyle: TextStyle(color: Colors.white54),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.white24)),
),
),
],
),
actions: [
TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('Annuler')),
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.redAccent),
onPressed: () {
final id = idController.text.trim();
if (id.isNotEmpty) {
setState(() {
_selectedChannelId = id;
_selectedChannelName = nameController.text.trim().isEmpty ? 'Chaîne $id' : nameController.text.trim();
_selectedStreamUrl = urlController.text.trim().isEmpty ? '/api/live/$id.ts' : urlController.text.trim();
});
Navigator.pop(ctx);
_loadEpg(id);
}
},
child: const Text('Charger'),
),
],
),
);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final playlist = ref.watch(selectedPlaylistProvider);
final settings = ref.watch(iptvSettingsProvider);
// Charger les chaînes seulement si on a une playlist active
final channelsAsync = playlist != null
? ref.watch(liveChannelsByPlaylistProvider(playlist))
: null;
return Padding( return Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Column( child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Zone de sélection de chaîne // ─── Colonne gauche : liste des chaînes filtrées ───
Row( SizedBox(
children: [ width: 220,
Expanded( child: Column(
child: GlassContainer( children: [
child: InkWell( // Barre de recherche
onTap: _showChannelInput, TextField(
borderRadius: BorderRadius.circular(12), controller: _searchCtrl,
child: Padding( style: const TextStyle(color: Colors.white, fontSize: 13),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14), decoration: InputDecoration(
child: Row( hintText: 'Chercher une chaîne...',
children: [ hintStyle: const TextStyle(color: Colors.white38, fontSize: 13),
const Icon(Icons.tv, color: Colors.white54, size: 20), prefixIcon: const Icon(Icons.search, color: Colors.white38, size: 18),
const SizedBox(width: 12), filled: true,
Text( fillColor: Colors.white.withOpacity(0.07),
_selectedChannelName ?? 'Sélectionner une chaîne...', border: OutlineInputBorder(
style: TextStyle( borderRadius: BorderRadius.circular(10),
color: _selectedChannelName != null ? Colors.white : Colors.white38, borderSide: BorderSide.none,
fontSize: 15,
),
),
const Spacer(),
const Icon(Icons.keyboard_arrow_down, color: Colors.white38),
],
),
), ),
contentPadding: const EdgeInsets.symmetric(vertical: 8),
), ),
), ),
), const SizedBox(height: 8),
if (_selectedChannelId != null) ...[ Expanded(
const SizedBox(width: 12), child: channelsAsync == null
IconButton( ? Center(
icon: const Icon(Icons.refresh, color: Colors.white70), child: Text('Aucune playlist
tooltip: 'Recharger l\'EPG', active',
onPressed: () => _loadEpg(_selectedChannelId!), textAlign: TextAlign.center,
style: GoogleFonts.outfit(color: Colors.white38, fontSize: 12)),
)
: channelsAsync.when(
loading: () => const Center(child: CircularProgressIndicator(strokeWidth: 2)),
error: (e, _) => Center(child: Text('Erreur: $e', style: const TextStyle(color: Colors.red, fontSize: 12))),
data: (groupedChannels) {
// Appliquer le même filtre que l'onglet TV
final filteredChannels = <Channel>[];
for (final entry in groupedChannels.entries) {
if (settings.liveTvKeywords.isEmpty ||
settings.matchesLiveTvFilter(entry.key)) {
filteredChannels.addAll(entry.value);
}
}
// Tri alphabétique
filteredChannels.sort((a, b) => a.name.compareTo(b.name));
// Filtre par recherche
final visible = _searchQuery.isEmpty
? filteredChannels
: filteredChannels
.where((c) => c.name.toLowerCase().contains(_searchQuery))
.toList();
if (visible.isEmpty) {
return Center(
child: Text('Aucune chaîne\n(vérifiez les filtres dans Settings)',
textAlign: TextAlign.center,
style: GoogleFonts.outfit(color: Colors.white38, fontSize: 12)),
);
}
return ListView.builder(
itemCount: visible.length,
itemBuilder: (ctx, i) {
final ch = visible[i];
final isSelected = ch.streamId.toString() == _selectedChannelId;
return InkWell(
onTap: () => _selectChannel(ch),
borderRadius: BorderRadius.circular(8),
child: Container(
margin: const EdgeInsets.only(bottom: 4),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
decoration: BoxDecoration(
color: isSelected
? Colors.redAccent.withOpacity(0.2)
: Colors.white.withOpacity(0.05),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isSelected
? Colors.redAccent.withOpacity(0.5)
: Colors.transparent,
),
),
child: Row(
children: [
if (ch.streamIcon != null && ch.streamIcon!.isNotEmpty)
ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Image.network(
ch.streamIcon!,
width: 28,
height: 20,
fit: BoxFit.contain,
errorBuilder: (_, __, ___) =>
const Icon(Icons.tv, color: Colors.white38, size: 20),
),
)
else
const Icon(Icons.tv, color: Colors.white38, size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(
ch.name,
style: GoogleFonts.outfit(
color: isSelected ? Colors.white : Colors.white70,
fontSize: 12,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
);
},
);
},
),
), ),
], ],
], ),
), ),
const SizedBox(height: 16), const SizedBox(width: 16),
// Contenu EPG // ─── Colonne droite : programmes de la chaîne sélectionnée ───
Expanded( Expanded(
child: _selectedChannelId == null child: _selectedChannelId == null
? Center( ? Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(Icons.tv_off, size: 64, color: Colors.white12), const Icon(Icons.tv_off, size: 64, color: Color(0x1FFFFFFF)),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
'Sélectionnez une chaîne pour\nvoir son guide des programmes', 'Sélectionnez une chaîne pour\nvoir son guide des programmes',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: GoogleFonts.outfit(color: Colors.white38, fontSize: 16), style: GoogleFonts.outfit(color: Colors.white38, fontSize: 15),
), ),
], ],
), ),
) )
: _loadingEpg : Column(
? const Center(child: CircularProgressIndicator()) crossAxisAlignment: CrossAxisAlignment.start,
: _programmes.isEmpty children: [
? Center( Row(
child: Text('Aucun programme EPG disponible', children: [
style: GoogleFonts.outfit(color: Colors.white38))) Text(
: ListView.builder( _selectedChannelName ?? '',
itemCount: _programmes.length, style: GoogleFonts.outfit(
itemBuilder: (ctx, i) => _ProgrammeCard( color: Colors.white,
programme: _programmes[i], fontWeight: FontWeight.bold,
channelName: _selectedChannelName ?? '', fontSize: 16,
channelId: _selectedChannelId!,
streamUrl: _selectedStreamUrl ?? '/api/live/$_selectedChannelId.ts',
), ),
), ),
const Spacer(),
IconButton(
icon: const Icon(Icons.refresh, color: Colors.white54, size: 18),
onPressed: () => _loadEpg(_selectedChannelId!),
tooltip: 'Recharger l\'EPG',
),
],
),
const Divider(color: Colors.white12),
Expanded(
child: _loadingEpg
? const Center(child: CircularProgressIndicator())
: _programmes.isEmpty
? Center(
child: Text('Aucun programme EPG disponible',
style: GoogleFonts.outfit(color: Colors.white38)),
)
: ListView.builder(
itemCount: _programmes.length,
itemBuilder: (ctx, i) => _ProgrammeCard(
programme: _programmes[i],
channelName: _selectedChannelName ?? '',
channelId: _selectedChannelId!,
streamUrl: _selectedStreamUrl ?? '/api/live/$_selectedChannelId.ts',
),
),
),
],
),
), ),
], ],
), ),