mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-26 12:52:40 +02:00
fix(library): show complete quality labels
This commit is contained in:
@@ -146,8 +146,12 @@ extension _QueueTabCollectionItemWidgets on _QueueTabState {
|
||||
if (quality != null && quality.isNotEmpty)
|
||||
Positioned(
|
||||
left: 4,
|
||||
right: 4,
|
||||
top: 4,
|
||||
child: _buildLibraryQualityBadge(context, colorScheme, quality),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: _buildLibraryQualityBadge(context, colorScheme, quality),
|
||||
),
|
||||
),
|
||||
],
|
||||
title: trackName,
|
||||
@@ -242,6 +246,24 @@ extension _QueueTabCollectionItemWidgets on _QueueTabState {
|
||||
}) {
|
||||
final tokens = context.tokens;
|
||||
final isHighlightedQuality = shouldHighlightAudioQualityBadge(quality);
|
||||
final displayQuality = listStyle
|
||||
? quality
|
||||
: formatLibraryGridAudioQualityLabel(quality);
|
||||
final isDetailed = isDetailedLibraryAudioQualityLabel(displayQuality);
|
||||
final label = Text(
|
||||
displayQuality,
|
||||
maxLines: 1,
|
||||
softWrap: false,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: isHighlightedQuality
|
||||
? listStyle
|
||||
? colorScheme.onPrimaryContainer
|
||||
: colorScheme.onPrimary
|
||||
: colorScheme.onSurfaceVariant,
|
||||
fontSize: isDetailed ? tokens.badgeFontSize - 1 : tokens.badgeFontSize,
|
||||
fontWeight: listStyle ? FontWeight.w500 : FontWeight.w600,
|
||||
),
|
||||
);
|
||||
return Container(
|
||||
padding: tokens.badgePadding,
|
||||
decoration: BoxDecoration(
|
||||
@@ -252,18 +274,13 @@ extension _QueueTabCollectionItemWidgets on _QueueTabState {
|
||||
: colorScheme.surfaceContainerHighest,
|
||||
borderRadius: tokens.borderRadiusBadge,
|
||||
),
|
||||
child: Text(
|
||||
listStyle ? quality : _getQualityBadgeText(quality),
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: isHighlightedQuality
|
||||
? listStyle
|
||||
? colorScheme.onPrimaryContainer
|
||||
: colorScheme.onPrimary
|
||||
: colorScheme.onSurfaceVariant,
|
||||
fontSize: tokens.badgeFontSize,
|
||||
fontWeight: listStyle ? FontWeight.w500 : FontWeight.w600,
|
||||
),
|
||||
),
|
||||
child: !listStyle && isDetailed
|
||||
? FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: Alignment.centerLeft,
|
||||
child: label,
|
||||
)
|
||||
: label,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1052,8 +1052,12 @@ extension _QueueTabItemWidgets on _QueueTabState {
|
||||
if (quality != null && quality.isNotEmpty)
|
||||
Positioned(
|
||||
left: 4,
|
||||
right: _isSelectionMode ? 4 : 28,
|
||||
top: 4,
|
||||
child: _buildLibraryQualityBadge(context, colorScheme, quality),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: _buildLibraryQualityBadge(context, colorScheme, quality),
|
||||
),
|
||||
),
|
||||
if (!_isSelectionMode)
|
||||
Positioned(
|
||||
|
||||
@@ -380,28 +380,6 @@ extension _QueueTabSelectionActions on _QueueTabState {
|
||||
);
|
||||
}
|
||||
|
||||
String _getQualityBadgeText(String quality) {
|
||||
final q = quality.trim().toLowerCase();
|
||||
if (q.contains('bit')) {
|
||||
return quality.split('/').first;
|
||||
}
|
||||
|
||||
final bitrateTextMatch = RegExp(
|
||||
r'(\d+)\s*k(?:bps)?',
|
||||
caseSensitive: false,
|
||||
).firstMatch(quality);
|
||||
if (bitrateTextMatch != null) {
|
||||
return '${bitrateTextMatch.group(1)}k';
|
||||
}
|
||||
|
||||
final bitrateIdMatch = RegExp(r'_(\d+)$').firstMatch(q);
|
||||
if (bitrateIdMatch != null) {
|
||||
return '${bitrateIdMatch.group(1)}k';
|
||||
}
|
||||
|
||||
return quality.split(' ').first;
|
||||
}
|
||||
|
||||
Future<void> _deleteSelected(List<UnifiedLibraryItem> allItems) async {
|
||||
final count = _selectedIds.length;
|
||||
final confirmed = await showDialog<bool>(
|
||||
|
||||
@@ -4,6 +4,11 @@ import 'package:spotiflac_android/utils/string_utils.dart';
|
||||
|
||||
const highQualityBadgeBitrateThresholdKbps = 900;
|
||||
|
||||
final RegExp _bitDepthQualityPattern = RegExp(
|
||||
r'\b\d+\s*(?:-\s*)?bit\b',
|
||||
caseSensitive: false,
|
||||
);
|
||||
|
||||
String normalizeLibraryQualityLabelMode(String? mode) {
|
||||
return switch (mode) {
|
||||
AppSettings.libraryQualityLabelBitDepth =>
|
||||
@@ -82,6 +87,34 @@ String? _buildBitDepthBitrateLabel({int? bitDepth, int? bitrateKbps}) {
|
||||
return '$bitDepth-bit/${bitrateKbps}kbps';
|
||||
}
|
||||
|
||||
/// Keeps detailed bit-depth labels intact in Library grid badges while
|
||||
/// shortening bitrate-only labels that already include a codec name.
|
||||
String formatLibraryGridAudioQualityLabel(String quality) {
|
||||
final normalized = quality.trim().toLowerCase();
|
||||
if (_bitDepthQualityPattern.hasMatch(normalized)) return quality;
|
||||
|
||||
final bitrateTextMatch = RegExp(
|
||||
r'(\d+)\s*k(?:bps)?',
|
||||
caseSensitive: false,
|
||||
).firstMatch(quality);
|
||||
if (bitrateTextMatch != null) {
|
||||
return '${bitrateTextMatch.group(1)}k';
|
||||
}
|
||||
|
||||
final bitrateIdMatch = RegExp(r'_(\d+)$').firstMatch(normalized);
|
||||
if (bitrateIdMatch != null) {
|
||||
return '${bitrateIdMatch.group(1)}k';
|
||||
}
|
||||
|
||||
return quality.split(' ').first;
|
||||
}
|
||||
|
||||
bool isDetailedLibraryAudioQualityLabel(String quality) {
|
||||
final normalized = quality.trim().toLowerCase();
|
||||
return _bitDepthQualityPattern.hasMatch(normalized) &&
|
||||
normalized.contains('/');
|
||||
}
|
||||
|
||||
/// Preserves the highlighted color used by legacy 24-bit Library badges while
|
||||
/// also supporting newer labels that display a measured bitrate instead.
|
||||
bool shouldHighlightAudioQualityBadge(String quality) {
|
||||
|
||||
Reference in New Issue
Block a user