diff --git a/LearnEnglish/LearnEnglish/Views/WordCardCell.swift b/LearnEnglish/LearnEnglish/Views/WordCardCell.swift index 96db8c2..fd0fb92 100644 --- a/LearnEnglish/LearnEnglish/Views/WordCardCell.swift +++ b/LearnEnglish/LearnEnglish/Views/WordCardCell.swift @@ -5,10 +5,12 @@ final class WordCardCell: UITableViewCell { private let wordLabel = UILabel() private let phoneticLabel = UILabel() private let meaningLabel = UILabel() + private let learnButton = UIButton(type: .system) private let speakerButton = UIButton(type: .system) private var word: Word? var onSpeak: ((Word) -> Void)? + var onLearn: ((Word) -> Void)? var zoomSourceView: UIView { cardView } @@ -39,6 +41,15 @@ final class WordCardCell: UITableViewCell { textStack.axis = .vertical textStack.spacing = 8 + learnButton.setImage(UIImage(systemName: "book", + withConfiguration: UIImage.SymbolConfiguration(pointSize: 15, weight: .medium)), + for: .normal) + learnButton.tintColor = Theme.Color.accent + learnButton.addAction(UIAction { [weak self] _ in + guard let self, let word else { return } + onLearn?(word) + }, for: .touchUpInside) + speakerButton.tintColor = Theme.Color.accent speakerButton.addAction(UIAction { [weak self] _ in guard let self, let word else { return } @@ -46,7 +57,7 @@ final class WordCardCell: UITableViewCell { }, for: .touchUpInside) speakerButton.setContentHuggingPriority(.required, for: .horizontal) - let row = UIStackView(arrangedSubviews: [textStack, speakerButton]) + let row = UIStackView(arrangedSubviews: [textStack, learnButton, speakerButton]) row.axis = .horizontal row.alignment = .center row.spacing = 8 @@ -57,6 +68,8 @@ final class WordCardCell: UITableViewCell { row.leadingAnchor.constraint(equalTo: cardView.leadingAnchor, constant: 14), row.trailingAnchor.constraint(equalTo: cardView.trailingAnchor, constant: -8), row.bottomAnchor.constraint(equalTo: cardView.bottomAnchor, constant: -10), + learnButton.widthAnchor.constraint(equalToConstant: 44), + learnButton.heightAnchor.constraint(equalToConstant: 44), speakerButton.widthAnchor.constraint(equalToConstant: 44), speakerButton.heightAnchor.constraint(equalToConstant: 44) ]) diff --git a/LearnEnglish/LearnEnglish/Views/WordListViewController.swift b/LearnEnglish/LearnEnglish/Views/WordListViewController.swift index 81616c6..8fa03ca 100644 --- a/LearnEnglish/LearnEnglish/Views/WordListViewController.swift +++ b/LearnEnglish/LearnEnglish/Views/WordListViewController.swift @@ -148,6 +148,11 @@ extension WordListViewController: UITableViewDataSource, UITableViewDelegate { 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 }