Skip to content

Commit 2506b6c

Browse files
- Re-added shuffle
- Fixed cached images loading
1 parent 941fb4a commit 2506b6c

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

Questions/AppDelegate.swift

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3636
navController?.navigationBar.prefersLargeTitles = true
3737
}
3838

39-
if #available(iOS 9.0, *) {
40-
41-
let readQRCode = UIMutableApplicationShortcutItem(type: ShortcutItemType.QRCode.rawValue,
42-
localizedTitle: "Scan QR Code".localized,
43-
localizedSubtitle: nil,
44-
icon: UIApplicationShortcutIcon(templateImageName: "QRCodeIcon"))
45-
46-
let darkTheme = UIMutableApplicationShortcutItem(type: ShortcutItemType.DarkTheme.rawValue,
47-
localizedTitle: "Dark Theme".localized,
48-
localizedSubtitle: nil,
49-
icon: UIApplicationShortcutIcon(templateImageName: "DarkThemeIcon"))
50-
51-
let lightTheme = UIMutableApplicationShortcutItem(type: ShortcutItemType.LightTheme.rawValue,
52-
localizedTitle: "Light Theme".localized,
53-
localizedSubtitle: nil,
54-
icon: UIApplicationShortcutIcon(templateImageName: "LightThemeIcon"))
55-
56-
application.shortcutItems = [readQRCode, darkTheme, lightTheme]
57-
}
39+
let readQRCode = UIMutableApplicationShortcutItem(type: ShortcutItemType.QRCode.rawValue,
40+
localizedTitle: "Scan QR Code".localized,
41+
localizedSubtitle: nil,
42+
icon: UIApplicationShortcutIcon(templateImageName: "QRCodeIcon"))
43+
44+
let darkTheme = UIMutableApplicationShortcutItem(type: ShortcutItemType.DarkTheme.rawValue,
45+
localizedTitle: "Dark Theme".localized,
46+
localizedSubtitle: nil,
47+
icon: UIApplicationShortcutIcon(templateImageName: "DarkThemeIcon"))
48+
49+
let lightTheme = UIMutableApplicationShortcutItem(type: ShortcutItemType.LightTheme.rawValue,
50+
localizedTitle: "Light Theme".localized,
51+
localizedSubtitle: nil,
52+
icon: UIApplicationShortcutIcon(templateImageName: "LightThemeIcon"))
53+
54+
application.shortcutItems = [readQRCode, darkTheme, lightTheme]
5855

5956
AppDelegate.updateVolumeBarTheme()
6057
VolumeBar.shared.start()

Questions/QuestionType.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ extension QuestionType: Equatable {
3030
return lhs.question == rhs.question && lhs.answers == rhs.answers && lhs.correctAnswers == rhs.correctAnswers
3131
}
3232
}
33+
34+
extension QuestionType: Hashable {
35+
var hashValue: Int {
36+
return question.hash
37+
}
38+
}

Questions/QuestionsViewController.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ class QuestionsViewController: UIViewController {
5959
if self.isSetFromJSON {
6060
self.goBack.isHidden = true
6161
}
62-
self.setUpQuiz()
6362

64-
DispatchQueue.global().async {
65-
self.preloadImages()
66-
}
63+
self.setUpQuiz()
64+
self.preloadImages()
6765

6866
self.createAnswerButtons()
6967

@@ -137,6 +135,9 @@ class QuestionsViewController: UIViewController {
137135
}
138136
})
139137
}
138+
else {
139+
// TODO: complete!
140+
}
140141
}
141142
}
142143

@@ -363,9 +364,7 @@ class QuestionsViewController: UIViewController {
363364

364365
for fullQuestion in self.set.dropFirst() { // Drops the first because it will be cached by the 'pickQuestion()' function
365366

366-
guard let validImageURL = fullQuestion.imageURL else { break }
367-
368-
print(validImageURL)
367+
guard let validImageURL = fullQuestion.imageURL else { continue }
369368

370369
CachedImages.shared.saveImage(withURL: validImageURL, onError: { cachedImagesError in
371370
switch cachedImagesError {
@@ -465,7 +464,6 @@ class QuestionsViewController: UIViewController {
465464
}
466465
}
467466

468-
private var currentURL: URL? = nil
469467
public func pickQuestion() {
470468

471469
if self.currentQuizOfTopic.options?.multipleCorrectAnswersAsMandatory ?? false {
@@ -615,7 +613,7 @@ class QuestionsViewController: UIViewController {
615613
if !self.isSetFromJSON { self.set = SetOfTopics.shared.currentTopics[currentTopicIndex].quiz.sets[currentSetIndex] }
616614

617615
if self.currentQuizOfTopic.options?.questionsInRandomOrder ?? true {
618-
//self.set.shuffle()
616+
self.set.shuffle()
619617
}
620618
self.quiz = self.set.enumerated().makeIterator()
621619
}

0 commit comments

Comments
 (0)