refactor(ui): share legacy provider-id resource helpers

legacyProviderIdFromResourceId and stripPrefixedResourceId were
copy-pasted in the album, artist, and playlist screens with slightly
different null semantics; the shared nullable variant plus explicit
?? 'spotify' fallbacks makes the difference visible at the call sites.
This commit is contained in:
zarzet
2026-07-09 20:10:36 +07:00
parent 70cba44164
commit 2e7e2b1964
4 changed files with 29 additions and 49 deletions
+18
View File
@@ -0,0 +1,18 @@
/// Maps a legacy prefixed resource id (e.g. "deezer:123") to its provider id,
/// or null when the value carries no known provider prefix.
String? legacyProviderIdFromResourceId(String value) {
if (value.startsWith('deezer:')) return 'deezer';
if (value.startsWith('qobuz:')) return 'qobuz';
if (value.startsWith('tidal:')) return 'tidal';
if (value.startsWith('spotify:')) return 'spotify';
return null;
}
/// Strips a leading "provider:" prefix from a resource id, if present.
String stripPrefixedResourceId(String value) {
final colonIndex = value.indexOf(':');
if (colonIndex <= 0 || colonIndex == value.length - 1) {
return value;
}
return value.substring(colonIndex + 1);
}