From 74dcaee3355a5abb42e47e88e9693fd24c50cde5 Mon Sep 17 00:00:00 2001 From: fish Date: Tue, 21 Jul 2026 21:31:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=94=B9=E7=94=A8=E5=8D=A1=E7=89=87=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=EF=BC=8C=E4=B8=8E=E9=A6=96=E9=A1=B5=E5=8D=95?= =?UTF-8?q?=E8=AF=8D=E5=88=97=E8=A1=A8=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- .../Views/HistoryViewController.swift | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift b/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift index e154618..95ba835 100644 --- a/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift +++ b/LearnEnglish/LearnEnglish/Views/HistoryViewController.swift @@ -2,6 +2,7 @@ import UIKit final class HistoryViewController: UITableViewController { private let sections: [(title: String, items: [LearnedRecord])] + private var speechObserver: NSObjectProtocol? init() { sections = LearnedStore.shared.sectioned @@ -11,13 +12,26 @@ final class HistoryViewController: UITableViewController { @available(*, unavailable) required init?(coder: NSCoder) { fatalError() } + deinit { + if let speechObserver { + NotificationCenter.default.removeObserver(speechObserver) + } + } + override func viewDidLoad() { super.viewDidLoad() title = "学习记录" navigationItem.largeTitleDisplayMode = .never - tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") + tableView.register(WordCardCell.self, forCellReuseIdentifier: "cell") + tableView.separatorStyle = .none tableView.backgroundColor = .systemBackground updateEmptyState() + + speechObserver = NotificationCenter.default.addObserver( + forName: SpeechService.speakingDidChangeNotification, object: nil, queue: .main + ) { [weak self] _ in + self?.updateVisibleSpeakers() + } } private func updateEmptyState() { @@ -38,6 +52,12 @@ final class HistoryViewController: UITableViewController { } } + private func updateVisibleSpeakers() { + for cell in tableView.visibleCells.compactMap({ $0 as? WordCardCell }) { + cell.updateSpeakerState() + } + } + override func numberOfSections(in tableView: UITableView) -> Int { sections.count } @@ -51,14 +71,17 @@ final class HistoryViewController: UITableViewController { } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! WordCardCell let record = sections[indexPath.section].items[indexPath.row] - var config = cell.defaultContentConfiguration() - config.text = record.word.word - config.secondaryText = "\(record.word.phonetic) \(record.word.meaning)" - config.image = UIImage(systemName: "text.book.closed") - config.imageProperties.tintColor = Theme.Color.accent - cell.contentConfiguration = config + cell.configure(with: record.word) + cell.onSpeak = { word in + SpeechService.shared.speak(word.word) + } + cell.onLearn = { [weak self] word in + guard let self else { return } + let config = QuizConfig(mode: .spelling, words: [word], isStudyMode: true) + navigationController?.pushViewController(QuizViewController(config: config), animated: true) + } return cell }