mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-19 05:06:21 +02:00
Merge remote-tracking branch 'origin/main' into main
Resolved conflicts by keeping remote functional features (RecordingScheduler, FFmpeg HLS transcoding, mobile player, channel cards) and restoring local Stitch theme foundation (app_colors, app_theme, glass_container, mobile_theme). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
commit
2ba16caf55
68 files changed
+18812
-1794
No files matched your search
@@ -27,11 +27,11 @@ class AdminPanel extends StatelessWidget {
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF0F1014),
|
||||
Color(0xFF121317),
|
||||
AppColors.surfaceVariant,
|
||||
AppColors.background,
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -80,13 +80,13 @@ class _AdminContentState extends ConsumerState<AdminContent>
|
||||
padding: const EdgeInsets.all(8),
|
||||
showBorder: false,
|
||||
onTap: () => context.go('/playlists'),
|
||||
child: const Icon(Icons.arrow_back, color: AppColors.onSurfaceVariant),
|
||||
child: const Icon(Icons.arrow_back, color: AppColors.textSecondary),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Text(
|
||||
'Administration',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.textPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@@ -136,10 +136,10 @@ class _AdminContentState extends ConsumerState<AdminContent>
|
||||
return GestureDetector(
|
||||
onTap: () => _tabController.animateTo(index),
|
||||
child: AnimatedContainer(
|
||||
duration: AppTheme.durationFast,
|
||||
duration: AppTheme.durationSm,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? AppColors.primaryContainer : Colors.transparent,
|
||||
color: isSelected ? AppColors.focusColor : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: Row(
|
||||
@@ -147,7 +147,7 @@ class _AdminContentState extends ConsumerState<AdminContent>
|
||||
Icon(
|
||||
icon,
|
||||
size: 18,
|
||||
color: isSelected ? AppColors.onPrimaryContainer : AppColors.onSurfaceVariant,
|
||||
color: isSelected ? AppColors.textPrimary : AppColors.textSecondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
@@ -155,7 +155,7 @@ class _AdminContentState extends ConsumerState<AdminContent>
|
||||
style: GoogleFonts.inter(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
color: isSelected ? AppColors.onPrimaryContainer : AppColors.onSurfaceVariant,
|
||||
color: isSelected ? AppColors.textPrimary : AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -187,7 +187,7 @@ class _PlaylistsTab extends ConsumerWidget {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge
|
||||
?.copyWith(color: AppColors.onSurfaceVariant),
|
||||
?.copyWith(color: AppColors.textSecondary),
|
||||
),
|
||||
GradientButton(
|
||||
label: 'Add Playlist',
|
||||
@@ -215,7 +215,7 @@ class _PlaylistsTab extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.playlist_remove,
|
||||
size: 64,
|
||||
color: AppColors.onSurfaceVariant.withOpacity(0.5),
|
||||
color: AppColors.textSecondary.withOpacity(0.5),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
@@ -252,7 +252,7 @@ class _PlaylistsTab extends ConsumerWidget {
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.playlist_play,
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
@@ -265,7 +265,7 @@ class _PlaylistsTab extends ConsumerWidget {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium
|
||||
?.copyWith(color: AppColors.onSurface),
|
||||
?.copyWith(color: Colors.white),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
@@ -273,7 +273,7 @@ class _PlaylistsTab extends ConsumerWidget {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(color: AppColors.onSurfaceVariant),
|
||||
?.copyWith(color: Colors.white60),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -282,7 +282,7 @@ class _PlaylistsTab extends ConsumerWidget {
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined, size: 20),
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: Colors.white70,
|
||||
onPressed: () =>
|
||||
_showPlaylistDialog(context, ref, playlist),
|
||||
tooltip: 'Edit',
|
||||
@@ -462,7 +462,7 @@ class _UsersTab extends ConsumerWidget {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge
|
||||
?.copyWith(color: AppColors.onSurfaceVariant),
|
||||
?.copyWith(color: AppColors.textSecondary),
|
||||
),
|
||||
GradientButton(
|
||||
label: 'Create User',
|
||||
@@ -490,7 +490,7 @@ class _UsersTab extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.people_outline,
|
||||
size: 64,
|
||||
color: AppColors.onSurfaceVariant.withOpacity(0.5),
|
||||
color: AppColors.textSecondary.withOpacity(0.5),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
@@ -518,7 +518,7 @@ class _UsersTab extends ConsumerWidget {
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: user.isAdmin
|
||||
? AppColors.primaryContainer
|
||||
? AppColors.focusColor
|
||||
: AppColors.surface,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
@@ -527,8 +527,8 @@ class _UsersTab extends ConsumerWidget {
|
||||
? Icons.admin_panel_settings
|
||||
: Icons.person,
|
||||
color: user.isAdmin
|
||||
? AppColors.onPrimaryContainer
|
||||
: AppColors.onSurface,
|
||||
? Colors.black
|
||||
: AppColors.textPrimary,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
@@ -544,7 +544,7 @@ class _UsersTab extends ConsumerWidget {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium
|
||||
?.copyWith(color: AppColors.onSurface),
|
||||
?.copyWith(color: Colors.white),
|
||||
),
|
||||
if (user.isAdmin) ...[
|
||||
const SizedBox(width: 8),
|
||||
@@ -554,16 +554,16 @@ class _UsersTab extends ConsumerWidget {
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryContainer
|
||||
color: AppColors.focusColor
|
||||
.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: Text(
|
||||
child: const Text(
|
||||
'ADMIN',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primaryContainer,
|
||||
color: AppColors.focusColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -576,7 +576,7 @@ class _UsersTab extends ConsumerWidget {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(color: AppColors.onSurfaceVariant),
|
||||
?.copyWith(color: Colors.white60),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -584,7 +584,7 @@ class _UsersTab extends ConsumerWidget {
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: Colors.white70,
|
||||
),
|
||||
color: AppColors.surface,
|
||||
shape: RoundedRectangleBorder(
|
||||
|
||||
@@ -51,54 +51,54 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// 1. Cinematic Background
|
||||
// 1. Cinematic Background (Deep Space - Premium Apple TV)
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF0F1014),
|
||||
Color(0xFF121317),
|
||||
Color(0xFF0D0E12),
|
||||
Color(0xFF050505),
|
||||
AppColors.background,
|
||||
Color(0xFF0A0A0A),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 2. Ambient Glows (Stitch style — blue diffuse)
|
||||
// 2. Ambient Glows (Apple TV Style - VISIBLE)
|
||||
Positioned(
|
||||
top: -size.height * 0.2,
|
||||
right: -size.width * 0.1,
|
||||
top: -size.height * 0.3,
|
||||
right: -size.width * 0.2,
|
||||
child: Container(
|
||||
width: size.width * 0.6,
|
||||
height: size.width * 0.6,
|
||||
width: size.width * 0.8,
|
||||
height: size.width * 0.8,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: RadialGradient(
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.06),
|
||||
AppColors.primary.withOpacity(0.4),
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
Colors.transparent,
|
||||
],
|
||||
radius: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: -size.height * 0.2,
|
||||
left: -size.width * 0.1,
|
||||
bottom: -size.height * 0.3,
|
||||
left: -size.width * 0.2,
|
||||
child: Container(
|
||||
width: size.width * 0.6,
|
||||
height: size.width * 0.6,
|
||||
width: size.width * 0.8,
|
||||
height: size.width * 0.8,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: RadialGradient(
|
||||
colors: [
|
||||
AppColors.primaryContainer.withOpacity(0.04),
|
||||
AppColors.info.withOpacity(0.3),
|
||||
AppColors.info.withOpacity(0.05),
|
||||
Colors.transparent,
|
||||
],
|
||||
radius: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -118,11 +118,15 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.primaryGradient,
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [AppColors.surfaceVariant, AppColors.background],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.glowPrimary(0.3),
|
||||
color: AppColors.background.withOpacity(0.5),
|
||||
blurRadius: 30,
|
||||
offset: const Offset(0, 15),
|
||||
),
|
||||
@@ -130,7 +134,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.play_arrow_rounded,
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.textPrimary,
|
||||
size: 64,
|
||||
),
|
||||
),
|
||||
@@ -140,10 +144,10 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
// Title
|
||||
Text(
|
||||
'XtremFlow',
|
||||
style: GoogleFonts.spaceGrotesk(
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 42,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.textPrimary,
|
||||
letterSpacing: -1.0,
|
||||
),
|
||||
),
|
||||
@@ -152,17 +156,18 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
'Sign in to sync your playlists',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 18,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: AppColors.textSecondary,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
// Login Form Container
|
||||
GlassContainer.floating(
|
||||
GlassContainer(
|
||||
width: 500,
|
||||
padding: const EdgeInsets.all(48),
|
||||
padding: const EdgeInsets.all(48), // Spacious padding
|
||||
borderRadius: 24,
|
||||
opacity: 0.7,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
@@ -191,7 +196,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
_obscurePassword
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
@@ -224,7 +229,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
Expanded(
|
||||
child: Text(
|
||||
authState.errorMessage!,
|
||||
style: GoogleFonts.inter(
|
||||
style: const TextStyle(
|
||||
color: AppColors.error,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -242,20 +247,14 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
TvFocusableCard(
|
||||
onTap: _handleLogin,
|
||||
scaleFactor: 1.03,
|
||||
focusColor: AppColors.primary,
|
||||
borderRadius: 16,
|
||||
child: Container(
|
||||
height: 60,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.primaryGradient,
|
||||
color: AppColors.textPrimary,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.glowPrimary(0.3),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: authState.isLoading
|
||||
? const SizedBox(
|
||||
@@ -263,13 +262,13 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.5,
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
'Sign In',
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.primary,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -286,7 +285,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
'Default: admin / admin',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
color: AppColors.outline,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -312,34 +311,28 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
obscureText: obscureText,
|
||||
style: GoogleFonts.inter(fontSize: 18, color: AppColors.onSurface),
|
||||
style: GoogleFonts.inter(fontSize: 18, color: AppColors.textPrimary),
|
||||
autofocus: autofocus,
|
||||
textInputAction: nextFocus ? TextInputAction.next : TextInputAction.done,
|
||||
onFieldSubmitted: isLast ? (_) => onSubmitted?.call() : null,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
labelStyle: GoogleFonts.inter(color: AppColors.onSurfaceVariant),
|
||||
prefixIcon: Icon(icon, color: AppColors.onSurfaceVariant),
|
||||
labelStyle: GoogleFonts.inter(color: AppColors.textSecondary),
|
||||
prefixIcon: Icon(icon, color: AppColors.textSecondary),
|
||||
suffixIcon: suffix,
|
||||
filled: true,
|
||||
fillColor: AppColors.surfaceContainerLow,
|
||||
fillColor: AppColors.surfaceVariant.withOpacity(0.5),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(
|
||||
color: AppColors.outlineVariant,
|
||||
width: 1,
|
||||
),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(
|
||||
color: AppColors.primaryContainer,
|
||||
width: 2,
|
||||
),
|
||||
borderSide: const BorderSide(color: AppColors.focusColor, width: 2),
|
||||
),
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../models/playlist.dart';
|
||||
|
||||
/// Represents a content recommendation
|
||||
class Recommendation {
|
||||
final Playlist item;
|
||||
final RecommendationType type;
|
||||
final double score;
|
||||
final String reason;
|
||||
|
||||
Recommendation({
|
||||
required this.item,
|
||||
required this.type,
|
||||
this.score = 0.0,
|
||||
required this.reason,
|
||||
});
|
||||
}
|
||||
|
||||
enum RecommendationType {
|
||||
continueWatching,
|
||||
trending,
|
||||
recentlyAdded,
|
||||
similarContent,
|
||||
topRated,
|
||||
forYou,
|
||||
}
|
||||
|
||||
class RecommendationService {
|
||||
/// Get continue watching items based on watch history
|
||||
static List<Recommendation> getContinueWatching(
|
||||
Map<String, dynamic> watchHistory,
|
||||
List<Playlist> allContent,
|
||||
) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
for (final item in allContent) {
|
||||
final historyKey = item.streamId.toString();
|
||||
if (watchHistory.containsKey(historyKey)) {
|
||||
final lastPosition = watchHistory[historyKey] as double? ?? 0.0;
|
||||
|
||||
// Only show if watched more than 5 seconds ago and less than 95% complete
|
||||
if (lastPosition > 5 && lastPosition < 95) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.continueWatching,
|
||||
score: 100.0 - lastPosition, // Score higher if recently started
|
||||
reason:
|
||||
'Continue watching from ${lastPosition.toStringAsFixed(0)}%',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by last watched (highest incomplete progress first)
|
||||
recommendations.sort((a, b) => b.score.compareTo(a.score));
|
||||
return recommendations.take(10).toList();
|
||||
}
|
||||
|
||||
/// Get trending content based on view counts
|
||||
static List<Recommendation> getTrending(
|
||||
Map<String, int> viewCounts,
|
||||
List<Playlist> allContent,
|
||||
) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
for (final item in allContent) {
|
||||
final views = viewCounts[item.streamId.toString()] ?? 0;
|
||||
if (views > 0) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.trending,
|
||||
score: views.toDouble(),
|
||||
reason: '$views views - Trending now',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
recommendations.sort((a, b) => b.score.compareTo(a.score));
|
||||
return recommendations.take(10).toList();
|
||||
}
|
||||
|
||||
/// Get recently added content
|
||||
static List<Recommendation> getRecentlyAdded(List<Playlist> allContent) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
// Sort by added date (most recent first)
|
||||
final sorted = [...allContent];
|
||||
sorted.sort((a, b) {
|
||||
final aDate = DateTime.tryParse(a.added ?? '') ?? DateTime(2000);
|
||||
final bDate = DateTime.tryParse(b.added ?? '') ?? DateTime(2000);
|
||||
return bDate.compareTo(aDate);
|
||||
});
|
||||
|
||||
for (final item in sorted.take(20)) {
|
||||
final daysAgo = DateTime.now()
|
||||
.difference(DateTime.tryParse(item.added ?? '') ?? DateTime(2000))
|
||||
.inDays;
|
||||
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.recentlyAdded,
|
||||
score: (20 - daysAgo).toDouble().clamp(0, 100),
|
||||
reason: 'Added $daysAgo days ago',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return recommendations.take(10).toList();
|
||||
}
|
||||
|
||||
/// Get personalized recommendations based on watch history
|
||||
static List<Recommendation> getForYou(
|
||||
Map<String, dynamic> watchHistory,
|
||||
List<Playlist> allContent,
|
||||
) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
// Collect watched categories
|
||||
final watchedCategories = <String>{};
|
||||
watchHistory.forEach((key, value) {
|
||||
if (value is Map && value.containsKey('category')) {
|
||||
watchedCategories.add(value['category'] as String);
|
||||
}
|
||||
});
|
||||
|
||||
// Recommend similar content
|
||||
for (final item in allContent) {
|
||||
if (watchedCategories.contains(item.categoryId)) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.forYou,
|
||||
score: 75.0,
|
||||
reason: 'Based on your interests',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add highly rated content
|
||||
var ratedContent = [...allContent];
|
||||
ratedContent.sort((a, b) {
|
||||
final aRating = double.tryParse(a.rating ?? '0') ?? 0.0;
|
||||
final bRating = double.tryParse(b.rating ?? '0') ?? 0.0;
|
||||
return bRating.compareTo(aRating);
|
||||
});
|
||||
|
||||
for (final item in ratedContent.where((i) {
|
||||
final rating = double.tryParse(i.rating ?? '0') ?? 0.0;
|
||||
return rating >= 7.5;
|
||||
}).take(5)) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.topRated,
|
||||
score: double.tryParse(item.rating ?? '0') ?? 0.0,
|
||||
reason: 'Highly rated - ${item.rating}/10',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Remove duplicates and limit
|
||||
final seen = <int>{};
|
||||
final unique = <Recommendation>[];
|
||||
for (final rec in recommendations) {
|
||||
if (!seen.contains(rec.item.streamId)) {
|
||||
unique.add(rec);
|
||||
seen.add(rec.item.streamId);
|
||||
}
|
||||
}
|
||||
|
||||
return unique.take(15).toList();
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for watch history
|
||||
final watchHistoryProvider =
|
||||
StateNotifierProvider<WatchHistoryNotifier, Map<String, dynamic>>((ref) {
|
||||
return WatchHistoryNotifier();
|
||||
});
|
||||
|
||||
class WatchHistoryNotifier extends StateNotifier<Map<String, dynamic>> {
|
||||
WatchHistoryNotifier() : super({});
|
||||
|
||||
void updateWatchTime(int streamId, double percentage) {
|
||||
state = {
|
||||
...state,
|
||||
streamId.toString(): {
|
||||
'percentage': percentage,
|
||||
'timestamp': DateTime.now().toIso8601String(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
void clearHistory() {
|
||||
state = {};
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for view counts/trending
|
||||
final trendingProvider =
|
||||
StateNotifierProvider<TrendingNotifier, Map<String, int>>((ref) {
|
||||
return TrendingNotifier();
|
||||
});
|
||||
|
||||
class TrendingNotifier extends StateNotifier<Map<String, int>> {
|
||||
TrendingNotifier() : super({});
|
||||
|
||||
void incrementViewCount(int streamId) {
|
||||
final key = streamId.toString();
|
||||
state = {
|
||||
...state,
|
||||
key: (state[key] ?? 0) + 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for recommendations
|
||||
final recommendationsProvider = FutureProvider.family<List<Recommendation>,
|
||||
(Playlist, Map<String, dynamic>, Map<String, int>, List<Playlist>)>(
|
||||
(ref, params) async {
|
||||
final (playlist, watchHistory, trending, allContent) = params;
|
||||
|
||||
// Combine all recommendation types
|
||||
final allRecommendations = <Recommendation>[
|
||||
...RecommendationService.getContinueWatching(watchHistory, allContent),
|
||||
...RecommendationService.getTrending(trending, allContent),
|
||||
...RecommendationService.getRecentlyAdded(allContent),
|
||||
...RecommendationService.getForYou(watchHistory, allContent),
|
||||
];
|
||||
|
||||
// Deduplicate and score
|
||||
final seen = <int>{};
|
||||
final scored = <Recommendation>[];
|
||||
|
||||
for (final rec in allRecommendations) {
|
||||
if (!seen.contains(rec.item.streamId)) {
|
||||
scored.add(rec);
|
||||
seen.add(rec.item.streamId);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by score
|
||||
scored.sort((a, b) => b.score.compareTo(a.score));
|
||||
return scored;
|
||||
},
|
||||
);
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
@@ -25,7 +24,13 @@ class DashboardScreen extends ConsumerStatefulWidget {
|
||||
|
||||
class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
int _selectedIndex = 0;
|
||||
final List<String> _tabs = ['Live TV', 'Movies', 'Series', 'Recordings', 'Settings'];
|
||||
final List<String> _tabs = [
|
||||
'Live TV',
|
||||
'Movies',
|
||||
'Series',
|
||||
'Recordings',
|
||||
'Settings',
|
||||
];
|
||||
final List<IconData> _icons = [
|
||||
Icons.live_tv_rounded,
|
||||
Icons.movie_rounded,
|
||||
@@ -41,34 +46,56 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// 1. Cinematic Deep Space Background
|
||||
// 1. Cinematic Deep Space Background - Premium Apple TV Style
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF0F1014),
|
||||
Color(0xFF121317),
|
||||
Color(0xFF050505), // Very dark top
|
||||
AppColors.background, // Black bottom
|
||||
Color(0xFF0A0A0A), // Slightly darker for depth
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Ambient Glow — primary accent diffuse
|
||||
// Ambient Glow Top-Left - Teal (Primary) - VISIBLE
|
||||
Positioned(
|
||||
top: -100,
|
||||
left: -100,
|
||||
top: -300,
|
||||
left: -300,
|
||||
child: Container(
|
||||
width: 500,
|
||||
height: 500,
|
||||
width: 800,
|
||||
height: 800,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: RadialGradient(
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.06),
|
||||
AppColors.primary.withOpacity(0.4),
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
Colors.transparent,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Ambient Glow Bottom-Right - Blue - VISIBLE
|
||||
Positioned(
|
||||
bottom: -250,
|
||||
right: -250,
|
||||
child: Container(
|
||||
width: 700,
|
||||
height: 700,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: RadialGradient(
|
||||
colors: [
|
||||
AppColors.info.withOpacity(0.35),
|
||||
AppColors.info.withOpacity(0.1),
|
||||
Colors.transparent,
|
||||
],
|
||||
),
|
||||
@@ -91,15 +118,19 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
// 3. Vertical Glass Sidebar (Stitch Level 2)
|
||||
// 3. Vertical Glass Sidebar
|
||||
Positioned(
|
||||
left: 24,
|
||||
top: 24,
|
||||
bottom: 24,
|
||||
width: 80,
|
||||
child: GlassContainer.floating(
|
||||
child: GlassContainer(
|
||||
borderRadius: 24,
|
||||
padding: EdgeInsets.zero,
|
||||
opacity: 0.1,
|
||||
// blur is hardcoded in GlassContainer (15), so we don't pass it
|
||||
// border is bool, borderColor allows customization
|
||||
hasBorder: true,
|
||||
borderColor: AppColors.border,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@@ -114,7 +145,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.glowPrimary(0.4),
|
||||
color: AppColors.primary.withOpacity(0.4),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
@@ -122,7 +153,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.play_arrow_rounded,
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.textPrimary,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
@@ -139,37 +170,27 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
onTap: () => setState(() => _selectedIndex = index),
|
||||
scaleFactor: 1.2,
|
||||
borderRadius: 16,
|
||||
focusColor: AppColors.primary,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColors.primary.withOpacity(0.15)
|
||||
? AppColors.primary.withOpacity(0.2)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: isSelected
|
||||
? Border.all(
|
||||
color: AppColors.primaryContainer
|
||||
.withOpacity(0.5),
|
||||
width: 2,
|
||||
color: AppColors.primary.withOpacity(0.5),
|
||||
)
|
||||
: null,
|
||||
boxShadow: isSelected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: AppColors.glowPrimary(0.2),
|
||||
blurRadius: 12,
|
||||
spreadRadius: 1,
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Icon(
|
||||
_icons[index],
|
||||
color: isSelected
|
||||
? AppColors.onSurface
|
||||
: AppColors.onSurfaceVariant,
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textSecondary,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
@@ -179,7 +200,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// Profile
|
||||
// Settings / Profile
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
child: TvFocusableCard(
|
||||
@@ -188,11 +209,10 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
scaleFactor: 1.1,
|
||||
child: CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: AppColors.surfaceContainerHigh
|
||||
.withOpacity(0.5),
|
||||
child: Icon(
|
||||
backgroundColor: AppColors.primary.withOpacity(0.1),
|
||||
child: const Icon(
|
||||
Icons.person,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: AppColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,496 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../models/playlist.dart';
|
||||
import '../services/xtream_service.dart';
|
||||
|
||||
/// EPG Program information
|
||||
class EpgProgram {
|
||||
final String id;
|
||||
final String channelId;
|
||||
final String title;
|
||||
final String description;
|
||||
final DateTime startTime;
|
||||
final DateTime endTime;
|
||||
final String? imageUrl;
|
||||
final bool isNow;
|
||||
final bool isNext;
|
||||
|
||||
EpgProgram({
|
||||
required this.id,
|
||||
required this.channelId,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.startTime,
|
||||
required this.endTime,
|
||||
this.imageUrl,
|
||||
this.isNow = false,
|
||||
this.isNext = false,
|
||||
});
|
||||
|
||||
Duration get duration => endTime.difference(startTime);
|
||||
|
||||
double get progress {
|
||||
if (!isNow) return 0;
|
||||
final now = DateTime.now();
|
||||
if (now.isBefore(startTime)) return 0;
|
||||
if (now.isAfter(endTime)) return 100;
|
||||
return ((now.difference(startTime).inSeconds) / duration.inSeconds) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
/// EPG Grid View Screen (7 days, 24 hours)
|
||||
class EpgGridScreen extends ConsumerStatefulWidget {
|
||||
final Playlist playlist;
|
||||
|
||||
const EpgGridScreen({
|
||||
super.key,
|
||||
required this.playlist,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<EpgGridScreen> createState() => _EpgGridScreenState();
|
||||
}
|
||||
|
||||
class _EpgGridScreenState extends ConsumerState<EpgGridScreen>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final _horizontalScroll = ScrollController();
|
||||
final _verticalScroll = ScrollController();
|
||||
Map<String, List<EpgProgram>> _epgData = {};
|
||||
DateTime _selectedDate = DateTime.now();
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 7, vsync: this);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadEpgData();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_horizontalScroll.dispose();
|
||||
_verticalScroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadEpgData() async {
|
||||
if (_isLoading) return;
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final service = ref.read(xtreamServiceProvider(widget.playlist));
|
||||
final channels = await service.getLiveChannels();
|
||||
|
||||
final epgMap = <String, List<EpgProgram>>{};
|
||||
|
||||
// Load EPG for each channel
|
||||
for (final channel in channels) {
|
||||
try {
|
||||
final epg = await service.getFullEpg(channel.streamId.toString());
|
||||
final programs = _parseEpgPrograms(epg, channel.streamId.toString());
|
||||
epgMap[channel.streamId.toString()] = programs;
|
||||
} catch (e) {
|
||||
print('Error loading EPG for ${channel.name}: $e');
|
||||
epgMap[channel.streamId.toString()] = [];
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_epgData = epgMap;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
print('Error loading EPG: $e');
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
List<EpgProgram> _parseEpgPrograms(
|
||||
Map<String, dynamic> epgData,
|
||||
String channelId,
|
||||
) {
|
||||
final programs = <EpgProgram>[];
|
||||
final now = DateTime.now();
|
||||
|
||||
// Parse EPG data structure
|
||||
if (epgData.containsKey('epg_listings')) {
|
||||
final listings = epgData['epg_listings'] as List;
|
||||
for (final item in listings) {
|
||||
try {
|
||||
final startStr = item['start'] as String?;
|
||||
final endStr = item['end'] as String?;
|
||||
final title = item['title'] as String?;
|
||||
final desc = item['description'] as String? ?? '';
|
||||
|
||||
if (startStr != null && endStr != null && title != null) {
|
||||
final start = _parseEpgTime(startStr);
|
||||
final end = _parseEpgTime(endStr);
|
||||
|
||||
programs.add(
|
||||
EpgProgram(
|
||||
id: '${channelId}_${start.millisecondsSinceEpoch}',
|
||||
channelId: channelId,
|
||||
title: title,
|
||||
description: desc,
|
||||
startTime: start,
|
||||
endTime: end,
|
||||
isNow: now.isAfter(start) && now.isBefore(end),
|
||||
isNext:
|
||||
start.isAfter(now) && start.difference(now).inMinutes < 60,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by start time
|
||||
programs.sort((a, b) => a.startTime.compareTo(b.startTime));
|
||||
return programs;
|
||||
}
|
||||
|
||||
DateTime _parseEpgTime(String timeStr) {
|
||||
try {
|
||||
// Handle various formats: "12:30", "12:30:00", unix timestamp
|
||||
if (timeStr.contains(':')) {
|
||||
final parts = timeStr.split(':');
|
||||
final hours = int.parse(parts[0]);
|
||||
final minutes = int.parse(parts[1]);
|
||||
final today = DateTime.now();
|
||||
return DateTime(today.year, today.month, today.day, hours, minutes);
|
||||
} else {
|
||||
return DateTime.fromMillisecondsSinceEpoch(int.parse(timeStr) * 1000);
|
||||
}
|
||||
} catch (e) {
|
||||
return DateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('EPG Guide'),
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
isScrollable: true,
|
||||
onTap: (index) {
|
||||
setState(() {
|
||||
_selectedDate = DateTime.now().add(Duration(days: index));
|
||||
});
|
||||
},
|
||||
tabs: List.generate(7, (index) {
|
||||
final date = DateTime.now().add(Duration(days: index));
|
||||
final day = DateFormat('EEE').format(date);
|
||||
final dateNum = DateFormat('d').format(date);
|
||||
return Tab(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(day, style: const TextStyle(fontSize: 11)),
|
||||
Text(
|
||||
dateNum,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _buildEpgGrid(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEpgGrid() {
|
||||
if (_epgData.isEmpty) {
|
||||
return const Center(
|
||||
child: Text('No EPG data available'),
|
||||
);
|
||||
}
|
||||
|
||||
final channels = _epgData.keys.toList();
|
||||
|
||||
return Scrollbar(
|
||||
controller: _horizontalScroll,
|
||||
child: SingleChildScrollView(
|
||||
controller: _horizontalScroll,
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Column(
|
||||
children: [
|
||||
// Time headers
|
||||
SizedBox(
|
||||
height: 60,
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
right: BorderSide(color: Colors.grey[700]!),
|
||||
bottom: BorderSide(color: Colors.grey[700]!),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
...List.generate(24, (hour) {
|
||||
return Container(
|
||||
width: 100,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
right: BorderSide(color: Colors.grey[700]!),
|
||||
bottom: BorderSide(color: Colors.grey[700]!),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'$hour:00',
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Channel rows
|
||||
Expanded(
|
||||
child: Scrollbar(
|
||||
controller: _verticalScroll,
|
||||
child: ListView.builder(
|
||||
controller: _verticalScroll,
|
||||
itemCount: channels.length,
|
||||
itemBuilder: (context, index) {
|
||||
final channelId = channels[index];
|
||||
final programs = _epgData[channelId] ?? [];
|
||||
|
||||
return _EpgChannelRow(
|
||||
channelId: channelId,
|
||||
programs: programs,
|
||||
onProgramTap: (program) {
|
||||
_showProgramDetail(program);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showProgramDetail(EpgProgram program) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => _ProgramDetailSheet(program: program),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Individual channel row in EPG grid
|
||||
class _EpgChannelRow extends StatelessWidget {
|
||||
final String channelId;
|
||||
final List<EpgProgram> programs;
|
||||
final Function(EpgProgram) onProgramTap;
|
||||
|
||||
const _EpgChannelRow({
|
||||
required this.channelId,
|
||||
required this.programs,
|
||||
required this.onProgramTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
// Channel name
|
||||
Container(
|
||||
width: 150,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
right: BorderSide(color: Colors.grey[700]!),
|
||||
bottom: BorderSide(color: Colors.grey[700]!),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Text(
|
||||
channelId,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Programs
|
||||
...programs.map((program) {
|
||||
final duration = program.duration.inMinutes;
|
||||
final width =
|
||||
(duration / 60 * 100).clamp(40, double.infinity).toDouble();
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => onProgramTap(program),
|
||||
child: Container(
|
||||
width: width,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
color: program.isNow
|
||||
? Colors.blue.withOpacity(0.7)
|
||||
: program.isNext
|
||||
? Colors.purple.withOpacity(0.5)
|
||||
: Colors.grey[800],
|
||||
border: Border(
|
||||
right: BorderSide(color: Colors.grey[700]!),
|
||||
bottom: BorderSide(color: Colors.grey[700]!),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Program info
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
program.title,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${DateFormat('HH:mm').format(program.startTime)} - ${DateFormat('HH:mm').format(program.endTime)}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Progress bar for now playing
|
||||
if (program.isNow)
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(4),
|
||||
bottomRight: Radius.circular(4),
|
||||
),
|
||||
child: LinearProgressIndicator(
|
||||
value: program.progress / 100,
|
||||
minHeight: 3,
|
||||
backgroundColor: Colors.white24,
|
||||
valueColor: const AlwaysStoppedAnimation(Colors.red),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Program detail bottom sheet
|
||||
class _ProgramDetailSheet extends StatelessWidget {
|
||||
final EpgProgram program;
|
||||
|
||||
const _ProgramDetailSheet({required this.program});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
program.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
program.isNow ? Icons.play_circle : Icons.schedule,
|
||||
color: program.isNow ? Colors.green : Colors.orange,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${DateFormat('HH:mm').format(program.startTime)} - ${DateFormat('HH:mm').format(program.endTime)}',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Text(
|
||||
'${program.duration.inMinutes} min',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
program.description.isEmpty
|
||||
? 'No description available'
|
||||
: program.description,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
icon: const Icon(Icons.play_arrow),
|
||||
label: const Text('Watch Now'),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
icon: const Icon(Icons.event),
|
||||
label: const Text('Add Reminder'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,10 @@ import '../providers/playback_positions_provider.dart';
|
||||
// ... (existing imports)
|
||||
// ... (existing imports)
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../../../core/models/iptv_models.dart';
|
||||
import '../../../core/widgets/tv_focusable_card.dart';
|
||||
import '../../../core/widgets/glass_container.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../widgets/epg_overlay.dart';
|
||||
|
||||
enum StreamType { live, vod, series }
|
||||
enum StreamType { live, vod, series, recording }
|
||||
|
||||
class PlayerScreen extends ConsumerStatefulWidget {
|
||||
final String streamId;
|
||||
@@ -57,7 +54,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
StreamSubscription? _messageSubscription;
|
||||
final String _aspectRatio = 'contain';
|
||||
bool _isSeeking = false;
|
||||
late final String _viewIdPrefix = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
late final String _viewIdPrefix =
|
||||
DateTime.now().millisecondsSinceEpoch.toString();
|
||||
String _viewId = 'iptv-player';
|
||||
String? _currentStreamUrl;
|
||||
String _statusMessage = 'Loading...';
|
||||
@@ -129,12 +127,14 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
currentStreamId,
|
||||
widget.containerExtension,
|
||||
);
|
||||
} else if (widget.streamType == StreamType.recording) {
|
||||
streamUrl = '${service.backendBaseUrl}/api/recordings/stream/$currentStreamId/playlist.m3u8';
|
||||
}
|
||||
|
||||
// Store URL for Lite Player
|
||||
final isMobile = MediaQuery.of(context).size.width < 600;
|
||||
final isLiveTV = widget.streamType == StreamType.live;
|
||||
|
||||
|
||||
// TURBO-START: Use direct MPEG-TS for Live TV on Desktop/Android for instant zapping
|
||||
if (isLiveTV && !isMobile) {
|
||||
streamUrl = service.getLiveStreamUrlTs(currentStreamId);
|
||||
@@ -152,15 +152,23 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
// Force player choice based on stream type:
|
||||
// - Live TV: Player Lite (simple TS playback with mpegts.js)
|
||||
// - VOD/Series: Player Standard (fuller controls, HLS support)
|
||||
|
||||
|
||||
// Cache buster to force reload of updated player.html
|
||||
final cacheBuster = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
final streamTypeParam = widget.streamType == StreamType.live ? 'live' : 'vod';
|
||||
final playerFile = isMobile ? 'player_mobile.html' : (isLiveTV ? 'player_lite.html' : 'player.html');
|
||||
|
||||
final streamTypeParam =
|
||||
widget.streamType == StreamType.live ? 'live' : 'vod';
|
||||
final playerFile = isMobile
|
||||
? 'player_mobile.html'
|
||||
: (isLiveTV ? 'player_lite.html' : 'player.html');
|
||||
|
||||
// Inject Turbo-Start flag
|
||||
var playerSrc = '$playerFile?url=$encodedUrl&type=$streamTypeParam&turbo=true&v=$cacheBuster';
|
||||
var playerSrc =
|
||||
'$playerFile?url=$encodedUrl&type=$streamTypeParam&turbo=true&v=$cacheBuster';
|
||||
|
||||
if (widget.streamType == StreamType.recording) {
|
||||
playerSrc += '&is_recording=true';
|
||||
}
|
||||
|
||||
if (startTimeOverride != null) {
|
||||
playerSrc += '&t=$startTimeOverride';
|
||||
@@ -300,31 +308,16 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
void _toggleFullscreen() {
|
||||
try {
|
||||
final doc = html.document;
|
||||
final isFullscreen = doc.fullscreenElement != null ||
|
||||
(doc as dynamic).webkitFullscreenElement != null ||
|
||||
(doc as dynamic).mozFullScreenElement != null;
|
||||
final isFullscreen = doc.fullscreenElement != null ||
|
||||
(doc as dynamic).webkitFullscreenElement != null ||
|
||||
(doc as dynamic).mozFullScreenElement != null;
|
||||
|
||||
if (isFullscreen) {
|
||||
if (doc.exitFullscreen != null) {
|
||||
doc.exitFullscreen();
|
||||
} else if ((doc as dynamic).webkitExitFullscreen != null) {
|
||||
(doc as dynamic).webkitExitFullscreen();
|
||||
} else if ((doc as dynamic).mozCancelFullScreen != null) {
|
||||
(doc as dynamic).mozCancelFullScreen();
|
||||
}
|
||||
doc.exitFullscreen();
|
||||
} else {
|
||||
final element = doc.documentElement;
|
||||
if (element != null) {
|
||||
if (element.requestFullscreen != null) {
|
||||
element.requestFullscreen();
|
||||
} else if ((element as dynamic).webkitRequestFullscreen != null) {
|
||||
(element as dynamic).webkitRequestFullscreen();
|
||||
} else if ((element as dynamic).mozRequestFullScreen != null) {
|
||||
(element as dynamic).mozRequestFullScreen();
|
||||
} else {
|
||||
// Fallback: Message the player if browser API fails
|
||||
_sendMessage({'type': 'request_fullscreen'});
|
||||
}
|
||||
element.requestFullscreen();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -442,16 +435,19 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
children: [
|
||||
Text(
|
||||
widget.channels != null
|
||||
? (widget.channels![_currentIndex]
|
||||
? (widget
|
||||
.channels![
|
||||
_currentIndex]
|
||||
.name ??
|
||||
widget.channels![
|
||||
widget
|
||||
.channels![
|
||||
_currentIndex]
|
||||
.title ??
|
||||
'Unknown')
|
||||
.toString()
|
||||
: widget.title,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurface,
|
||||
style: GoogleFonts.outfit(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -478,29 +474,34 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
// Unified Bottom Bar - EPG + Controls in one bar
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
bottom: _showControls ? 24 : -150, // More offset for stacked layout
|
||||
bottom: _showControls
|
||||
? 24
|
||||
: -150, // More offset for stacked layout
|
||||
left: 16,
|
||||
right: 16,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isSmallScreen = constraints.maxWidth < 600;
|
||||
final isSmallScreen =
|
||||
constraints.maxWidth < 600;
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: isSmallScreen ? 16 : 20,
|
||||
vertical: isSmallScreen ? 12 : 16,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A2E).withOpacity(0.95),
|
||||
color: AppColors.surface.withOpacity(0.95),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.background.withOpacity(0.3),
|
||||
color: AppColors.background
|
||||
.withOpacity(0.3),
|
||||
blurRadius: 10,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
],
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
color: AppColors.textPrimary
|
||||
.withOpacity(0.15),
|
||||
),
|
||||
),
|
||||
child: isSmallScreen
|
||||
@@ -510,14 +511,17 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
// EPG Info (top in mobile)
|
||||
_buildInlineEpg(),
|
||||
const SizedBox(height: 12),
|
||||
const Divider(color: AppColors.outlineVariant),
|
||||
const Divider(
|
||||
color: Colors.white10,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Control Buttons
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: _buildControlButtons(
|
||||
isSmallScreen),
|
||||
isSmallScreen,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -532,7 +536,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: _buildControlButtons(
|
||||
isSmallScreen),
|
||||
isSmallScreen,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -554,7 +559,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
|
||||
// STANDARD PLAYER MODE (VOD/Series)
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
@@ -585,7 +590,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
Positioned.fill(
|
||||
child: PointerInterceptor(
|
||||
child: Container(
|
||||
color: AppColors.background.withOpacity(0.4),
|
||||
color: Colors.black.withOpacity(0.4),
|
||||
child: Stack(
|
||||
children: [
|
||||
// Top Bar
|
||||
@@ -593,9 +598,10 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
top: 24,
|
||||
left: 24,
|
||||
right: 24,
|
||||
child: GlassContainer.glass(
|
||||
child: GlassContainer(
|
||||
height: 72,
|
||||
borderRadius: 24,
|
||||
opacity: 0.1,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -607,10 +613,10 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.title,
|
||||
style: GoogleFonts.inter(
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -632,8 +638,11 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
bottom: 40,
|
||||
left: 40,
|
||||
right: 40,
|
||||
child: GlassContainer.glass(
|
||||
child: GlassContainer(
|
||||
borderRadius: 24,
|
||||
opacity: 0.2, // Slightly more opaque for controls
|
||||
hasBorder: true,
|
||||
borderColor: Colors.white.withOpacity(0.1),
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -648,7 +657,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
),
|
||||
),
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: Colors.white70,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
@@ -659,7 +668,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
activeTrackColor: AppColors.primary,
|
||||
inactiveTrackColor:
|
||||
Colors.white.withOpacity(0.2),
|
||||
thumbColor: AppColors.onSurface,
|
||||
thumbColor: Colors.white,
|
||||
thumbShape: const RoundSliderThumbShape(
|
||||
enabledThumbRadius: 8,
|
||||
),
|
||||
@@ -700,7 +709,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
),
|
||||
),
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: Colors.white70,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -796,7 +805,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
? null
|
||||
: Border.all(color: Colors.white.withOpacity(0.1)),
|
||||
),
|
||||
child: Icon(icon, color: AppColors.onSurface, size: iconSize),
|
||||
child: Icon(icon, color: Colors.white, size: iconSize),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -847,7 +856,6 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
onTap: _toggleMute,
|
||||
size: buttonSize,
|
||||
),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -887,7 +895,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: highlighted ? AppColors.primary : AppColors.onSurface,
|
||||
color: highlighted ? AppColors.primary : Colors.white,
|
||||
size: iconSize,
|
||||
),
|
||||
),
|
||||
@@ -919,13 +927,13 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.error,
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'LIVE',
|
||||
style: TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
@@ -937,8 +945,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
widget.channels != null
|
||||
? widget.channels![_currentIndex].name
|
||||
: widget.title,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurface,
|
||||
style: GoogleFonts.outfit(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -967,13 +975,13 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.error,
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'LIVE',
|
||||
style: TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
@@ -987,8 +995,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
children: [
|
||||
Text(
|
||||
currentProgram.title,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurface,
|
||||
style: GoogleFonts.outfit(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -999,7 +1007,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
Text(
|
||||
currentProgram.description,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: Colors.white60,
|
||||
fontSize: 12,
|
||||
),
|
||||
maxLines: 1,
|
||||
@@ -1016,13 +1024,13 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.error,
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'LIVE',
|
||||
style: TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
@@ -1033,8 +1041,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
widget.channels != null
|
||||
? widget.channels![_currentIndex].name
|
||||
: widget.title,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurface,
|
||||
style: GoogleFonts.outfit(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -1045,8 +1053,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
widget.channels != null
|
||||
? widget.channels![_currentIndex].name
|
||||
: widget.title,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurface,
|
||||
style: GoogleFonts.outfit(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -1055,5 +1063,4 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,9 +27,9 @@ class PlaylistSelectionScreen extends ConsumerWidget {
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'Select Playlist',
|
||||
style: GoogleFonts.inter(
|
||||
style: GoogleFonts.roboto(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.transparent,
|
||||
@@ -37,13 +37,15 @@ class PlaylistSelectionScreen extends ConsumerWidget {
|
||||
actions: [
|
||||
if (currentUser?.isAdmin ?? false)
|
||||
IconButton(
|
||||
icon:
|
||||
const Icon(Icons.admin_panel_settings, color: AppColors.onSurfaceVariant),
|
||||
icon: const Icon(
|
||||
Icons.admin_panel_settings,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
onPressed: () => context.go('/admin'),
|
||||
tooltip: 'Admin Panel',
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout, color: AppColors.onSurfaceVariant),
|
||||
icon: const Icon(Icons.logout, color: AppColors.textSecondary),
|
||||
onPressed: () async {
|
||||
await ref.read(authProvider.notifier).logout();
|
||||
if (context.mounted) {
|
||||
@@ -57,107 +59,122 @@ class PlaylistSelectionScreen extends ConsumerWidget {
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF0F1014), // Deep Space Dark
|
||||
Color(0xFF181920), // Soft Eerie Black
|
||||
Color(0xFF050505),
|
||||
AppColors.background,
|
||||
Color(0xFF0A0A0A),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: playlistsAsync.when(
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
),
|
||||
error: (error, stack) => Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error_outline,
|
||||
size: 64, color: AppColors.error),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Error loading playlists',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 18,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ElevatedButton(
|
||||
onPressed: () => ref.refresh(playlistsProvider),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: AppColors.onSurface,
|
||||
),
|
||||
child: Text('Retry', style: GoogleFonts.inter()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
data: (playlists) {
|
||||
if (playlists.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.playlist_remove,
|
||||
size: 64,
|
||||
color: AppColors.outlineVariant,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No playlists available',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 18,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
currentUser?.isAdmin ?? false
|
||||
? 'Add playlists in Admin Panel'
|
||||
: 'Contact administrator',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
color: AppColors.outline,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
48,
|
||||
100,
|
||||
48,
|
||||
48,
|
||||
), // More padding for cinematic feel
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount:
|
||||
MediaQuery.of(context).size.width > 1200 ? 4 : 3,
|
||||
crossAxisSpacing: 32,
|
||||
mainAxisSpacing: 32,
|
||||
childAspectRatio: 1.4,
|
||||
),
|
||||
itemCount: playlists.length,
|
||||
itemBuilder: (context, index) {
|
||||
final playlist = playlists[index];
|
||||
return _PlaylistCard(
|
||||
playlist: playlist,
|
||||
onTap: () {
|
||||
// Update current selected playlist provider first
|
||||
ref.read(selectedPlaylistProvider.notifier).state = playlist;
|
||||
// Then navigate to dashboard
|
||||
context.go('/dashboard');
|
||||
},
|
||||
child: SafeArea(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Safety: if constraints are invalid, show loading spinner
|
||||
if (!constraints.maxWidth.isFinite ||
|
||||
constraints.maxWidth <= 0 ||
|
||||
!constraints.maxHeight.isFinite ||
|
||||
constraints.maxHeight <= 0) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
return playlistsAsync.when(
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
),
|
||||
error: (error, stack) => Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: AppColors.error,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Error loading playlists',
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 18,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ElevatedButton(
|
||||
onPressed: () => ref.refresh(playlistsProvider),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: AppColors.textPrimary,
|
||||
),
|
||||
child: Text('Retry', style: GoogleFonts.inter()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
data: (playlists) {
|
||||
if (playlists.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.playlist_remove,
|
||||
size: 64,
|
||||
color: Colors.white24,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No playlists available',
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 18,
|
||||
color: Colors.white60,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
currentUser?.isAdmin ?? false
|
||||
? 'Add playlists in Admin Panel'
|
||||
: 'Contact administrator',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
color: Colors.white38,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Simple Wrap layout - no grid, no NaN-prone calculations
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(48, 32, 48, 48),
|
||||
child: Wrap(
|
||||
spacing: 32,
|
||||
runSpacing: 32,
|
||||
children: playlists.map((playlist) {
|
||||
return SizedBox(
|
||||
width: 340,
|
||||
height: 240,
|
||||
child: _PlaylistCard(
|
||||
playlist: playlist,
|
||||
onTap: () {
|
||||
ref
|
||||
.read(selectedPlaylistProvider.notifier)
|
||||
.state = playlist;
|
||||
context.go('/dashboard');
|
||||
},
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -193,7 +210,7 @@ class _PlaylistCardState extends State<_PlaylistCard> {
|
||||
decoration: BoxDecoration(
|
||||
color: _isHovered
|
||||
? Colors.white.withOpacity(0.1)
|
||||
: Colors.white.withOpacity(0.03), // Subtle glass
|
||||
: Colors.white.withOpacity(0.03),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(
|
||||
color: _isHovered
|
||||
@@ -246,16 +263,16 @@ class _PlaylistCardState extends State<_PlaylistCard> {
|
||||
child: Icon(
|
||||
Icons.playlist_play_rounded,
|
||||
size: 32,
|
||||
color: _isHovered ? AppColors.onSurface : AppColors.onSurfaceVariant,
|
||||
color: _isHovered ? Colors.white : Colors.white70,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
widget.playlist.name,
|
||||
style: GoogleFonts.inter(
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
height: 1.2,
|
||||
),
|
||||
maxLines: 2,
|
||||
@@ -266,7 +283,7 @@ class _PlaylistCardState extends State<_PlaylistCard> {
|
||||
Uri.tryParse(widget.playlist.dns)?.host ?? widget.playlist.dns,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 13,
|
||||
color: AppColors.outline,
|
||||
color: Colors.white38,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
maxLines: 1,
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
/// Represents a download task
|
||||
class DownloadTask {
|
||||
final String id;
|
||||
final String title;
|
||||
final String url;
|
||||
final String filePath;
|
||||
final DownloadStatus status;
|
||||
final double progress;
|
||||
final int? totalSize;
|
||||
final int downloadedSize;
|
||||
|
||||
DownloadTask({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.url,
|
||||
required this.filePath,
|
||||
this.status = DownloadStatus.pending,
|
||||
this.progress = 0.0,
|
||||
this.totalSize,
|
||||
this.downloadedSize = 0,
|
||||
});
|
||||
|
||||
DownloadTask copyWith({
|
||||
DownloadStatus? status,
|
||||
double? progress,
|
||||
int? downloadedSize,
|
||||
}) =>
|
||||
DownloadTask(
|
||||
id: id,
|
||||
title: title,
|
||||
url: url,
|
||||
filePath: filePath,
|
||||
status: status ?? this.status,
|
||||
progress: progress ?? this.progress,
|
||||
totalSize: totalSize,
|
||||
downloadedSize: downloadedSize ?? this.downloadedSize,
|
||||
);
|
||||
}
|
||||
|
||||
enum DownloadStatus {
|
||||
pending,
|
||||
downloading,
|
||||
paused,
|
||||
completed,
|
||||
failed,
|
||||
cancelled,
|
||||
}
|
||||
|
||||
/// Service for managing downloads
|
||||
class DownloadService {
|
||||
static const _downloadDir = './downloads';
|
||||
static const _maxConcurrentDownloads = 3;
|
||||
static const _maxStorageGb = 50;
|
||||
|
||||
final List<DownloadTask> _downloads = [];
|
||||
final List<String> _activeDownloads = [];
|
||||
|
||||
/// Initialize download directory
|
||||
static Future<void> initialize() async {
|
||||
final dir = Directory(_downloadDir);
|
||||
if (!dir.existsSync()) {
|
||||
await dir.create(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Start a new download
|
||||
Future<DownloadTask> startDownload({
|
||||
required String id,
|
||||
required String title,
|
||||
required String url,
|
||||
}) async {
|
||||
final filePath = '$_downloadDir/$id.mp4';
|
||||
final task = DownloadTask(
|
||||
id: id,
|
||||
title: title,
|
||||
url: url,
|
||||
filePath: filePath,
|
||||
);
|
||||
|
||||
_downloads.add(task);
|
||||
_processDownloadQueue();
|
||||
return task;
|
||||
}
|
||||
|
||||
/// Pause download
|
||||
void pauseDownload(String id) {
|
||||
final index = _downloads.indexWhere((t) => t.id == id);
|
||||
if (index != -1) {
|
||||
_downloads[index] = _downloads[index].copyWith(
|
||||
status: DownloadStatus.paused,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Resume download
|
||||
void resumeDownload(String id) {
|
||||
final index = _downloads.indexWhere((t) => t.id == id);
|
||||
if (index != -1) {
|
||||
_downloads[index] = _downloads[index].copyWith(
|
||||
status: DownloadStatus.pending,
|
||||
);
|
||||
_processDownloadQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/// Cancel download
|
||||
void cancelDownload(String id) {
|
||||
final index = _downloads.indexWhere((t) => t.id == id);
|
||||
if (index != -1) {
|
||||
_downloads.removeAt(index);
|
||||
_activeDownloads.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all downloads
|
||||
List<DownloadTask> getAllDownloads() => List.from(_downloads);
|
||||
|
||||
/// Get download progress
|
||||
double getDownloadProgress(String id) {
|
||||
final task = _downloads.firstWhere(
|
||||
(t) => t.id == id,
|
||||
orElse: () => DownloadTask(
|
||||
id: id,
|
||||
title: '',
|
||||
url: '',
|
||||
filePath: '',
|
||||
),
|
||||
);
|
||||
return task.progress;
|
||||
}
|
||||
|
||||
/// Get available storage
|
||||
Future<int> getAvailableStorage() async {
|
||||
final dir = Directory(_downloadDir);
|
||||
if (!dir.existsSync()) return _maxStorageGb * 1024 * 1024 * 1024;
|
||||
|
||||
int totalSize = 0;
|
||||
final files = dir.listSync(recursive: true);
|
||||
for (final file in files) {
|
||||
if (file is File) {
|
||||
totalSize += file.lengthSync();
|
||||
}
|
||||
}
|
||||
|
||||
return (_maxStorageGb * 1024 * 1024 * 1024) - totalSize;
|
||||
}
|
||||
|
||||
/// Clean up old downloads based on space
|
||||
Future<void> cleanupOldDownloads() async {
|
||||
final available = await getAvailableStorage();
|
||||
if (available < 1024 * 1024 * 1024) {
|
||||
// Less than 1GB free
|
||||
final dir = Directory(_downloadDir);
|
||||
final files = dir.listSync().whereType<File>().toList();
|
||||
|
||||
// Sort by modification time, delete oldest first
|
||||
files.sort(
|
||||
(a, b) => a.statSync().modified.compareTo(b.statSync().modified),
|
||||
);
|
||||
|
||||
for (final file in files.take(files.length ~/ 3)) {
|
||||
try {
|
||||
file.deleteSync();
|
||||
} catch (e) {
|
||||
print('Error deleting file: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Process download queue
|
||||
Future<void> _processDownloadQueue() async {
|
||||
while (_activeDownloads.length < _maxConcurrentDownloads) {
|
||||
final pendingIndex =
|
||||
_downloads.indexWhere((t) => t.status == DownloadStatus.pending);
|
||||
if (pendingIndex == -1) break;
|
||||
|
||||
final task = _downloads[pendingIndex];
|
||||
_activeDownloads.add(task.id);
|
||||
|
||||
_downloads[pendingIndex] =
|
||||
task.copyWith(status: DownloadStatus.downloading);
|
||||
|
||||
try {
|
||||
await _downloadFile(task);
|
||||
} catch (e) {
|
||||
print('Download error: $e');
|
||||
final index = _downloads.indexWhere((t) => t.id == task.id);
|
||||
if (index != -1) {
|
||||
_downloads[index] =
|
||||
_downloads[index].copyWith(status: DownloadStatus.failed);
|
||||
}
|
||||
} finally {
|
||||
_activeDownloads.remove(task.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Download file with progress tracking
|
||||
Future<void> _downloadFile(DownloadTask task) async {
|
||||
// Simplified version - in production use dio or http with progress tracking
|
||||
final file = File(task.filePath);
|
||||
if (!file.existsSync()) {
|
||||
file.createSync(recursive: true);
|
||||
}
|
||||
|
||||
// Stream download and update progress
|
||||
// This is a placeholder - implement with actual download logic
|
||||
for (int i = 0; i <= 100; i++) {
|
||||
final index = _downloads.indexWhere((t) => t.id == task.id);
|
||||
if (index != -1) {
|
||||
_downloads[index] = _downloads[index].copyWith(
|
||||
progress: i.toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
// Check if paused or cancelled
|
||||
final currentTask =
|
||||
_downloads.firstWhere((t) => t.id == task.id, orElse: () => task);
|
||||
if (currentTask.status == DownloadStatus.paused ||
|
||||
!_activeDownloads.contains(task.id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
|
||||
// Mark as completed
|
||||
final index = _downloads.indexWhere((t) => t.id == task.id);
|
||||
if (index != -1) {
|
||||
_downloads[index] = _downloads[index].copyWith(
|
||||
status: DownloadStatus.completed,
|
||||
progress: 100.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if file is available for offline playback
|
||||
bool isAvailableOffline(String id) {
|
||||
final task = _downloads.firstWhere(
|
||||
(t) => t.id == id,
|
||||
orElse: () => DownloadTask(
|
||||
id: id,
|
||||
title: '',
|
||||
url: '',
|
||||
filePath: '',
|
||||
),
|
||||
);
|
||||
if (task.status == DownloadStatus.completed) {
|
||||
return File(task.filePath).existsSync();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Get file path for offline content
|
||||
String? getOfflineFilePath(String id) {
|
||||
final task = _downloads.firstWhere(
|
||||
(t) => t.id == id && t.status == DownloadStatus.completed,
|
||||
orElse: () => DownloadTask(
|
||||
id: id,
|
||||
title: '',
|
||||
url: '',
|
||||
filePath: '',
|
||||
),
|
||||
);
|
||||
|
||||
if (File(task.filePath).existsSync()) {
|
||||
return task.filePath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Riverpod providers
|
||||
|
||||
final downloadServiceProvider = Provider<DownloadService>((ref) {
|
||||
return DownloadService();
|
||||
});
|
||||
|
||||
final downloadsProvider =
|
||||
StateNotifierProvider<DownloadsNotifier, List<DownloadTask>>((ref) {
|
||||
return DownloadsNotifier();
|
||||
});
|
||||
|
||||
class DownloadsNotifier extends StateNotifier<List<DownloadTask>> {
|
||||
DownloadsNotifier() : super([]);
|
||||
|
||||
void addDownload(DownloadTask task) {
|
||||
state = [...state, task];
|
||||
}
|
||||
|
||||
void updateDownload(DownloadTask task) {
|
||||
state = [
|
||||
for (final d in state)
|
||||
if (d.id == task.id) task else d,
|
||||
];
|
||||
}
|
||||
|
||||
void removeDownload(String id) {
|
||||
state = state.where((d) => d.id != id).toList();
|
||||
}
|
||||
|
||||
void clearCompleted() {
|
||||
state = state.where((d) => d.status != DownloadStatus.completed).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
/// Subtitle track information
|
||||
class SubtitleTrack {
|
||||
final String id;
|
||||
final String name;
|
||||
final String language;
|
||||
final String url;
|
||||
final bool isEnabled;
|
||||
|
||||
SubtitleTrack({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.language,
|
||||
required this.url,
|
||||
this.isEnabled = false,
|
||||
});
|
||||
|
||||
SubtitleTrack copyWith({bool? isEnabled}) => SubtitleTrack(
|
||||
id: id,
|
||||
name: name,
|
||||
language: language,
|
||||
url: url,
|
||||
isEnabled: isEnabled ?? this.isEnabled,
|
||||
);
|
||||
}
|
||||
|
||||
/// Subtitle content with timing
|
||||
class SubtitleEntry {
|
||||
final int index;
|
||||
final Duration startTime;
|
||||
final Duration endTime;
|
||||
final String text;
|
||||
|
||||
SubtitleEntry({
|
||||
required this.index,
|
||||
required this.startTime,
|
||||
required this.endTime,
|
||||
required this.text,
|
||||
});
|
||||
}
|
||||
|
||||
/// Service for handling subtitles
|
||||
class SubtitleService {
|
||||
static const _srtPattern =
|
||||
r'(\d+)\n(\d{2}):(\d{2}):(\d{2}),(\d{3}) --> (\d{2}):(\d{2}):(\d{2}),(\d{3})\n([\s\S]*?)(?=\n\n|\Z)';
|
||||
|
||||
/// Parse SRT subtitle content
|
||||
static List<SubtitleEntry> parseSrt(String content) {
|
||||
final entries = <SubtitleEntry>[];
|
||||
final blocks = content.split('\n\n');
|
||||
|
||||
for (final block in blocks) {
|
||||
if (block.trim().isEmpty) continue;
|
||||
|
||||
final lines = block.trim().split('\n');
|
||||
if (lines.length < 3) continue;
|
||||
|
||||
try {
|
||||
final index = int.parse(lines[0]);
|
||||
final timeLine = lines[1];
|
||||
final text = lines.sublist(2).join('\n').trim();
|
||||
|
||||
// Parse timing: 00:00:01,000 --> 00:00:05,000
|
||||
final times = timeLine.split('-->');
|
||||
if (times.length != 2) continue;
|
||||
|
||||
final startTime = _parseTime(times[0].trim());
|
||||
final endTime = _parseTime(times[1].trim());
|
||||
|
||||
entries.add(
|
||||
SubtitleEntry(
|
||||
index: index,
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
text: text,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/// Parse WebVTT subtitle content
|
||||
static List<SubtitleEntry> parseWebVtt(String content) {
|
||||
final entries = <SubtitleEntry>[];
|
||||
final blocks = content.split('\n\n');
|
||||
|
||||
for (final block in blocks) {
|
||||
if (block.trim().isEmpty || block.startsWith('WEBVTT')) continue;
|
||||
|
||||
final lines = block.trim().split('\n');
|
||||
if (lines.length < 2) continue;
|
||||
|
||||
try {
|
||||
final timeLine = lines[0];
|
||||
final text = lines.sublist(1).join('\n').trim();
|
||||
|
||||
// Parse timing: 00:00:01.000 --> 00:00:05.000
|
||||
final times = timeLine.split('-->');
|
||||
if (times.length != 2) continue;
|
||||
|
||||
final startTime = _parseWebVttTime(times[0].trim());
|
||||
final endTime = _parseWebVttTime(times[1].trim());
|
||||
|
||||
entries.add(
|
||||
SubtitleEntry(
|
||||
index: entries.length,
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
text: text,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/// Get subtitle at specific time
|
||||
static String? getSubtitleAtTime(List<SubtitleEntry> entries, Duration time) {
|
||||
for (final entry in entries) {
|
||||
if (time.compareTo(entry.startTime) >= 0 &&
|
||||
time.compareTo(entry.endTime) <= 0) {
|
||||
return entry.text;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Download subtitle from URL
|
||||
static Future<String> downloadSubtitle(String url) async {
|
||||
try {
|
||||
final response = await http.get(Uri.parse(url));
|
||||
if (response.statusCode == 200) {
|
||||
return response.body;
|
||||
}
|
||||
throw Exception('Failed to download subtitle: ${response.statusCode}');
|
||||
} catch (e) {
|
||||
throw Exception('Error downloading subtitle: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse time format HH:MM:SS,mmm (SRT)
|
||||
static Duration _parseTime(String time) {
|
||||
final parts = time.split(':');
|
||||
final hours = int.parse(parts[0]);
|
||||
final minutes = int.parse(parts[1]);
|
||||
final secondsParts = parts[2].split(',');
|
||||
final seconds = int.parse(secondsParts[0]);
|
||||
final milliseconds = int.parse(secondsParts[1]);
|
||||
|
||||
return Duration(
|
||||
hours: hours,
|
||||
minutes: minutes,
|
||||
seconds: seconds,
|
||||
milliseconds: milliseconds,
|
||||
);
|
||||
}
|
||||
|
||||
/// Parse time format HH:MM:SS.mmm (WebVTT)
|
||||
static Duration _parseWebVttTime(String time) {
|
||||
final parts = time.split(':');
|
||||
final hours = int.parse(parts[0]);
|
||||
final minutes = int.parse(parts[1]);
|
||||
final secondsParts = parts[2].split('.');
|
||||
final seconds = int.parse(secondsParts[0]);
|
||||
final milliseconds = int.parse(secondsParts[1].padEnd(3, '0'));
|
||||
|
||||
return Duration(
|
||||
hours: hours,
|
||||
minutes: minutes,
|
||||
seconds: seconds,
|
||||
milliseconds: milliseconds,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import 'dart:convert';
|
||||
import 'dart:html' as html;
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
|
||||
import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../../../core/models/iptv_models.dart';
|
||||
@@ -34,9 +33,9 @@ class XtreamService {
|
||||
);
|
||||
|
||||
// Setup caching for API responses
|
||||
// Use MemCacheStore on Web to avoid path errors
|
||||
// Use MemCacheStore for in-memory caching
|
||||
_cacheOptions = CacheOptions(
|
||||
store: kIsWeb ? MemCacheStore() : HiveCacheStore('./cache'),
|
||||
store: MemCacheStore(),
|
||||
policy: CachePolicy.forceCache, // Prioritize local cache
|
||||
maxStale: const Duration(hours: 1), // Increase to 1h for stability
|
||||
priority: CachePriority.high,
|
||||
@@ -184,11 +183,15 @@ class XtreamService {
|
||||
/// Get all live TV channels grouped by category
|
||||
///
|
||||
/// Returns a Map where key is category name and value is list of channels
|
||||
Future<Map<String, List<Channel>>> getLiveChannels({bool refresh = false}) async {
|
||||
Future<Map<String, List<Channel>>> getLiveChannels({
|
||||
bool refresh = false,
|
||||
}) async {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
final options = refresh
|
||||
? _cacheOptions.copyWith(policy: CachePolicy.refreshForceCache).toExtra()
|
||||
final options = refresh
|
||||
? _cacheOptions
|
||||
.copyWith(policy: CachePolicy.refreshForceCache)
|
||||
.toExtra()
|
||||
: _cacheOptions.toExtra();
|
||||
|
||||
try {
|
||||
@@ -227,7 +230,8 @@ class XtreamService {
|
||||
return groupedChannels;
|
||||
} catch (e) {
|
||||
// Try to return from local cache if network fails
|
||||
final cached = _loadFromLocalCache<Channel>('live_channels', Channel.fromJson);
|
||||
final cached =
|
||||
_loadFromLocalCache<Channel>('live_channels', Channel.fromJson);
|
||||
if (cached.isNotEmpty) return cached;
|
||||
throw Exception('Failed to fetch live channels: $e');
|
||||
}
|
||||
@@ -237,27 +241,30 @@ class XtreamService {
|
||||
if (!kIsWeb) return;
|
||||
try {
|
||||
final jsonStr = jsonEncode(data);
|
||||
html.window.localStorage['xtream_cache_${_currentPlaylist?.id}_$key'] = jsonStr;
|
||||
html.window.localStorage['xtream_cache_${_currentPlaylist?.id}_$key'] =
|
||||
jsonStr;
|
||||
} catch (e) {
|
||||
debugPrint('Error saving to local cache ($key): $e');
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<T>> _loadFromLocalCache<T>(
|
||||
String key, T Function(Map<String, dynamic>) fromJson) {
|
||||
String key,
|
||||
T Function(Map<String, dynamic>) fromJson,
|
||||
) {
|
||||
if (!kIsWeb) return {};
|
||||
try {
|
||||
final jsonStr = html.window.localStorage['xtream_cache_${_currentPlaylist?.id}_$key'];
|
||||
final jsonStr =
|
||||
html.window.localStorage['xtream_cache_${_currentPlaylist?.id}_$key'];
|
||||
if (jsonStr == null) return {};
|
||||
|
||||
|
||||
final data = jsonDecode(jsonStr) as Map<String, dynamic>;
|
||||
final result = <String, List<T>>{};
|
||||
|
||||
|
||||
data.forEach((cat, items) {
|
||||
if (items is List) {
|
||||
result[cat] = items
|
||||
.map((i) => fromJson(i as Map<String, dynamic>))
|
||||
.toList();
|
||||
result[cat] =
|
||||
items.map((i) => fromJson(i as Map<String, dynamic>)).toList();
|
||||
}
|
||||
});
|
||||
return result;
|
||||
@@ -302,8 +309,10 @@ class XtreamService {
|
||||
Future<Map<String, List<VodItem>>> getVodItems({bool refresh = false}) async {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
final options = refresh
|
||||
? _cacheOptions.copyWith(policy: CachePolicy.refreshForceCache).toExtra()
|
||||
final options = refresh
|
||||
? _cacheOptions
|
||||
.copyWith(policy: CachePolicy.refreshForceCache)
|
||||
.toExtra()
|
||||
: _cacheOptions.toExtra();
|
||||
|
||||
try {
|
||||
@@ -343,7 +352,8 @@ class XtreamService {
|
||||
return groupedVods;
|
||||
} catch (e) {
|
||||
// Try to return from local cache if network fails
|
||||
final cached = _loadFromLocalCache<VodItem>('vod_items', VodItem.fromJson);
|
||||
final cached =
|
||||
_loadFromLocalCache<VodItem>('vod_items', VodItem.fromJson);
|
||||
if (cached.isNotEmpty) return cached;
|
||||
throw Exception('Failed to fetch VOD items: $e');
|
||||
}
|
||||
@@ -384,8 +394,10 @@ class XtreamService {
|
||||
Future<Map<String, List<Series>>> getSeries({bool refresh = false}) async {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
final options = refresh
|
||||
? _cacheOptions.copyWith(policy: CachePolicy.refreshForceCache).toExtra()
|
||||
final options = refresh
|
||||
? _cacheOptions
|
||||
.copyWith(policy: CachePolicy.refreshForceCache)
|
||||
.toExtra()
|
||||
: _cacheOptions.toExtra();
|
||||
|
||||
try {
|
||||
@@ -425,15 +437,18 @@ class XtreamService {
|
||||
return groupedSeries;
|
||||
} catch (e) {
|
||||
// Try to return from local cache if network fails
|
||||
final cached = _loadFromLocalCache<Series>('series_items', Series.fromJson);
|
||||
final cached =
|
||||
_loadFromLocalCache<Series>('series_items', Series.fromJson);
|
||||
if (cached.isNotEmpty) return cached;
|
||||
throw Exception('Failed to fetch series: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Get movies with pagination support
|
||||
Future<List<xm.Movie>> getMoviesPaginated(
|
||||
{int offset = 0, int limit = 100}) async {
|
||||
Future<List<xm.Movie>> getMoviesPaginated({
|
||||
int offset = 0,
|
||||
int limit = 100,
|
||||
}) async {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
try {
|
||||
@@ -512,8 +527,10 @@ class XtreamService {
|
||||
}
|
||||
|
||||
/// Get series with pagination support (returns flat list)
|
||||
Future<List<xm.Series>> getSeriesPaginated(
|
||||
{int offset = 0, int limit = 100}) async {
|
||||
Future<List<xm.Series>> getSeriesPaginated({
|
||||
int offset = 0,
|
||||
int limit = 100,
|
||||
}) async {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,62 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../providers/favorites_provider.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../../iptv/providers/xtream_provider.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
class ChannelCard extends ConsumerStatefulWidget {
|
||||
final String streamId;
|
||||
final String name;
|
||||
final String? iconUrl;
|
||||
class ChannelCard extends StatefulWidget {
|
||||
final String channelNumber;
|
||||
final String channelName;
|
||||
final String? channelLogo;
|
||||
final String? currentProgram;
|
||||
final bool isLive;
|
||||
final String? programTime;
|
||||
final bool isFavorite;
|
||||
final VoidCallback? onTap;
|
||||
final double? width;
|
||||
final double? height;
|
||||
final PlaylistConfig playlist;
|
||||
final VoidCallback? onFavoriteTap;
|
||||
final bool isActive;
|
||||
|
||||
const ChannelCard({
|
||||
super.key,
|
||||
required this.streamId,
|
||||
required this.name,
|
||||
required this.playlist,
|
||||
this.iconUrl,
|
||||
required this.channelNumber,
|
||||
required this.channelName,
|
||||
this.channelLogo,
|
||||
this.currentProgram,
|
||||
this.isLive = true,
|
||||
this.programTime,
|
||||
this.isFavorite = false,
|
||||
this.onTap,
|
||||
this.width,
|
||||
this.height,
|
||||
this.onFavoriteTap,
|
||||
this.isActive = false,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<ChannelCard> createState() => _ChannelCardState();
|
||||
State<ChannelCard> createState() => _ChannelCardState();
|
||||
}
|
||||
|
||||
class _ChannelCardState extends ConsumerState<ChannelCard>
|
||||
class _ChannelCardState extends State<ChannelCard>
|
||||
with SingleTickerProviderStateMixin {
|
||||
bool _isHovered = false;
|
||||
late AnimationController _pulseController;
|
||||
|
||||
// EPG State
|
||||
String? _epgNow;
|
||||
bool _epgLoaded = false;
|
||||
|
||||
late Animation<double> _pulseAnimation;
|
||||
bool _isHovered = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pulseController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1000),
|
||||
vsync: this,
|
||||
duration: AppTheme.durationMd,
|
||||
)..repeat(reverse: true);
|
||||
|
||||
// Fetch EPG immediately when card is built
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_fetchEpg();
|
||||
});
|
||||
|
||||
_pulseAnimation = Tween<double>(begin: 1.0, end: 1.05).animate(
|
||||
CurvedAnimation(parent: _pulseController, curve: AppTheme.curveSmooth),
|
||||
);
|
||||
|
||||
if (widget.isActive) {
|
||||
_pulseController.forward();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChannelCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.isActive && !oldWidget.isActive) {
|
||||
_pulseController.forward();
|
||||
} else if (!widget.isActive && oldWidget.isActive) {
|
||||
_pulseController.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -65,218 +70,158 @@ class _ChannelCardState extends ConsumerState<ChannelCard>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _fetchEpg() async {
|
||||
if (_epgLoaded) return;
|
||||
|
||||
try {
|
||||
// Don't modify state if unmounted
|
||||
if (!mounted) return;
|
||||
|
||||
final service = ref.read(xtreamServiceProvider(widget.playlist));
|
||||
// We use the short EPG endpoint for quick access
|
||||
final entries = await service.getShortEpg(widget.streamId);
|
||||
|
||||
if (mounted && entries.isNotEmpty) {
|
||||
final now = DateTime.now();
|
||||
// Find current program
|
||||
final current = entries.firstWhere(
|
||||
(e) {
|
||||
try {
|
||||
final start = DateTime.parse(e.start);
|
||||
final end = DateTime.parse(e.end);
|
||||
return now.isAfter(start) && now.isBefore(end);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
orElse: () => entries.first,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_epgNow = current.title;
|
||||
_epgLoaded = true;
|
||||
});
|
||||
}
|
||||
} catch (_) {
|
||||
// Fail silently
|
||||
if (mounted) setState(() => _epgLoaded = true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final favorites = ref.watch(favoritesProvider);
|
||||
final isFavorite = favorites.contains(widget.streamId);
|
||||
|
||||
// Dynamic sizing based on hover
|
||||
return MouseRegion(
|
||||
onEnter: (_) {
|
||||
setState(() => _isHovered = true);
|
||||
},
|
||||
onExit: (_) => setState(() => _isHovered = false),
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _isHovered = true),
|
||||
onExit: (_) => setState(() => _isHovered = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// The Image Card (Scales)
|
||||
AnimatedScale(
|
||||
scale: _isHovered ? 1.05 : 1.0,
|
||||
duration: AppTheme.durationFast,
|
||||
curve: AppTheme.curveDefault,
|
||||
child: AnimatedContainer(
|
||||
duration: AppTheme.durationFast,
|
||||
width: widget.width ?? 180,
|
||||
height: widget.height ?? 110,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
color: AppColors.surface, // Fallback color
|
||||
// Thick white border on focus (tvOS style)
|
||||
border: Border.all(
|
||||
color: _isHovered ? AppColors.primaryContainer : Colors.transparent,
|
||||
width: _isHovered ? 3 : 0,
|
||||
child: ScaleTransition(
|
||||
scale: widget.isActive
|
||||
? _pulseAnimation
|
||||
: const AlwaysStoppedAnimation(1.0),
|
||||
child: AnimatedContainer(
|
||||
duration: AppTheme.durationMd,
|
||||
curve: AppTheme.curveDefault,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.isActive
|
||||
? AppColors.primary.withOpacity(0.15)
|
||||
: AppColors.surface,
|
||||
border: Border.all(
|
||||
color: widget.isActive
|
||||
? AppColors.primary
|
||||
: (_isHovered
|
||||
? AppColors.border
|
||||
: AppColors.border.withOpacity(0.5)),
|
||||
width: widget.isActive ? 2.5 : 1.5,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
boxShadow: [
|
||||
if (_isHovered || widget.isActive)
|
||||
BoxShadow(
|
||||
color: widget.isActive
|
||||
? AppColors.primary.withOpacity(0.25)
|
||||
: AppColors.primary.withOpacity(0.1),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
spreadRadius: 1,
|
||||
),
|
||||
// Deep shadow on focus
|
||||
boxShadow: _isHovered
|
||||
? [
|
||||
BoxShadow(
|
||||
color: AppColors.background.withOpacity(0.5),
|
||||
blurRadius: 30,
|
||||
offset: const Offset(0, 15),
|
||||
spreadRadius: 2,
|
||||
),
|
||||
]
|
||||
: [
|
||||
BoxShadow(
|
||||
color: AppColors.background.withOpacity(0.2),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd - (_isHovered ? 2 : 0)), // Adjust inner radius
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(AppTheme.spacingMd),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 1. Background Image / Logo - EDGE TO EDGE
|
||||
_buildChannelImage(),
|
||||
|
||||
// 2. Gradient Overlay (Subtle)
|
||||
if (_isHovered)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.transparent, AppColors.background.withOpacity(0.4)],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.channelNumber,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
SizedBox(height: AppTheme.spacingXs),
|
||||
Text(
|
||||
widget.channelName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: widget.onFavoriteTap,
|
||||
child: AnimatedScale(
|
||||
scale: widget.isFavorite ? 1.1 : 1.0,
|
||||
duration: AppTheme.durationXs,
|
||||
child: Icon(
|
||||
widget.isFavorite
|
||||
? Icons.favorite
|
||||
: Icons.favorite_border,
|
||||
color: widget.isFavorite
|
||||
? AppColors.secondary
|
||||
: AppColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 3. Live Badge (Top Right)
|
||||
if (widget.isLive)
|
||||
Positioned(
|
||||
top: 8,
|
||||
right: 8,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.live,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
],
|
||||
),
|
||||
SizedBox(height: AppTheme.spacingSm),
|
||||
if (widget.currentProgram != null)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.currentProgram!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
child: const Text('LIVE', style: TextStyle(color: AppColors.onSurface, fontSize: 9, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
|
||||
// 4. Favorite Icon (Top Left)
|
||||
if (_isHovered || isFavorite)
|
||||
Positioned(
|
||||
top: 5,
|
||||
left: 5,
|
||||
child: GestureDetector(
|
||||
onTap: () => ref.read(favoritesProvider.notifier).toggleFavorite(widget.streamId),
|
||||
child: Icon(
|
||||
isFavorite ? Icons.favorite : Icons.favorite_border,
|
||||
color: isFavorite ? AppColors.live : AppColors.onSurface.withOpacity(0.7),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
if (widget.programTime != null) ...[
|
||||
SizedBox(height: AppTheme.spacingXs),
|
||||
Text(
|
||||
widget.programTime!,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Text separates from card (Classic tvOS look)
|
||||
SizedBox(
|
||||
width: widget.width ?? 180,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
widget.name,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: _isHovered ? AppColors.primaryContainer : AppColors.onSurfaceVariant,
|
||||
fontWeight: _isHovered ? FontWeight.bold : FontWeight.w500,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
if ((widget.currentProgram != null || _epgNow != null)) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_epgNow ?? widget.currentProgram ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textTertiary,
|
||||
fontSize: 11,
|
||||
if (widget.isActive)
|
||||
Positioned(
|
||||
top: AppTheme.spacingSm,
|
||||
right: AppTheme.spacingSm,
|
||||
child: Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.6),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChannelImage() {
|
||||
if (widget.iconUrl != null && widget.iconUrl!.isNotEmpty) {
|
||||
return Container(
|
||||
color: Colors.white, // Logos usually look best on white/light grey
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: widget.iconUrl!,
|
||||
fit: BoxFit.contain,
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
placeholder: (context, url) => _buildPlaceholder(),
|
||||
errorWidget: (context, url, error) => _buildPlaceholder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _buildPlaceholder();
|
||||
}
|
||||
|
||||
Widget _buildPlaceholder() {
|
||||
return Container(
|
||||
color: AppColors.surface,
|
||||
child: const Center(
|
||||
child: Icon(Icons.tv, color: AppColors.textTertiary),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,543 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import '../providers/recommendations_provider.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../models/playlist.dart';
|
||||
|
||||
/// Widget showing "Continue Watching" section
|
||||
class ContinueWatchingWidget extends ConsumerStatefulWidget {
|
||||
final Playlist playlist;
|
||||
final List<Playlist> content;
|
||||
final VoidCallback? onItemTap;
|
||||
|
||||
const ContinueWatchingWidget({
|
||||
super.key,
|
||||
required this.playlist,
|
||||
required this.content,
|
||||
this.onItemTap,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<ContinueWatchingWidget> createState() =>
|
||||
_ContinueWatchingWidgetState();
|
||||
}
|
||||
|
||||
class _ContinueWatchingWidgetState
|
||||
extends ConsumerState<ContinueWatchingWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final watchHistory = ref.watch(watchHistoryProvider);
|
||||
final continueWatching =
|
||||
RecommendationService.getContinueWatching(watchHistory, widget.content);
|
||||
|
||||
if (continueWatching.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Continue Watching',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// Navigate to full continue watching list
|
||||
},
|
||||
child: const Text('View All'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
...continueWatching.take(5).map((rec) {
|
||||
final item = rec.item;
|
||||
final percentage =
|
||||
watchHistory[item.streamId.toString()] is Map
|
||||
? (watchHistory[item.streamId.toString()]
|
||||
as Map)['percentage'] as double? ??
|
||||
0.0
|
||||
: 0.0;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
child: _ContinueWatchingCard(
|
||||
item: item,
|
||||
progress: percentage,
|
||||
onTap: widget.onItemTap,
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ContinueWatchingCard extends StatelessWidget {
|
||||
final Playlist item;
|
||||
final double progress;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _ContinueWatchingCard({
|
||||
required this.item,
|
||||
required this.progress,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Poster with progress bar
|
||||
Container(
|
||||
width: 160,
|
||||
height: 240,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Poster image
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: item.cover ?? '',
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(
|
||||
Icons.image_not_supported,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Dark overlay at bottom
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Progress bar
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
child: LinearProgressIndicator(
|
||||
value: progress / 100.0,
|
||||
minHeight: 3,
|
||||
backgroundColor: Colors.white30,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
_getProgressColor(progress),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${progress.toStringAsFixed(0)}% watched',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Play button overlay on hover
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.withOpacity(0.7),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
margin: const EdgeInsets.all(8),
|
||||
child: const Icon(
|
||||
Icons.play_arrow,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Title
|
||||
SizedBox(
|
||||
width: 160,
|
||||
child: Text(
|
||||
item.name ?? 'Unknown',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getProgressColor(double progress) {
|
||||
if (progress < 30) return Colors.red;
|
||||
if (progress < 70) return Colors.orange;
|
||||
return Colors.green;
|
||||
}
|
||||
}
|
||||
|
||||
/// Widget showing trending/popular content
|
||||
class TrendingWidget extends ConsumerWidget {
|
||||
final Playlist playlist;
|
||||
final List<Playlist> content;
|
||||
final VoidCallback? onItemTap;
|
||||
|
||||
const TrendingWidget({
|
||||
super.key,
|
||||
required this.playlist,
|
||||
required this.content,
|
||||
this.onItemTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final trending = ref.watch(trendingProvider);
|
||||
final trendingContent =
|
||||
RecommendationService.getTrending(trending, content);
|
||||
|
||||
if (trendingContent.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.local_fire_department,
|
||||
color: Colors.red,
|
||||
size: 24,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Trending Now',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text('View All'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
...trendingContent.take(5).map((rec) {
|
||||
final item = rec.item;
|
||||
final rank = trendingContent.indexOf(rec) + 1;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
child: _TrendingCard(
|
||||
item: item,
|
||||
rank: rank,
|
||||
onTap: onItemTap,
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TrendingCard extends StatelessWidget {
|
||||
final Playlist item;
|
||||
final int rank;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _TrendingCard({
|
||||
required this.item,
|
||||
required this.rank,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Stack(
|
||||
children: [
|
||||
// Card
|
||||
Container(
|
||||
width: 180,
|
||||
height: 260,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Image
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: item.cover ?? '',
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(
|
||||
Icons.image_not_supported,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Info
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.name ?? 'Unknown',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
if (item.rating != null)
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.star,
|
||||
color: Colors.amber,
|
||||
size: 12,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
item.rating ?? '0',
|
||||
style: const TextStyle(fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Rank badge
|
||||
Positioned(
|
||||
top: 8,
|
||||
left: 8,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _getRankColor(rank),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'#$rank',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getRankColor(int rank) {
|
||||
switch (rank) {
|
||||
case 1:
|
||||
return Colors.amber.shade700;
|
||||
case 2:
|
||||
return Colors.grey.shade600;
|
||||
case 3:
|
||||
return Colors.orange.shade700;
|
||||
default:
|
||||
return Colors.blue.shade700;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Widget showing recently added content
|
||||
class RecentlyAddedWidget extends ConsumerWidget {
|
||||
final Playlist playlist;
|
||||
final List<Playlist> content;
|
||||
final VoidCallback? onItemTap;
|
||||
|
||||
const RecentlyAddedWidget({
|
||||
super.key,
|
||||
required this.playlist,
|
||||
required this.content,
|
||||
this.onItemTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final recent = RecommendationService.getRecentlyAdded(content);
|
||||
|
||||
if (recent.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
'Recently Added',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
...recent.take(5).map((rec) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
child: _RecentCard(
|
||||
item: rec.item,
|
||||
onTap: onItemTap,
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RecentCard extends StatelessWidget {
|
||||
final Playlist item;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _RecentCard({
|
||||
required this.item,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 140,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: item.cover ?? '',
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
errorWidget: (context, url, error) =>
|
||||
Icon(Icons.image_not_supported, color: Colors.grey[600]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,10 +64,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
body: channelsAsync.when(
|
||||
loading: () => const ThemedLoading(),
|
||||
error: (e, s) => Center(
|
||||
child: Text(
|
||||
'Error: $e',
|
||||
style: GoogleFonts.inter(color: AppColors.onSurface),
|
||||
),
|
||||
child: Text('Error: $e', style: const TextStyle(color: Colors.white)),
|
||||
),
|
||||
data: (groupedChannels) {
|
||||
var categories = groupedChannels.keys.toList();
|
||||
@@ -76,6 +73,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
.where((cat) => settings.matchesLiveTvFilter(cat))
|
||||
.toList();
|
||||
}
|
||||
// REMOVED: categories.sort(); - Respect API/Settings order
|
||||
|
||||
List<Channel> displayedChannels = [];
|
||||
bool showingCategoryGrid = false;
|
||||
@@ -98,11 +96,12 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// HEADER (Glass Level 1)
|
||||
// HEADER (Glass)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 16, 24, 16),
|
||||
child: GlassContainer.glass(
|
||||
child: GlassContainer(
|
||||
borderRadius: 16,
|
||||
opacity: 0.6,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
child: Row(
|
||||
@@ -121,13 +120,12 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceContainerHigh
|
||||
.withOpacity(0.5),
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
child: const Icon(
|
||||
Icons.arrow_back,
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -141,10 +139,10 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
: _showFavoritesOnly
|
||||
? 'Favorites'
|
||||
: _selectedCategory ?? 'Live TV',
|
||||
style: GoogleFonts.spaceGrotesk(
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -156,22 +154,17 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
width: 250,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceContainerLow,
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.outlineVariant,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
style: GoogleFonts.inter(color: AppColors.onSurface),
|
||||
style: GoogleFonts.inter(color: Colors.white),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search channels...',
|
||||
hintStyle:
|
||||
GoogleFonts.inter(color: AppColors.outline),
|
||||
hintStyle: GoogleFonts.inter(color: Colors.white54),
|
||||
prefixIcon:
|
||||
Icon(Icons.search, color: AppColors.outline),
|
||||
const Icon(Icons.search, color: Colors.white54),
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
@@ -179,9 +172,9 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
),
|
||||
suffixIcon: _searchQuery.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(
|
||||
icon: const Icon(
|
||||
Icons.clear,
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: _searchController.clear,
|
||||
)
|
||||
@@ -206,8 +199,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
decoration: BoxDecoration(
|
||||
color: _showFavoritesOnly
|
||||
? AppColors.live.withOpacity(0.2)
|
||||
: AppColors.surfaceContainerHigh
|
||||
.withOpacity(0.5),
|
||||
: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: _showFavoritesOnly
|
||||
? Border.all(color: AppColors.live)
|
||||
@@ -219,7 +211,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
: Icons.favorite_border,
|
||||
color: _showFavoritesOnly
|
||||
? AppColors.live
|
||||
: AppColors.onSurfaceVariant,
|
||||
: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -240,19 +232,20 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
Icon(
|
||||
Icons.tv_off,
|
||||
size: 64,
|
||||
color: AppColors.outline,
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No channels found',
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: Colors.white54,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
// Use raw grid for now, but wrapped in focusable cards
|
||||
: _buildChannelGrid(displayedChannels),
|
||||
),
|
||||
],
|
||||
@@ -295,20 +288,21 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
});
|
||||
},
|
||||
borderRadius: 16,
|
||||
child: GlassContainer.glass(
|
||||
child: GlassContainer(
|
||||
borderRadius: 16,
|
||||
padding: EdgeInsets.zero,
|
||||
opacity: 0.2, // Darker glass
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Stack(
|
||||
children: [
|
||||
// Background Gradient
|
||||
// Background Gradient - Apple TV Style
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.surfaceContainerLow.withOpacity(0.5),
|
||||
AppColors.primary.withOpacity(0.03),
|
||||
AppColors.primary.withOpacity(0.15),
|
||||
AppColors.primary.withOpacity(0.05),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -319,7 +313,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
children: [
|
||||
Icon(
|
||||
Icons.folder_copy_outlined,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
size: 32,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -331,7 +325,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -342,7 +336,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
'$count Channels',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 13,
|
||||
color: AppColors.outline,
|
||||
color: Colors.white54,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -371,7 +365,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
crossAxisCount: columns,
|
||||
mainAxisSpacing: 16,
|
||||
crossAxisSpacing: 16,
|
||||
childAspectRatio: 1.0,
|
||||
childAspectRatio: 1.0, // Square-ish cards
|
||||
),
|
||||
itemCount: channels.length,
|
||||
itemBuilder: (context, index) {
|
||||
@@ -381,7 +375,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
borderRadius: 12,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceContainerLow,
|
||||
color: AppColors.surfaceVariant,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Stack(
|
||||
@@ -394,10 +388,12 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceContainer
|
||||
.withOpacity(0.5),
|
||||
color: Colors.white.withOpacity(
|
||||
0.05,
|
||||
), // Subtle transparent background
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12)),
|
||||
top: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
@@ -406,16 +402,16 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
_getProxiedIconUrl(channel.streamIcon)!,
|
||||
errorBuilder: (_, __, ___) => Icon(
|
||||
Icons.tv,
|
||||
color: AppColors.outline,
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
size: 40,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
channel.name.characters.first.toUpperCase(),
|
||||
style: GoogleFonts.spaceGrotesk(
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 40,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.outlineVariant,
|
||||
color: Colors.white24,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -424,19 +420,17 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
// Footer
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceContainerHigh.withOpacity(0.9),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
bottom: Radius.circular(12)),
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
color: Colors.black54,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
channel.name,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.onSurface,
|
||||
color: Colors.white,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
@@ -461,7 +455,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
return Text(
|
||||
'No Info',
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.outline,
|
||||
color: Colors.white54,
|
||||
fontSize: 10,
|
||||
),
|
||||
);
|
||||
@@ -474,8 +468,9 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
EpgEntry.parseDateTime(entry.start);
|
||||
final end =
|
||||
EpgEntry.parseDateTime(entry.end);
|
||||
if (start == null || end == null)
|
||||
if (start == null || end == null) {
|
||||
return false;
|
||||
}
|
||||
return now.isAfter(start) &&
|
||||
now.isBefore(end);
|
||||
} catch (e) {
|
||||
@@ -488,7 +483,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
return Text(
|
||||
currentProgram.title,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.ratingGold,
|
||||
color: const Color(0xFFFFD700),
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -499,14 +494,14 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
loading: () => Text(
|
||||
'...',
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.outlineVariant,
|
||||
color: Colors.white24,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
error: (_, __) => Text(
|
||||
'Err',
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.error,
|
||||
color: Colors.red,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
@@ -518,7 +513,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
),
|
||||
],
|
||||
),
|
||||
// Record Button Icon Overlay
|
||||
// Record Button Icon Overlay (Positioned top right)
|
||||
Positioned(
|
||||
top: 8,
|
||||
right: 8,
|
||||
@@ -531,12 +526,12 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.background.withOpacity(0.5),
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.fiber_manual_record,
|
||||
color: AppColors.error,
|
||||
color: Colors.redAccent,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/services/adaptive_bitrate_service.dart';
|
||||
|
||||
/// Widget for displaying and selecting video quality during playback
|
||||
class QualitySelectorWidget extends ConsumerStatefulWidget {
|
||||
final QualitySelector qualitySelector;
|
||||
final VoidCallback onClose;
|
||||
|
||||
const QualitySelectorWidget({
|
||||
super.key,
|
||||
required this.qualitySelector,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<QualitySelectorWidget> createState() =>
|
||||
_QualitySelectorWidgetState();
|
||||
}
|
||||
|
||||
class _QualitySelectorWidgetState extends ConsumerState<QualitySelectorWidget> {
|
||||
late List<QualityLevel> _availableQualities;
|
||||
late QualityLevel _selectedQuality;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_availableQualities = QualityProfiles.getBalancedProfiles();
|
||||
_selectedQuality = widget.qualitySelector.currentQuality;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final currentQuality = widget.qualitySelector.currentQuality;
|
||||
final bandwidthMbps = widget.qualitySelector.getEstimatedBandwidthMbps();
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: Colors.black87,
|
||||
insetPadding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Colors.white24),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Video Quality',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: widget.onClose,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Network Info
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white10,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Current Bandwidth:',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
Text(
|
||||
'${bandwidthMbps.toStringAsFixed(1)} Mbps',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Quality Options
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: _availableQualities.length,
|
||||
itemBuilder: (context, index) {
|
||||
final quality = _availableQualities[index];
|
||||
final isSelected = quality == currentQuality;
|
||||
|
||||
return ListTile(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
leading: isSelected
|
||||
? const Icon(Icons.check_circle, color: Colors.blue)
|
||||
: const Icon(
|
||||
Icons.radio_button_unchecked,
|
||||
color: Colors.white30,
|
||||
),
|
||||
title: Text(
|
||||
quality.label,
|
||||
style: TextStyle(
|
||||
color: isSelected ? Colors.blue : Colors.white,
|
||||
fontWeight:
|
||||
isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
'${quality.bitrateBps ~/ 1000000} Mbps',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
onTap: () {
|
||||
widget.qualitySelector.setQuality(quality);
|
||||
setState(() {
|
||||
_selectedQuality = quality;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
// Auto Quality Option
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(color: Colors.white24),
|
||||
),
|
||||
),
|
||||
child: ListTile(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
leading: const Icon(Icons.auto_awesome, color: Colors.amber),
|
||||
title: const Text(
|
||||
'Auto Quality',
|
||||
style: TextStyle(
|
||||
color: Colors.amber,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
subtitle: const Text(
|
||||
'Adjusts based on network speed',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
onTap: () {
|
||||
// Auto mode would be handled by the player
|
||||
widget.onClose();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Floating quality indicator (minimal UI during playback)
|
||||
class QualityIndicator extends ConsumerWidget {
|
||||
final QualitySelector qualitySelector;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const QualityIndicator({
|
||||
super.key,
|
||||
required this.qualitySelector,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final quality = qualitySelector.currentQuality;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.high_quality, color: Colors.white, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
quality.resolution.split('x')[1], // Show just the height
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Bandwidth monitor widget (for debugging/info)
|
||||
class BandwidthMonitor extends ConsumerWidget {
|
||||
final QualitySelector qualitySelector;
|
||||
|
||||
const BandwidthMonitor({
|
||||
super.key,
|
||||
required this.qualitySelector,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.speed, color: Colors.green, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${qualitySelector.getEstimatedBandwidthMbps().toStringAsFixed(1)} Mbps',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,329 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../../core/models/iptv_models.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/widgets/glass_container.dart';
|
||||
|
||||
class SimpleRecordingWidget extends StatefulWidget {
|
||||
final Channel channel;
|
||||
final String streamUrl;
|
||||
|
||||
const SimpleRecordingWidget({
|
||||
super.key,
|
||||
required this.channel,
|
||||
required this.streamUrl,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SimpleRecordingWidget> createState() => _SimpleRecordingWidgetState();
|
||||
}
|
||||
|
||||
class _SimpleRecordingWidgetState extends State<SimpleRecordingWidget> {
|
||||
bool _isRecording = false;
|
||||
String _status = '';
|
||||
int _durationMinutes = 60;
|
||||
DateTime _startTime = DateTime.now();
|
||||
|
||||
/// 🟢 Record NOW for X minutes
|
||||
Future<void> _recordNow(int minutes) async {
|
||||
setState(() => _status = 'Starting...');
|
||||
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('/api/record/now'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({
|
||||
'channel_id': widget.channel.streamId,
|
||||
'stream_url': widget.streamUrl,
|
||||
'title': widget.channel.name,
|
||||
'duration_minutes': minutes,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
setState(() {
|
||||
_isRecording = true;
|
||||
_status = '🔴 Recording for $minutes min';
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('✅ Recording started!')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw Exception('API error');
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() => _status = '❌ Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔵 Schedule for later
|
||||
Future<void> _scheduleRecording() async {
|
||||
final endTime = _startTime.add(Duration(minutes: _durationMinutes));
|
||||
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('/api/record/schedule'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({
|
||||
'channel_id': widget.channel.streamId,
|
||||
'stream_url': widget.streamUrl,
|
||||
'title': widget.channel.name,
|
||||
'start_time': _startTime.toIso8601String(),
|
||||
'end_time': endTime.toIso8601String(),
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
setState(() => _status = '⏰ Scheduled for ${_startTime.toLocal()}');
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('✅ Recording scheduled!')),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() => _status = '❌ Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔴 Stop recording
|
||||
Future<void> _stopRecording() async {
|
||||
try {
|
||||
await http.post(
|
||||
Uri.parse('/api/record/stop/${widget.channel.streamId}'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_isRecording = false;
|
||||
_status = 'Stopped';
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('✅ Recording stopped!')),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() => _status = '❌ Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
insetPadding: const EdgeInsets.all(20),
|
||||
child: GlassContainer(
|
||||
child: Container(
|
||||
width: 500,
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Title
|
||||
Text(
|
||||
'🎬 Record "${widget.channel.name}"',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Status
|
||||
if (_status.isNotEmpty)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
_status,
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
color: Colors.white70,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// 🟢 Quick record buttons
|
||||
if (!_isRecording) ...[
|
||||
Text(
|
||||
'⚡ Quick Record',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_QuickButton(
|
||||
label: '30 min',
|
||||
onTap: () => _recordNow(30),
|
||||
),
|
||||
_QuickButton(
|
||||
label: '1 hour',
|
||||
onTap: () => _recordNow(60),
|
||||
),
|
||||
_QuickButton(
|
||||
label: '2 hours',
|
||||
onTap: () => _recordNow(120),
|
||||
),
|
||||
_QuickButton(
|
||||
label: '4 hours',
|
||||
onTap: () => _recordNow(240),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
],
|
||||
|
||||
// 🔴 Stop if recording
|
||||
if (_isRecording)
|
||||
ElevatedButton.icon(
|
||||
onPressed: _stopRecording,
|
||||
icon: const Icon(Icons.stop),
|
||||
label: const Text('STOP RECORDING'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
|
||||
if (!_isRecording) ...[
|
||||
// 🔵 Schedule section
|
||||
ExpansionTile(
|
||||
title: Text(
|
||||
'🔵 Schedule for Later',
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
// Start time picker
|
||||
ListTile(
|
||||
title: const Text('Start'),
|
||||
trailing: Text(
|
||||
'${_startTime.toLocal().hour}:${_startTime.toLocal().minute.toString().padLeft(2, '0')}',
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
onTap: () async {
|
||||
final time = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.fromDateTime(_startTime),
|
||||
);
|
||||
if (time != null) {
|
||||
setState(() {
|
||||
_startTime = _startTime.copyWith(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
// Duration selector
|
||||
ListTile(
|
||||
title: const Text('Duration'),
|
||||
trailing: DropdownButton<int>(
|
||||
value: _durationMinutes,
|
||||
dropdownColor: Colors.grey[800],
|
||||
items: [30, 60, 120, 240, 480]
|
||||
.map(
|
||||
(m) => DropdownMenuItem(
|
||||
value: m,
|
||||
child: Text('$m min'),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _durationMinutes = v);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Schedule button
|
||||
ElevatedButton.icon(
|
||||
onPressed: _scheduleRecording,
|
||||
icon: const Icon(Icons.schedule),
|
||||
label: const Text('SCHEDULE'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Close button
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Quick button component
|
||||
class _QuickButton extends StatelessWidget {
|
||||
final String label;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _QuickButton({
|
||||
required this.label,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
onPressed: onTap,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary.withOpacity(0.7),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Text(label),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user