Files
iptv-ren/lib/utils/channel_name_formatter.dart
renato97 5351513619 v1.1.2: Channel name formatting and Live TV search optimization
## New Features

### lib/utils/channel_name_formatter.dart (NEW)
- Created new utility class for formatting channel names
- Removes quality tokens (SD, HD, FHD, UHD, 4K, 8K, HDR, HEVC, H264, H265, FULLHD)
- Strips prefixes before pipe character (e.g., "AR | Channel" → "Channel")
- Removes leading dashes, colons, and other separators
- Implements caching mechanism (max 50,000 entries) for performance
- Normalizes tokens by removing non-alphanumeric characters

## UI/UX Improvements

### lib/screens/home_screen.dart
- **Live TV Memory Optimization**: Live streams list now persists in memory while app is running
  - Prevents unnecessary reloads when navigating back to Live TV
  - Improves performance and reduces API calls
- **Search Bar Visibility**: Hidden search bar for Live TV content type
  - Search only shown for Movies and Series
  - Cleaner UI for Live TV browsing
- **Channel Name Display**: Applied ChannelNameFormatter to channel cards
  - Removes quality indicators from displayed names
  - Better text styling with centered alignment
  - Increased font weight (w500 → w600)
  - Improved line height (1.15) for better readability
  - Text alignment changed to center
  - Better overflow handling with ellipsis

### lib/screens/player_screen.dart
- Code cleanup and optimization
- Removed unused imports/statements (9 lines removed)

## Technical Details

### Performance
- Channel name caching reduces string processing overhead
- Live TV list persistence reduces API calls
- Memory-efficient cache with automatic cleanup

### Code Quality
- Separation of concerns with new utility class
- Consistent formatting across channel names
- Better memory management for large channel lists

## Statistics
- 3 files changed
- +141 insertions, -68 deletions
- Net: +73 lines
- New file: lib/utils/channel_name_formatter.dart

## Breaking Changes
None - all changes are additive or UI improvements
2026-02-26 00:28:03 -03:00

56 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
class ChannelNameFormatter {
static final Map<String, String> _cache = <String, String>{};
static const Set<String> _qualityTokens = <String>{
'SD',
'HD',
'FHD',
'UHD',
'4K',
'8K',
'HDR',
'HEVC',
'H264',
'H265',
'FULLHD',
};
static String forDisplay(String rawName) {
if (rawName.isEmpty) return rawName;
final cached = _cache[rawName];
if (cached != null) return cached;
var display = rawName.trim();
final pipeIndex = display.indexOf('|');
if (pipeIndex >= 0 && pipeIndex < display.length - 1) {
display = display.substring(pipeIndex + 1).trim();
}
display = display.replaceFirst(RegExp(r'^[\-\\—:]+'), '').trim();
if (display.isNotEmpty) {
final parts = display.split(RegExp(r'\s+')).toList(growable: true);
while (parts.isNotEmpty && _isQualityToken(parts.last)) {
parts.removeLast();
}
display = parts.join(' ').trim();
}
if (display.isEmpty) {
display = rawName.trim();
}
if (_cache.length > 50000) {
_cache.clear();
}
_cache[rawName] = display;
return display;
}
static bool _isQualityToken(String token) {
final normalized = token.toUpperCase().replaceAll(RegExp(r'[^A-Z0-9]'), '');
return _qualityTokens.contains(normalized);
}
}