Skip to content

Commit

Permalink
Add option for viewing current level graph before finishing vocab (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadpikle committed Feb 12, 2023
1 parent 7062fb5 commit 680acde
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 30 deletions.
13 changes: 13 additions & 0 deletions ios/LocalCachingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ private func postNotificationOnMainQueue(_ notification: Notification.Name) {
return getAssignments(level: Int(userInfo.level))
}

func hasCompletedPreviousLevel() -> Bool {
guard let userInfo = getUserInfo() else {
return false
}
var level = Int(userInfo.level)
if level > 1 {
level = level - 1
}
let assignments = getAssignments(level: level)
// if any assignment has not been passed, they have not passed the prior level
return !assignments.contains { !$0.hasPassedAt }
}

private func getAssignments(level: Int, transaction db: FMDatabase) -> [TKMAssignment] {
var ret = [TKMAssignment]()
var subjectIds = Set<Int>()
Expand Down
64 changes: 40 additions & 24 deletions ios/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class MainViewController: UIViewController, LoginViewControllerDelegate,
var hasReviews = false
var updatingTableModel = false

var selectedSubjectCatalogLevel = -1

private let nd = NotificationDispatcher()

func setup(services: TKMServices) {
Expand Down Expand Up @@ -158,6 +160,9 @@ class MainViewController: UIViewController, LoginViewControllerDelegate,
private func recreateTableModel() {
guard let user = services.localCachingClient.getUserInfo() else { return }

// make sure that the selected subject level is reset each time table is loaded in case things change
selectedSubjectCatalogLevel = -1

let lessons = services.localCachingClient.availableLessonCount
let reviews = services.localCachingClient.availableReviewCount
let upcomingReviews = services.localCachingClient.upcomingReviews
Expand Down Expand Up @@ -197,26 +202,29 @@ class MainViewController: UIViewController, LoginViewControllerDelegate,
currentLevelAssignments: currentLevelAssignments))
}

model.add(section: "This level")
if Settings.showPreviousLevelGraph, user.currentLevel > 1,
!services.localCachingClient.hasCompletedPreviousLevel() {
let previousLevel = Int(user.currentLevel) - 1
model
.add(section: "Current level (\(user.currentLevel - 1))")
let currentGraphLevelAssignments = services.localCachingClient
.getAssignments(level: previousLevel)
model.add(CurrentLevelChartItem(currentLevelAssignments: currentGraphLevelAssignments))
addShowRemainingAllItems(model: model, level: previousLevel)
// add header for next section; graph and other items will be added after this if/else block
model.add(section: "Next level (\(user.currentLevel))")
} else {
model.add(section: "Current level")
}

model.add(CurrentLevelChartItem(currentLevelAssignments: currentLevelAssignments))

if !user.hasVacationStartedAt {
model
.add(createLevelTimeRemainingItem(services: services,
currentLevelAssignments: currentLevelAssignments))
}
model.add(BasicModelItem(style: .default,
title: "Show remaining",
subtitle: nil,
accessoryType: .disclosureIndicator,
target: self,
action: #selector(showRemaining)))
model.add(BasicModelItem(style: .default,
title: "Show all",
subtitle: "",
accessoryType: .disclosureIndicator,
target: self,
action: #selector(showAll)))
addShowRemainingAllItems(model: model, level: Int(user.currentLevel))

model.add(section: "All levels")
for category in SRSStageCategory.apprentice ... SRSStageCategory.burned {
Expand All @@ -230,6 +238,23 @@ class MainViewController: UIViewController, LoginViewControllerDelegate,
updateUserInfo()
}

private func addShowRemainingAllItems(model: MutableTableModel, level: Int) {
model.add(BasicModelItem(style: .default,
title: "Show remaining",
subtitle: nil,
accessoryType: .disclosureIndicator) {
self.selectedSubjectCatalogLevel = level
self.performSegue(withIdentifier: "showRemaining", sender: self)
})
model.add(BasicModelItem(style: .default,
title: "Show all",
subtitle: "",
accessoryType: .disclosureIndicator) {
self.selectedSubjectCatalogLevel = level
self.performSegue(withIdentifier: "showAll", sender: self)
})
}

// MARK: - UIViewController

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -311,12 +336,11 @@ class MainViewController: UIViewController, LoginViewControllerDelegate,

case "showAll":
let vc = segue.destination as! SubjectCatalogueViewController
let level = services.localCachingClient.getUserInfo()!.level
vc.setup(services: services, level: Int(level))
vc.setup(services: services, level: selectedSubjectCatalogLevel)

case "showRemaining":
let vc = segue.destination as! SubjectsRemainingViewController
vc.setup(services: services)
vc.setup(services: services, level: selectedSubjectCatalogLevel)

case "settings":
let vc = segue.destination as! SettingsViewController
Expand Down Expand Up @@ -561,14 +585,6 @@ class MainViewController: UIViewController, LoginViewControllerDelegate,
performSegue(withIdentifier: "startLessons", sender: self)
}

@objc func showRemaining() {
performSegue(withIdentifier: "showRemaining", sender: self)
}

@objc func showAll() {
performSegue(withIdentifier: "showAll", sender: self)
}

@objc func showTableForecast() {
performSegue(withIdentifier: "tableForecast", sender: self)
}
Expand Down
1 change: 1 addition & 0 deletions ios/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,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(true, #keyPath(showPreviousLevelGraph)) static var showPreviousLevelGraph: Bool

@Setting(false, #keyPath(seenFullAnswerPrompt)) static var seenFullAnswerPrompt: Bool

Expand Down
12 changes: 12 additions & 0 deletions ios/SubjectDetailsSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class SubjectDetailsSettingsViewController: UITableViewController, TKMViewContro
on: Settings.showOldMnemonic,
target: self,
action: #selector(showOldMnemonicSwitchChanged(_:))))
let currentLevelGraphItem = SwitchModelItem(style: .subtitle,
title: "Keep current level graph",
subtitle: "Instead of showing the next level's graph when you finish the kanji for a given level, keep showing the same level completion graph until all radicals, kanji, and vocabulary have gotten to Guru or higher",
on: Settings.showPreviousLevelGraph,
target: self,
action: #selector(levelGraphSwitchChanged(_:)))
currentLevelGraphItem.numberOfSubtitleLines = 0
model.add(currentLevelGraphItem)

self.model = model
model.reloadTable()
Expand All @@ -81,4 +89,8 @@ class SubjectDetailsSettingsViewController: UITableViewController, TKMViewContro
@objc private func showAllReadingsSwitchChanged(_ switchView: UISwitch) {
Settings.showAllReadings = switchView.isOn
}

@objc private func levelGraphSwitchChanged(_ switchView: UISwitch) {
Settings.showPreviousLevelGraph = switchView.isOn
}
}
20 changes: 14 additions & 6 deletions ios/SubjectsRemainingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class SubjectsRemainingViewController: UITableViewController, SubjectDelegate,
TKMViewController {
var services: TKMServices!
var model: TableModel?
private var level: Int = 0

func setup(services: TKMServices) {
func setup(services: TKMServices, level: Int) {
self.services = services
self.level = level
}

// MARK: - TKMViewController
Expand All @@ -33,22 +35,20 @@ class SubjectsRemainingViewController: UITableViewController, SubjectDelegate,
override func viewDidLoad() {
super.viewDidLoad()

guard let level = services.localCachingClient.getUserInfo()?.level else {
return
}
navigationItem.title = "Remaining in Level \(level)"

var radicals = [SubjectModelItem]()
var kanji = [SubjectModelItem]()
for assignment in services.localCachingClient.getAssignmentsAtUsersCurrentLevel() {
var vocabulary = [SubjectModelItem]()
for assignment in services.localCachingClient.getAssignments(level: level) {
if assignment.srsStage > .apprentice4 {
continue
}
guard let subject = services.localCachingClient.getSubject(id: assignment.subjectID)
else {
continue
}
if subject.subjectType == .vocabulary {
if !Settings.showPreviousLevelGraph, subject.subjectType == .vocabulary {
continue
}

Expand All @@ -65,6 +65,8 @@ class SubjectsRemainingViewController: UITableViewController, SubjectDelegate,
radicals.append(item)
case .kanji:
kanji.append(item)
case .vocabulary:
vocabulary.append(item)
default:
break
}
Expand All @@ -83,6 +85,12 @@ class SubjectsRemainingViewController: UITableViewController, SubjectDelegate,
model.add(item)
}
}
if !vocabulary.isEmpty {
model.add(section: "Vocabulary")
for item in vocabulary {
model.add(item)
}
}

for section in 0 ..< model.sectionCount {
model.sort(section: section) { (itemA: SubjectModelItem, itemB: SubjectModelItem) -> Bool in
Expand Down

0 comments on commit 680acde

Please sign in to comment.