Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature | Anki Mode] 594 - Combine Reading + Meaning #664

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ios/ReviewSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ReviewSession {
self.services = services
reviewQueue = items

if Settings.groupMeaningReading {
if Settings.groupMeaningReading || (Settings.ankiMode &&
Settings.ankiModeCombineReadingMeaning) {
activeQueueSize = 1
} else {
activeQueueSize = Int(Settings.reviewBatchSize)
Expand Down Expand Up @@ -85,7 +86,8 @@ class ReviewSession {
activeTaskType = .reading
} else if activeTask.answeredReading || activeSubject.readings.isEmpty {
activeTaskType = .meaning
} else if Settings.groupMeaningReading {
} else if Settings.groupMeaningReading || (Settings.ankiMode &&
Settings.ankiModeCombineReadingMeaning) {
activeTaskType = Settings.meaningFirst ? .meaning : .reading
} else {
activeTaskType = TaskType.random()
Expand Down
20 changes: 20 additions & 0 deletions ios/ReviewSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ReviewSettingsViewController: UITableViewController, TKMViewController {
private var services: TKMServices!
private var model: TableModel?
private var groupMeaningReadingIndexPath: IndexPath?
private var ankiModeCombineReadingMeaningIndexPath: IndexPath?

func setup(services: TKMServices) {
self.services = services
Expand Down Expand Up @@ -151,6 +152,17 @@ class ReviewSettingsViewController: UITableViewController, TKMViewController {
target: self,
action: #selector(ankiModeSwitchChanged(_:))))

let ankiModeCombineReadingMeaning = SwitchModelItem(style: .subtitle,
title: "Combine Reading + Meaning",
subtitle: "Only one review for reading and meaning with Anki mode enabled",
on: Settings.ankiModeCombineReadingMeaning,
target: self,
action: #selector(ankiModeCombineReadingMeaningSwitchChanged(_:)))

ankiModeCombineReadingMeaning.numberOfSubtitleLines = 0
ankiModeCombineReadingMeaningIndexPath = model.add(ankiModeCombineReadingMeaning,
hidden:!Settings.ankiMode)

model.add(section: "Audio")
model.add(SwitchModelItem(style: .subtitle,
title: "Play audio automatically",
Expand Down Expand Up @@ -292,6 +304,14 @@ class ReviewSettingsViewController: UITableViewController, TKMViewController {

@objc private func ankiModeSwitchChanged(_ switchView: UISwitch) {
Settings.ankiMode = switchView.isOn
Settings.ankiModeCombineReadingMeaning = false
if let indexPath = ankiModeCombineReadingMeaningIndexPath {
model?.setIndexPath(indexPath, hidden: !switchView.isOn)
}
}

@objc private func ankiModeCombineReadingMeaningSwitchChanged(_ switchView: UISwitch) {
Settings.ankiModeCombineReadingMeaning = switchView.isOn
}

@objc private func playAudioAutomaticallySwitchChanged(_ switchView: UISwitch) {
Expand Down
15 changes: 14 additions & 1 deletion ios/ReviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ class ReviewViewController: UIViewController, UITextFieldDelegate, SubjectDelega
}
}

if session.activeAssignment.subjectType != .radical,
Settings.ankiMode,
Settings.ankiModeCombineReadingMeaning {
taskTypePrompt = Settings.meaningFirst ? "Meaning + Reading" : "Reading + Meaning"
}

// Choose a random font.
currentFontName = randomFont(thatCanRenderText: session.activeSubject.japanese)

Expand Down Expand Up @@ -1019,10 +1025,17 @@ class ReviewViewController: UIViewController, UITextFieldDelegate, SubjectDelega
}

// Mark the task.
let marked = session.markAnswer(result)
var marked = session.markAnswer(result)

// Show a new task if it was correct.
if result != .Incorrect {
if session.activeAssignment.subjectType != .radical, // or kana mode?
Settings.ankiMode,
Settings.ankiModeCombineReadingMeaning {
session.nextTask()
marked = session.markAnswer(.Correct)
}

if Settings.playAudioAutomatically, session.activeTaskType == .reading,
let subject = session.activeSubject,
subject.hasVocabulary, !subject.vocabulary.audio.isEmpty {
Expand Down
1 change: 1 addition & 0 deletions ios/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ protocol SettingProtocol {
@Setting(false, #keyPath(allowSkippingReviews)) static var allowSkippingReviews: Bool
@Setting(true, #keyPath(minimizeReviewPenalty)) static var minimizeReviewPenalty: Bool
@Setting(false, #keyPath(ankiMode)) static var ankiMode: Bool
@Setting(false, #keyPath(ankiModeCombineReadingMeaning)) static var ankiModeCombineReadingMeaning: Bool
@Setting(true, #keyPath(showPreviousLevelGraph)) static var showPreviousLevelGraph: Bool
@Setting(true, #keyPath(showKanaOnlyVocab)) static var showKanaOnlyVocab: Bool

Expand Down