## Screens ### home_screen.dart - Removed unused imports (flutter/services) - Removed unused _focusedIndex state variable - Simplified responsive layout logic: - Removed _isMediumScreen, _gridCrossAxisCount getters - Removed _titleFontSize, _iconSize getters - Kept only _headerPadding for responsive padding - Improved navigation with mounted checks - Better MaterialPageRoute formatting - Enhanced _downloadPlaylistAsJson method ## Services ### xtream_api.dart - Added http.Client dependency injection for testability - Implemented _countryExtractionCache for performance - Added regex patterns for country code extraction: - _leadingCodeRegex for "AR - Channel" format - _bracketCodeRegex for "[AR] Channel" format - Enhanced football channel detection patterns - Improved error handling and messages - Better formatted country mapping with regions ### iptv_provider.dart - Better state management separation - Optimized stream filtering for large lists - Refactored country filtering methods - Enhanced playlist download and caching logic - Improved memory management ## Widgets ### countries_sidebar.dart - Better responsive design for TV screens - Enhanced FocusableActionDetector implementation - Improved focus indicators for Android TV - Smoother transitions between selections ### simple_countries_sidebar.dart - Cleaner, more maintainable code structure - Better keyboard/remote navigation support - Improved visual feedback and styling ## Player ### player_screen.dart - Better error handling for playback failures - Enhanced responsive layout - Improved Android TV control visibility - Better buffer management and loading indicators ## Tests ### widget_test.dart - Updated to match new widget signatures - Improved test coverage for refactored components ## Technical Improvements - Better separation of concerns across all layers - Dependency injection patterns for testability - Performance optimizations with caching - Consistent code formatting and documentation - Removed unused code and imports - Enhanced Android TV support with FocusableActionDetector ## Statistics - 8 files changed - +1300 insertions - -1139 deletions - Net: +161 lines of cleaner code ## Breaking Changes None - all internal refactorings with no API changes
269 lines
8.0 KiB
Dart
269 lines
8.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class SimpleCountriesSidebar extends StatelessWidget {
|
|
final List<String> countries;
|
|
final String selectedCountry;
|
|
final ValueChanged<String> onCountrySelected;
|
|
final bool isLoading;
|
|
final bool isOrganizing;
|
|
final bool showFootballCategory;
|
|
final VoidCallback? onFootballSelected;
|
|
|
|
const SimpleCountriesSidebar({
|
|
super.key,
|
|
required this.countries,
|
|
required this.selectedCountry,
|
|
required this.onCountrySelected,
|
|
this.isLoading = false,
|
|
this.isOrganizing = false,
|
|
this.showFootballCategory = false,
|
|
this.onFootballSelected,
|
|
});
|
|
|
|
static const String _footballCategoryName = 'Fútbol Argentino';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (countries.isNotEmpty) {
|
|
for (int i = 0; i < countries.length && i < 10; i++) {}
|
|
}
|
|
|
|
return Container(
|
|
width: 250,
|
|
color: Colors.grey[900],
|
|
child: Column(
|
|
children: [
|
|
// Header
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
color: Colors.red,
|
|
child: const Row(
|
|
children: [
|
|
Icon(Icons.public, color: Colors.white),
|
|
SizedBox(width: 8),
|
|
Text(
|
|
'PAÍSES',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// List
|
|
Expanded(
|
|
child: isOrganizing || (isLoading && countries.isEmpty)
|
|
? const Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(color: Colors.red),
|
|
SizedBox(height: 16),
|
|
Text(
|
|
'Organizando países...',
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: countries.isEmpty
|
|
? const Center(
|
|
child: Text(
|
|
'No hay países',
|
|
style: TextStyle(color: Colors.white54),
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
itemCount: _getItemCount(),
|
|
itemBuilder: (context, index) {
|
|
return _buildItemAtIndex(context, index);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCountryItem(String name, bool isSelected, VoidCallback onTap) {
|
|
return FocusableActionDetector(
|
|
actions: <Type, Action<Intent>>{
|
|
ActivateIntent: CallbackAction<ActivateIntent>(
|
|
onInvoke: (intent) {
|
|
onTap();
|
|
return null;
|
|
},
|
|
),
|
|
ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(
|
|
onInvoke: (intent) {
|
|
onTap();
|
|
return null;
|
|
},
|
|
),
|
|
},
|
|
child: Builder(
|
|
builder: (context) {
|
|
final hasFocus = Focus.of(context).hasFocus;
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
decoration: BoxDecoration(
|
|
color: isSelected
|
|
? Colors.red
|
|
: (hasFocus
|
|
? Colors.red.withValues(alpha: 0.5)
|
|
: Colors.transparent),
|
|
border: Border(
|
|
left: BorderSide(
|
|
color: isSelected
|
|
? Colors.white
|
|
: (hasFocus ? Colors.white : Colors.transparent),
|
|
width: 4,
|
|
),
|
|
),
|
|
),
|
|
child: Text(
|
|
name,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14,
|
|
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
int _getItemCount() {
|
|
int count = countries.length + 1; // +1 for "Todos"
|
|
if (showFootballCategory) {
|
|
count += 1; // +1 for "Fútbol Argentino"
|
|
}
|
|
return count;
|
|
}
|
|
|
|
Widget _buildItemAtIndex(BuildContext context, int index) {
|
|
if (index == 0) {
|
|
return _buildCountryItem(
|
|
'Todos',
|
|
selectedCountry.isEmpty,
|
|
() => onCountrySelected(''),
|
|
);
|
|
}
|
|
|
|
// Find insertion point for "Fútbol Argentino" (after Perú)
|
|
final peruIndex = countries.indexOf('Perú');
|
|
final footballInsertIndex = peruIndex >= 0
|
|
? peruIndex + 1
|
|
: countries.length;
|
|
|
|
if (showFootballCategory) {
|
|
// Adjust for "Todos" at index 0 and "Fútbol Argentino" after Perú
|
|
if (index == footballInsertIndex + 1) {
|
|
return _buildFootballItem();
|
|
}
|
|
|
|
// Map the adjusted index to the actual country list
|
|
int countryIndex;
|
|
if (index <= footballInsertIndex) {
|
|
// Before football item
|
|
countryIndex = index - 1;
|
|
} else {
|
|
// After football item
|
|
countryIndex = index - 2;
|
|
}
|
|
|
|
if (countryIndex >= 0 && countryIndex < countries.length) {
|
|
final country = countries[countryIndex];
|
|
return _buildCountryItem(
|
|
country,
|
|
selectedCountry == country,
|
|
() => onCountrySelected(country),
|
|
);
|
|
}
|
|
} else {
|
|
// Normal behavior without football category
|
|
final country = countries[index - 1];
|
|
return _buildCountryItem(
|
|
country,
|
|
selectedCountry == country,
|
|
() => onCountrySelected(country),
|
|
);
|
|
}
|
|
|
|
return const SizedBox.shrink();
|
|
}
|
|
|
|
Widget _buildFootballItem() {
|
|
final isSelected = selectedCountry == _footballCategoryName;
|
|
return FocusableActionDetector(
|
|
actions: <Type, Action<Intent>>{
|
|
ActivateIntent: CallbackAction<ActivateIntent>(
|
|
onInvoke: (intent) {
|
|
onFootballSelected?.call();
|
|
return null;
|
|
},
|
|
),
|
|
ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(
|
|
onInvoke: (intent) {
|
|
onFootballSelected?.call();
|
|
return null;
|
|
},
|
|
),
|
|
},
|
|
child: Builder(
|
|
builder: (context) {
|
|
final hasFocus = Focus.of(context).hasFocus;
|
|
return GestureDetector(
|
|
onTap: onFootballSelected,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
decoration: BoxDecoration(
|
|
color: isSelected
|
|
? Colors.green[700]
|
|
: (hasFocus
|
|
? Colors.green[700]?.withValues(alpha: 0.8)
|
|
: Colors.green[900]?.withValues(alpha: 0.3)),
|
|
border: Border(
|
|
left: BorderSide(
|
|
color: isSelected
|
|
? Colors.white
|
|
: (hasFocus ? Colors.white : Colors.green[400]!),
|
|
width: 4,
|
|
),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.sports_soccer, color: Colors.white, size: 20),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
_footballCategoryName,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14,
|
|
fontWeight: isSelected
|
|
? FontWeight.bold
|
|
: FontWeight.normal,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|