学习记录页面改用卡片风格展示,与首页单词列表保持一致
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import UIKit
|
|||||||
|
|
||||||
final class HistoryViewController: UITableViewController {
|
final class HistoryViewController: UITableViewController {
|
||||||
private let sections: [(title: String, items: [LearnedRecord])]
|
private let sections: [(title: String, items: [LearnedRecord])]
|
||||||
|
private var speechObserver: NSObjectProtocol?
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
sections = LearnedStore.shared.sectioned
|
sections = LearnedStore.shared.sectioned
|
||||||
@@ -11,13 +12,26 @@ final class HistoryViewController: UITableViewController {
|
|||||||
@available(*, unavailable)
|
@available(*, unavailable)
|
||||||
required init?(coder: NSCoder) { fatalError() }
|
required init?(coder: NSCoder) { fatalError() }
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
if let speechObserver {
|
||||||
|
NotificationCenter.default.removeObserver(speechObserver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
title = "学习记录"
|
title = "学习记录"
|
||||||
navigationItem.largeTitleDisplayMode = .never
|
navigationItem.largeTitleDisplayMode = .never
|
||||||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
|
tableView.register(WordCardCell.self, forCellReuseIdentifier: "cell")
|
||||||
|
tableView.separatorStyle = .none
|
||||||
tableView.backgroundColor = .systemBackground
|
tableView.backgroundColor = .systemBackground
|
||||||
updateEmptyState()
|
updateEmptyState()
|
||||||
|
|
||||||
|
speechObserver = NotificationCenter.default.addObserver(
|
||||||
|
forName: SpeechService.speakingDidChangeNotification, object: nil, queue: .main
|
||||||
|
) { [weak self] _ in
|
||||||
|
self?.updateVisibleSpeakers()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateEmptyState() {
|
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 {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
sections.count
|
sections.count
|
||||||
}
|
}
|
||||||
@@ -51,14 +71,17 @@ final class HistoryViewController: UITableViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
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]
|
let record = sections[indexPath.section].items[indexPath.row]
|
||||||
var config = cell.defaultContentConfiguration()
|
cell.configure(with: record.word)
|
||||||
config.text = record.word.word
|
cell.onSpeak = { word in
|
||||||
config.secondaryText = "\(record.word.phonetic) \(record.word.meaning)"
|
SpeechService.shared.speak(word.word)
|
||||||
config.image = UIImage(systemName: "text.book.closed")
|
}
|
||||||
config.imageProperties.tintColor = Theme.Color.accent
|
cell.onLearn = { [weak self] word in
|
||||||
cell.contentConfiguration = config
|
guard let self else { return }
|
||||||
|
let config = QuizConfig(mode: .spelling, words: [word], isStudyMode: true)
|
||||||
|
navigationController?.pushViewController(QuizViewController(config: config), animated: true)
|
||||||
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user