feat(ui): 收藏项无元数据时,副标题显示上级文件夹名(带括号)

之前无标签时副标题固定写"收藏",和"歌手"语义混在一起。
现在取 path 的上一级目录(解码后)显示为 "(B-未分类)" 这种形式:
- 括号清楚表明是目录,不是艺术家
- 有标签时仍优先显示艺术家
- 目录层级不足或解码失败时回退为空(displaySubtitle 兜底"未知艺术家")

真机验证:收藏项显示 "13楼的大笨象 - 郑融" / "(B-未分类)"。
This commit is contained in:
2026-10-24 21:44:14 +08:00
parent d3ed871626
commit 672a545c38
+14 -4
View File
@@ -35,11 +35,10 @@ class SongItem {
: fileName.replaceAll(RegExp(r'\.[^.]*$'), ''); : fileName.replaceAll(RegExp(r'\.[^.]*$'), '');
String get displaySubtitle { String get displaySubtitle {
if (metadataState == 'success' && artist != null) { if (metadataState == 'success' && artist != null && artist!.isNotEmpty) {
return artist!; return artist!;
} else {
return sourceTag;
} }
return sourceTag.isNotEmpty ? sourceTag : '未知艺术家';
} }
} }
@@ -272,12 +271,23 @@ class _HomePageState extends BaseState<HomePage> {
displayName = rawName; displayName = rawName;
} }
// 取上级目录名,作为没有标签时的副标题(加括号区分"这是文件夹")
final segments = path.split('/').where((s) => s.isNotEmpty).toList();
String folderName = '';
if (segments.length >= 2) {
try {
folderName = Uri.decodeComponent(segments[segments.length - 2]);
} catch (_) {
folderName = segments[segments.length - 2];
}
}
items.add(SongItem( items.add(SongItem(
path: path, path: path,
fileName: displayName, fileName: displayName,
title: hasTitle ? title : null, title: hasTitle ? title : null,
artist: artist.isNotEmpty ? artist : null, artist: artist.isNotEmpty ? artist : null,
sourceTag: '收藏', sourceTag: folderName.isNotEmpty ? '($folderName)' : '',
metadataState: hasTitle ? 'success' : 'unknown', metadataState: hasTitle ? 'success' : 'unknown',
)); ));
} }