feat(library): add quality label display modes

This commit is contained in:
zarzet
2026-07-27 17:25:39 +07:00
parent e4cd52f29f
commit 454ef53977
13 changed files with 334 additions and 44 deletions
+65
View File
@@ -1,4 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:spotiflac_android/models/settings.dart';
import 'package:spotiflac_android/utils/audio_quality_badge_policy.dart';
void main() {
@@ -22,4 +23,68 @@ void main() {
expect(shouldHighlightAudioQualityBadge('16-bit/44.1kHz'), isFalse);
});
});
group('Library audio quality label mode', () {
test('uses measured bitrate by default', () {
expect(
buildLibraryAudioQualityLabel(
mode: AppSettings.libraryQualityLabelBitrate,
format: 'flac',
bitrateKbps: 1760,
bitDepth: 24,
sampleRate: 48000,
),
'FLAC 1760kbps',
);
expect(
normalizeLibraryQualityLabelMode('unsupported'),
AppSettings.libraryQualityLabelBitrate,
);
});
test('restores legacy bit depth and sample rate labels', () {
expect(
buildLibraryAudioQualityLabel(
mode: AppSettings.libraryQualityLabelBitDepth,
format: 'flac',
bitrateKbps: 1760,
bitDepth: 24,
sampleRate: 48000,
),
'24-bit/48kHz',
);
});
test('keeps bitrate meaningful for lossy formats', () {
expect(
buildLibraryAudioQualityLabel(
mode: AppSettings.libraryQualityLabelBitDepth,
format: 'mp3',
bitrateKbps: 320,
bitDepth: 16,
sampleRate: 44100,
),
'MP3 320kbps',
);
});
test('falls back when the preferred metadata is unavailable', () {
expect(
buildLibraryAudioQualityLabel(
mode: AppSettings.libraryQualityLabelBitDepth,
format: 'flac',
bitrateKbps: 950,
storedQuality: 'LOSSLESS',
),
'FLAC 950kbps',
);
expect(
buildLibraryAudioQualityLabel(
mode: AppSettings.libraryQualityLabelBitrate,
storedQuality: '24-bit/96kHz',
),
'24-bit/96kHz',
);
});
});
}
+14
View File
@@ -510,6 +510,10 @@ void main() {
expect(settings.deduplicateDownloads, isTrue);
expect(settings.allowQualityVariants, isFalse);
expect(settings.nativeDownloadWorkerEnabled, isFalse);
expect(
settings.libraryQualityLabelMode,
AppSettings.libraryQualityLabelBitrate,
);
});
test('copyWith updates values and can clear nullable provider fields', () {
@@ -526,6 +530,7 @@ void main() {
lyricsAppleElrcWordSync: true,
deduplicateDownloads: false,
allowQualityVariants: true,
libraryQualityLabelMode: AppSettings.libraryQualityLabelBitDepth,
clearDownloadFallbackExtensionIds: true,
clearSearchProvider: true,
clearHomeFeedProvider: true,
@@ -537,6 +542,10 @@ void main() {
expect(updated.lyricsAppleElrcWordSync, isTrue);
expect(updated.deduplicateDownloads, isFalse);
expect(updated.allowQualityVariants, isTrue);
expect(
updated.libraryQualityLabelMode,
AppSettings.libraryQualityLabelBitDepth,
);
expect(updated.downloadFallbackExtensionIds, isNull);
expect(updated.searchProvider, isNull);
expect(updated.homeFeedProvider, isNull);
@@ -563,6 +572,7 @@ void main() {
deduplicateDownloads: false,
allowQualityVariants: true,
nativeDownloadWorkerEnabled: true,
libraryQualityLabelMode: AppSettings.libraryQualityLabelBitDepth,
);
final decoded = AppSettings.fromJson(settings.toJson());
@@ -582,6 +592,10 @@ void main() {
expect(decoded.musixmatchLanguage, 'id');
expect(decoded.lyricsAppleElrcWordSync, isTrue);
expect(decoded.lastSeenVersion, '4.5.0');
expect(
decoded.libraryQualityLabelMode,
AppSettings.libraryQualityLabelBitDepth,
);
expect(decoded.deduplicateDownloads, isFalse);
expect(decoded.allowQualityVariants, isTrue);
expect(decoded.nativeDownloadWorkerEnabled, isTrue);