单词详情页增加学习按钮,支持单词拼写循环练习
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,13 @@ struct QuizSetupRequest: Hashable {
|
|||||||
struct QuizConfig: Hashable {
|
struct QuizConfig: Hashable {
|
||||||
let mode: QuizMode
|
let mode: QuizMode
|
||||||
let words: [Word]
|
let words: [Word]
|
||||||
|
let isStudyMode: Bool
|
||||||
|
|
||||||
|
init(mode: QuizMode, words: [Word], isStudyMode: Bool = false) {
|
||||||
|
self.mode = mode
|
||||||
|
self.words = words
|
||||||
|
self.isStudyMode = isStudyMode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct QuizQuestion: Identifiable {
|
struct QuizQuestion: Identifiable {
|
||||||
|
|||||||
@@ -347,10 +347,23 @@ final class QuizViewController: UIViewController {
|
|||||||
resultLabel.textColor = correct ? Theme.Color.correct : Theme.Color.wrong
|
resultLabel.textColor = correct ? Theme.Color.correct : Theme.Color.wrong
|
||||||
resultLabel.isHidden = false
|
resultLabel.isHidden = false
|
||||||
|
|
||||||
|
if config.isStudyMode {
|
||||||
|
if correct {
|
||||||
|
nextButton.isHidden = true
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) { [weak self] in
|
||||||
|
self?.restart()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextButton.configuration?.title = "继续学习"
|
||||||
|
nextButton.isEnabled = true
|
||||||
|
nextButton.isHidden = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
nextButton.configuration?.title = currentIndex + 1 < questions.count ? "下一题" : "查看成绩"
|
nextButton.configuration?.title = currentIndex + 1 < questions.count ? "下一题" : "查看成绩"
|
||||||
nextButton.isEnabled = true
|
nextButton.isEnabled = true
|
||||||
nextButton.isHidden = false
|
nextButton.isHidden = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func speakCurrentWord() {
|
@objc private func speakCurrentWord() {
|
||||||
guard let question = current else { return }
|
guard let question = current else { return }
|
||||||
@@ -358,7 +371,9 @@ final class QuizViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func primaryButtonTapped() {
|
private func primaryButtonTapped() {
|
||||||
if config.mode == .spelling, selectedOption == nil {
|
if config.isStudyMode, selectedOption != nil {
|
||||||
|
restart()
|
||||||
|
} else if config.mode == .spelling, selectedOption == nil {
|
||||||
guard let question = current, spellingView.isComplete else { return }
|
guard let question = current, spellingView.isComplete else { return }
|
||||||
submitSpelling(spellingView.typedWord(), for: question)
|
submitSpelling(spellingView.typedWord(), for: question)
|
||||||
} else if config.mode == .dictation, selectedOption == nil {
|
} else if config.mode == .dictation, selectedOption == nil {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ final class WordDetailViewController: UIViewController {
|
|||||||
view.backgroundColor = .systemBackground
|
view.backgroundColor = .systemBackground
|
||||||
title = categoryName
|
title = categoryName
|
||||||
navigationItem.largeTitleDisplayMode = .never
|
navigationItem.largeTitleDisplayMode = .never
|
||||||
|
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "学习", style: .plain, target: self, action: #selector(startSpelling))
|
||||||
buildLayout()
|
buildLayout()
|
||||||
updateSpeakState()
|
updateSpeakState()
|
||||||
speechObserver = NotificationCenter.default.addObserver(
|
speechObserver = NotificationCenter.default.addObserver(
|
||||||
@@ -186,6 +187,12 @@ final class WordDetailViewController: UIViewController {
|
|||||||
return card
|
return card
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func startSpelling() {
|
||||||
|
Haptics.selection()
|
||||||
|
let config = QuizConfig(mode: .spelling, words: [word])
|
||||||
|
navigationController?.pushViewController(QuizViewController(config: config), animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
private func searchMeaning() {
|
private func searchMeaning() {
|
||||||
Haptics.selection()
|
Haptics.selection()
|
||||||
let text = "\(word.meaning) 是什么意思"
|
let text = "\(word.meaning) 是什么意思"
|
||||||
|
|||||||
Reference in New Issue
Block a user