Skip to content

Commit e28f53d

Browse files
committed
FEAT: 难度徽章不再限定社区合集,学习页推荐只选有字幕材料
- 难度徽章只要 difficulty 有值就显示,不再要求仍关联社区合集(覆盖搜索结果、已完成列表和元信息行) - 学习页「为你推荐」与「已学完的材料」不再显示 CC 标记(新增 showTranscriptBadge,默认仍显示) - 学习页推荐的候选材料必须有字幕 - 修正测试:全局列表显示难度徽章;完成状态下首次学习与已完成复习轮次各显示一次 4/4
1 parent e0f3cf7 commit e28f53d

7 files changed

Lines changed: 69 additions & 20 deletions

File tree

‎lib/providers/study_task_provider.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ AudioItem? selectStudyRecommendation({
391391
final recentCompletionIds = recentCompletions
392392
.map((completion) => completion.audioId)
393393
.toSet();
394+
// 推荐的材料必须有字幕,否则学习页推荐的入口无法进入逐句学习。
394395
bool isEligibleForRecommendation(AudioItem material) {
395396
final progress = progressByAudioId[material.id];
396-
return !recentCompletionIds.contains(material.id) &&
397+
return material.hasTranscript &&
398+
!recentCompletionIds.contains(material.id) &&
397399
progress?.isCompleted != true &&
398400
progress?.isInReviewStage != true;
399401
}

‎lib/screens/study_screen.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class _RecommendedMaterialCard extends ConsumerWidget {
541541
crossAxisAlignment: CrossAxisAlignment.start,
542542
mainAxisSize: MainAxisSize.min,
543543
children: [
544-
AudioMetaLine(audio: material),
544+
AudioMetaLine(audio: material, showTranscriptBadge: false),
545545
const SizedBox(height: 3),
546546
Text(
547547
_stageSubStageLabel(l10n, stage, subStage),
@@ -835,6 +835,7 @@ class _CompletedSection extends StatelessWidget {
835835
(audio) => AudioListTile(
836836
audioItem: audio,
837837
showMenu: false,
838+
showTranscriptBadge: false,
838839
titleMaxLines: 1,
839840
outerPadding: EdgeInsets.zero,
840841
),

‎lib/widgets/audio_list_tile.dart‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class AudioListTile extends ConsumerWidget {
9595
/// 是否展示右侧菜单按钮。只读展示场景(如学习页已完成折叠区)传 false。
9696
final bool showMenu;
9797

98+
/// 是否显示字幕 CC 徽章;学习页的已完成列表不需要展示。
99+
final bool showTranscriptBadge;
100+
98101
/// 标题最多显示行数。默认 2 行,与合集详情页、搜索结果保持一致;
99102
/// 空间紧凑的只读列表(如学习页已完成折叠区)可传 1。
100103
final int titleMaxLines;
@@ -117,6 +120,7 @@ class AudioListTile extends ConsumerWidget {
117120
this.onSelectToggle,
118121
this.searchQuery = '',
119122
this.showMenu = true,
123+
this.showTranscriptBadge = true,
120124
this.titleMaxLines = 2,
121125
this.outerPadding = const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
122126
});
@@ -131,9 +135,8 @@ class AudioListTile extends ConsumerWidget {
131135
final pinnedHighlightColor = theme.colorScheme.primary.withValues(
132136
alpha: 0.06,
133137
);
134-
final difficulty = audioItem.isCommunity
135-
? CommunityDifficulty.fromCode(audioItem.difficulty)
136-
: null;
138+
// 难度是通用属性:只要有值就显示,不再区分是否仍关联社区合集。
139+
final difficulty = CommunityDifficulty.fromCode(audioItem.difficulty);
137140

138141
// 已订阅合集(社区 / 播客)的下载状态在元信息行展示。
139142
final subscribedCollection = _subscribedCollection(ref);
@@ -418,7 +421,8 @@ class AudioListTile extends ConsumerWidget {
418421
audioItem.contentStatus,
419422
);
420423
// CC 徽章已下沉到元信息行(与时长/日期同排),不再触发标签行。
421-
final hasCc = audioItem.hasTranscript && !isTranscribing;
424+
final hasCc =
425+
showTranscriptBadge && audioItem.hasTranscript && !isTranscribing;
422426
final hasBadgeRow =
423427
isTranscribing ||
424428
contentWarningLabel != null ||

‎lib/widgets/audio_meta_line.dart‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,21 @@ String formatAudioDuration(int totalSeconds) {
9595
class AudioMetaLine extends StatelessWidget {
9696
final AudioItem audio;
9797

98-
const AudioMetaLine({super.key, required this.audio});
98+
/// 是否显示字幕 CC 徽章;学习页的已完成/推荐区域不需要展示。
99+
final bool showTranscriptBadge;
100+
101+
const AudioMetaLine({
102+
super.key,
103+
required this.audio,
104+
this.showTranscriptBadge = true,
105+
});
99106

100107
@override
101108
Widget build(BuildContext context) {
102109
final l10n = AppLocalizations.of(context)!;
103110
final theme = Theme.of(context);
104-
final difficulty = audio.isCommunity
105-
? CommunityDifficulty.fromCode(audio.difficulty)
106-
: null;
111+
// 难度是通用属性:只要有值就显示,不再区分是否仍关联社区合集。
112+
final difficulty = CommunityDifficulty.fromCode(audio.difficulty);
107113
final meta = buildAudioMetaParts(context, audio);
108114
final metaText = Text.rich(
109115
TextSpan(children: meta.spans),
@@ -116,7 +122,7 @@ class AudioMetaLine extends StatelessWidget {
116122

117123
return Row(
118124
children: [
119-
if (audio.hasTranscript) ...[
125+
if (showTranscriptBadge && audio.hasTranscript) ...[
120126
TranscriptCcBadge(
121127
containerKey: const Key('audio_meta_line_transcript_badge'),
122128
label: l10n.transcript,

‎test/providers/study_task_provider_test.dart‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,12 +1141,14 @@ void main() {
11411141
group('selectStudyRecommendation', () {
11421142
final now = DateTime(2026, 10, 11, 12);
11431143

1144-
AudioItem material(String id, String name) => AudioItem(
1145-
id: id,
1146-
name: name,
1147-
audioPath: 'materials/$id.mp3',
1148-
addedDate: now,
1149-
);
1144+
AudioItem material(String id, String name, {bool hasSubtitle = true}) =>
1145+
AudioItem(
1146+
id: id,
1147+
name: name,
1148+
audioPath: 'materials/$id.mp3',
1149+
addedDate: now,
1150+
transcriptSource: hasSubtitle ? TranscriptSource.local : null,
1151+
);
11501152

11511153
RecentCompletion completion(String audioId, DateTime completedAt) =>
11521154
RecentCompletion(
@@ -1201,6 +1203,24 @@ void main() {
12011203
expect(result?.id, 'planned');
12021204
});
12031205

1206+
test('没有字幕的材料不推荐,即使它是最近学习的材料', () {
1207+
final result = selectStudyRecommendation(
1208+
materials: [
1209+
material('no-subtitle', 'No Subtitle', hasSubtitle: false),
1210+
material('with-subtitle', 'With Subtitle'),
1211+
],
1212+
progressByAudioId: {},
1213+
playbackSavedAtByAudioId: {
1214+
'no-subtitle': now.add(const Duration(hours: 5)),
1215+
'with-subtitle': now.add(const Duration(hours: 1)),
1216+
},
1217+
latestCompletionAtByAudioId: const {},
1218+
recentCompletions: const [],
1219+
);
1220+
1221+
expect(result?.id, 'with-subtitle');
1222+
});
1223+
12041224
test('待解锁的复习材料不推荐,即使它是最近学习的材料', () {
12051225
final result = selectStudyRecommendation(
12061226
materials: [material('locked', 'Locked'), material('free', 'Free')],

‎test/screens/learning_plan_screen_test.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,8 @@ void main() {
21152115
expect(find.text('100%'), findsOneWidget);
21162116
// 卡片不再显示状态文案
21172117
expect(find.text('Completed'), findsNothing);
2118-
expect(find.text('4/4'), findsOneWidget);
2118+
// 首次学习卡片与已完成的复习轮次各显示一次 4/4
2119+
expect(find.text('4/4'), findsNWidgets(2));
21192120
expect(find.text('4/4 completed'), findsNothing);
21202121
expect(find.text('✅'), findsNothing);
21212122
expect(

‎test/widgets/audio_list_tile_test.dart‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void main() {
218218
expect(tester.takeException(), isNull);
219219
});
220220

221-
testWidgets('资源库全局列表不显示合集专属难度徽章', (tester) async {
221+
testWidgets('全局列表(搜索结果、已完成列表)同样显示社区难度徽章', (tester) async {
222222
final item = createTestAudioItem().copyWith(
223223
remoteAudioId: 'remote-1',
224224
difficulty: 'B1',
@@ -227,7 +227,22 @@ void main() {
227227
await tester.pumpWidget(buildTile(item));
228228
await tester.pumpAndSettle();
229229

230-
expect(find.byKey(const Key('community_difficulty_badge')), findsNothing);
230+
expect(
231+
find.byKey(const Key('community_difficulty_badge')),
232+
findsOneWidget,
233+
);
234+
});
235+
236+
testWidgets('已解除社区关联的本地音频保留难度并显示徽章', (tester) async {
237+
final item = createTestAudioItem().copyWith(difficulty: 'B1');
238+
239+
await tester.pumpWidget(buildTile(item));
240+
await tester.pumpAndSettle();
241+
242+
expect(
243+
find.byKey(const Key('community_difficulty_badge')),
244+
findsOneWidget,
245+
);
231246
});
232247

233248
testWidgets('全局搜索结果长标题同样最多显示两行', (tester) async {

0 commit comments

Comments
 (0)