学习记录展示具体学习时间,精确到时分秒

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-21 22:17:15 +08:00
parent 106b60b58f
commit ad0ff1ca7a
3 changed files with 11 additions and 4 deletions
@@ -3,6 +3,12 @@ import UIKit
final class HistoryViewController: UITableViewController { final class HistoryViewController: UITableViewController {
private var sections: [(title: String, items: [LearnedRecord])] = [] private var sections: [(title: String, items: [LearnedRecord])] = []
private var speechObserver: NSObjectProtocol? private var speechObserver: NSObjectProtocol?
private let timeFormatter: DateFormatter = {
let f = DateFormatter()
f.locale = Locale(identifier: "zh_CN")
f.dateFormat = "HH:mm:ss"
return f
}()
init() { init() {
super.init(style: .plain) super.init(style: .plain)
@@ -73,7 +79,8 @@ 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) as! WordCardCell 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]
cell.configure(with: record.word, count: record.count, accuracy: record.accuracy) let time = timeFormatter.string(from: record.learnedAt)
cell.configure(with: record.word, count: record.count, accuracy: record.accuracy, time: time)
cell.onSpeak = { word in cell.onSpeak = { word in
SpeechService.shared.speak(word.word) SpeechService.shared.speak(word.word)
} }
@@ -92,9 +92,9 @@ final class WordCardCell: UITableViewCell {
updateSpeakerState() updateSpeakerState()
} }
func configure(with word: Word, count: Int, accuracy: Int) { func configure(with word: Word, count: Int, accuracy: Int, time: String) {
configure(with: word) configure(with: word)
countLabel.text = "\(count)次 · \(accuracy)%" countLabel.text = "\(count)次 · \(accuracy)% · \(time)"
countLabel.isHidden = false countLabel.isHidden = false
} }
@@ -118,7 +118,7 @@ final class WordHistoryViewController: UIViewController {
let formatter = DateFormatter() let formatter = DateFormatter()
formatter.locale = Locale(identifier: "zh_CN") formatter.locale = Locale(identifier: "zh_CN")
formatter.dateFormat = "yyyy-MM-dd HH:mm" formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateLabel = UILabel() let dateLabel = UILabel()
dateLabel.text = "最近学习:\(formatter.string(from: record.learnedAt))" dateLabel.text = "最近学习:\(formatter.string(from: record.learnedAt))"
dateLabel.font = .preferredFont(forTextStyle: .caption1) dateLabel.font = .preferredFont(forTextStyle: .caption1)