Skip to content

Instantly share code, notes, and snippets.

@dennda
Created April 16, 2018 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennda/5236af753d21a349a3e39e7d1326eca5 to your computer and use it in GitHub Desktop.
Save dennda/5236af753d21a349a3e39e7d1326eca5 to your computer and use it in GitHub Desktop.
diff --git a/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/DUOSkill.swift b/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/DUOSkill.swift
index f8d3c1fa6..e047ffdad 100644
--- a/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/DUOSkill.swift
+++ b/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/DUOSkill.swift
@@ -8,139 +8,140 @@
import Foundation
-final class DUOSkill: NSObject, DUOCoding {
-
- /// Present and true iff user can open this skill.
- let isAccessible: Bool
-
- /// Present and true iff this is a bonus skill.
- let isBonusSkill: Bool
-
- /// Tips and notes.
- let explanation: String?
-
- /// Number of lessons completed by the user.
- let finishedLessons: Int
-
- /// Number of levels completed by the user.
- let finishedLevels: Int
-
- /// From language.
- let fromLanguage: Language
-
- /// Icon ID. The icon's image and color are bundled with the client.
- let iconId: Int
-
- /// Skill ID.
- let id: String
-
- /// Learning language.
- let learningLanguage: Language
-
- /// Array of words taught per lesson.
- let lessonWords: [String]
-
- /// Number of lessons in this skill.
- let lessons: Int
-
- /// Number of levels in this skill.
- let levels: Int
-
- /// Skill name as shown on the skill page.
- let name: String
-
- /// Skill name as shown in the skill tree.
- let shortName: String
-
- /// Skill strength as a float.
- let strength: Double
-
- /// Skill name as shown in web's skill page URL.
- let urlName: String?
-
- /// Weakest words.
- let weakWords: [String]
-
- init(isAccessible: Bool,
- isBonusSkill: Bool,
- explanation: String?,
- finishedLessons: Int,
- finishedLevels: Int,
- fromLanguage: Language,
- iconId: Int,
- id: String,
- learningLanguage: Language,
- lessonWords: [String],
- lessons: Int,
- levels: Int,
- name: String,
- shortName: String,
- strength: Double,
- urlName: String?,
- weakWords: [String]) {
- self.isAccessible = isAccessible
- self.isBonusSkill = isBonusSkill
- self.explanation = explanation
- self.finishedLessons = finishedLessons
- self.finishedLevels = finishedLevels
- self.fromLanguage = fromLanguage
- self.iconId = iconId
- self.id = id
- self.learningLanguage = learningLanguage
- self.lessonWords = lessonWords
- self.lessons = lessons
- self.levels = levels
- self.name = name
- self.shortName = shortName
- self.strength = strength
- self.urlName = urlName
- self.weakWords = weakWords
- }
-
- func encode(with aCoder: NSCoder) {
- duoEncoded().forEach { key, value in
- aCoder.encode(value, forKey: key)
- }
- }
-
- convenience init?(coder aDecoder: NSCoder) {
- self.init(subscriptable: aDecoder)
- }
-
- convenience init?<T: Subscriptable>(subscriptable sub: T) where T.Key == String, T.Value == NSObject {
- guard
- let accessible = sub["accessible"] as? Bool,
- let bonus = sub["bonus"] as? Bool,
- let iconId = sub["iconId"] as? Int,
- let id = sub["id"] as? String,
- let fromLanguageID = sub["fromLanguage"] as? String,
- let learningLanguageID = sub["learningLanguage"] as? String,
- let lessonWords = sub["lessonWords"] as? [String],
- let lessons = sub["lessons"] as? Int,
- let name = sub["name"] as? String,
- let shortName = sub["shortName"] as? String,
- let weakWords = sub["weakWords"] as? [String]
- else {
- return nil
- }
-
- self.init(isAccessible: accessible,
- isBonusSkill: bonus,
- explanation: sub["explanation"] as? String,
- finishedLessons: (sub["finishedLessons"] as? Int) ?? 0,
- finishedLevels: (sub["finishedLevels"] as? Int) ?? 0,
- fromLanguage: Language(id: fromLanguageID),
- iconId: iconId,
- id: id,
- learningLanguage: Language(id: learningLanguageID),
- lessonWords: lessonWords,
- lessons: lessons,
- levels: (sub["levels"] as? Int) ?? 0,
- name: name,
- shortName: shortName,
- strength: (sub["strength"] as? Double) ?? 0,
- urlName: sub["urlName"] as? String,
- weakWords: weakWords)
- }
+//final class DUOSkill: NSObject, DUOCoding {
+//
+// /// Present and true iff user can open this skill.
+// let isAccessible: Bool
+//
+// /// Present and true iff this is a bonus skill.
+// let isBonusSkill: Bool
+//
+// /// Tips and notes.
+//// let explanation: String?
+//
+// /// Number of lessons completed by the user.
+// let finishedLessons: Int
+//
+// /// Number of levels completed by the user.
+// let finishedLevels: Int
+//
+// /// From language.
+// let fromLanguage: Language
+//
+// /// Icon ID. The icon's image and color are bundled with the client.
+// let iconId: Int
+//
+// /// Skill ID.
+// let id: String
+//
+// /// Learning language.
+// let learningLanguage: Language
+//
+// /// Array of words taught per lesson.
+// let lessonWords: [String]
+//
+// /// Number of lessons in this skill.
+// let lessons: Int
+//
+// /// Number of levels in this skill.
+// let levels: Int
+//
+// /// Skill name as shown on the skill page.
+// let name: String
+//
+// /// Skill name as shown in the skill tree.
+// let shortName: String
+//
+// /// Skill strength as a float.
+// let strength: Double
+//
+// /// Skill name as shown in web's skill page URL.
+// let urlName: String?
+//
+// /// Weakest words.
+// let weakWords: [String]
+//
+// init(isAccessible: Bool,
+// isBonusSkill: Bool,
+// explanation: String?,
+// finishedLessons: Int,
+// finishedLevels: Int,
+// fromLanguage: Language,
+// iconId: Int,
+// id: String,
+// learningLanguage: Language,
+// lessonWords: [String],
+// lessons: Int,
+// levels: Int,
+// name: String,
+// shortName: String,
+// strength: Double,
+// urlName: String?,
+// weakWords: [String]) {
+// self.isAccessible = isAccessible
+// self.isBonusSkill = isBonusSkill
+//// self.explanation = explanation
+// self.finishedLessons = finishedLessons
+// self.finishedLevels = finishedLevels
+// self.fromLanguage = fromLanguage
+// self.iconId = iconId
+// self.id = id
+// self.learningLanguage = learningLanguage
+// self.lessonWords = lessonWords
+// self.lessons = lessons
+// self.levels = levels
+// self.name = name
+// self.shortName = shortName
+// self.strength = strength
+// self.urlName = urlName
+// self.weakWords = weakWords
+// }
+//
+// func encode(with aCoder: NSCoder) {
+// duoEncoded().forEach { key, value in
+// aCoder.encode(value, forKey: key)
+// }
+// }
+//
+// convenience init?(coder aDecoder: NSCoder) {
+// self.init(subscriptable: aDecoder)
+// }
+//
+// convenience init?<T: Subscriptable>(subscriptable sub: T) where T.Key == String, T.Value == NSObject {
+// guard
+// let accessible = sub["accessible"] as? Bool,
+// let bonus = sub["bonus"] as? Bool,
+// let iconId = sub["iconId"] as? Int,
+// let id = sub["id"] as? String,
+// let fromLanguageID = sub["fromLanguage"] as? String,
+// let learningLanguageID = sub["learningLanguage"] as? String,
+// let lessonWords = sub["lessonWords"] as? [String],
+// let lessons = sub["lessons"] as? Int,
+// let name = sub["name"] as? String,
+// let shortName = sub["shortName"] as? String,
+// let weakWords = sub["weakWords"] as? [String]
+// else {
+// return nil
+// }
+//
+// self.init(isAccessible: accessible,
+// isBonusSkill: bonus,
+// explanation: sub["explanation"] as? String,
+// finishedLessons: (sub["finishedLessons"] as? Int) ?? 0,
+// finishedLevels: (sub["finishedLevels"] as? Int) ?? 0,
+// fromLanguage: Language(id: fromLanguageID),
+// iconId: iconId,
+// id: id,
+// learningLanguage: Language(id: learningLanguageID),
+// lessonWords: lessonWords,
+// lessons: lessons,
+// levels: (sub["levels"] as? Int) ?? 0,
+// name: name,
+// shortName: shortName,
+// strength: (sub["strength"] as? Double) ?? 0,
+// urlName: sub["urlName"] as? String,
+// weakWords: weakWords)
+// }
+//
+//}
-}
diff --git a/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/Extensions/DUOSkill+Extensions.swift b/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/Extensions/DUOSkill+Extensions.swift
index 36a2e631e..37f0cd814 100644
--- a/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/Extensions/DUOSkill+Extensions.swift
+++ b/DuolingoMobile/Sources/Library/Networking/NetworkClient/Models/Extensions/DUOSkill+Extensions.swift
@@ -8,29 +8,75 @@
import Foundation
-extension DUOSkill {
-
- /// The color to use for the skill when it is locked.
- static var lockedColor: UIColor {
- return UIColor.duolingoNewVeryLightGray()
- }
-
- /// The color to use for the skill when it is at full strength, i.e. gold.
- static var goldColor: UIColor {
- return UIColor.duolingoNewGold()
- }
+//extension DUOSkill {
+//
+// /// The color to use for the skill when it is locked.
+// static var lockedColor: UIColor {
+// return UIColor.duolingoNewVeryLightGray()
+// }
+//
+// /// The color to use for the skill when it is at full strength, i.e. gold.
+// static var goldColor: UIColor {
+// return UIColor.duolingoNewGold()
+// }
+//
+// /// The color to use for the skill when it is unlocked, but not gilded.
+// static func unlockedColor(iconID: Int) -> UIColor {
+// let graphics = DUOGraphicsManager.instance()
+// guard
+// let colorType = graphics?.colorType(forIconID: iconID),
+// let color = graphics?.color(for: colorType)
+// else {
+// return UIColor.duolingoRed()
+// }
+//
+// return color
+// }
+//
+// /// The strength that a skill has to be above in order for it to be considered gold.
+// @objc static var goldStrength: Double {
+// return 0.75
+// }
+//
+// /// Whether the skill's strength is high enough to be considered full strength.
+// @objc static func isFullStrength(_ strength: Double) -> Bool {
+// if StrengthBarExperiment.condition.isControl {
+// return strength > goldStrength
+// } else {
+// return strength >= goldStrength
+// }
+// }
+//
+// /// Whether or not the skill should be considered gold.
+// var isGilded: Bool {
+// return finishedLessons >= lessons && DUOSkill.isFullStrength(strength)
+// }
+//
+// /// The current color for this skill, based on the current status.
+// var iconColor: UIColor {
+// if !self.isAccessible {
+// return DUOSkill.lockedColor
+// } else if isGilded {
+// return DUOSkill.goldColor
+// } else {
+// return DUOSkill.unlockedColor(iconID: iconId)
+// }
+// }
+//
+// /// Returns a newly-loaded image for this icon.
+// func loadIconImage() -> PDFImage {
+// return DUOGraphicsManager.instance().icon(forIconIndex: iconId,
+// locked: !isAccessible,
+// fullStrength: isGilded)
+// }
+//
+//}
- /// The color to use for the skill when it is unlocked, but not gilded.
- static func unlockedColor(iconID: Int) -> UIColor {
- let graphics = DUOGraphicsManager.instance()
- guard
- let colorType = graphics?.colorType(forIconID: iconID),
- let color = graphics?.color(for: colorType)
- else {
- return UIColor.duolingoRed()
- }
+extension DUOSkillSummary {
- return color
+ /// Whether or not the user has completed the skill.
+ var isCompleted: Bool {
+ return finishedLessons >= lessons
}
/// The strength that a skill has to be above in order for it to be considered gold.
@@ -47,51 +93,42 @@ extension DUOSkill {
}
}
- /// Whether or not the skill should be considered gold.
- var isGilded: Bool {
- return finishedLessons >= lessons && DUOSkill.isFullStrength(strength)
- }
-
- /// The current color for this skill, based on the current status.
- var iconColor: UIColor {
- if !self.isAccessible {
- return DUOSkill.lockedColor
- } else if isGilded {
- return DUOSkill.goldColor
- } else {
- return DUOSkill.unlockedColor(iconID: iconId)
- }
+ /// The color to use for the skill when it is locked.
+ private static var lockedColor: UIColor {
+ return UIColor.duolingoNewVeryLightGray()
}
- /// Returns a newly-loaded image for this icon.
- func loadIconImage() -> PDFImage {
- return DUOGraphicsManager.instance().icon(forIconIndex: iconId,
- locked: !isAccessible,
- fullStrength: isGilded)
+ /// The color to use for the skill when it is at full strength, i.e. gold.
+ private static var goldColor: UIColor {
+ return UIColor.duolingoNewGold()
}
-}
-
-extension DUOSkillSummary {
+ /// The color to use for the skill when it is unlocked, but not gilded.
+ private static func unlockedColor(iconID: Int) -> UIColor {
+ let graphics = DUOGraphicsManager.instance()
+ guard
+ let colorType = graphics?.colorType(forIconID: iconID),
+ let color = graphics?.color(for: colorType)
+ else {
+ return UIColor.duolingoRed()
+ }
- /// Whether or not the user has completed the skill.
- var isCompleted: Bool {
- return finishedLessons >= lessons
+ return color
}
/// Whether or not the skill should be considered gold.
var isGilded: Bool {
- return isCompleted && DUOSkill.isFullStrength(strength)
+ return isCompleted && DUOSkillSummary.isFullStrength(strength)
}
/// The current color for this skill, based on the current status.
var iconColor: UIColor {
if !self.isAccessible {
- return DUOSkill.lockedColor
+ return DUOSkillSummary.lockedColor
} else if isGilded {
- return DUOSkill.goldColor
+ return DUOSkillSummary.goldColor
} else {
- return DUOSkill.unlockedColor(iconID: iconId)
+ return DUOSkillSummary.unlockedColor(iconID: iconId)
}
}
diff --git a/DuolingoMobile/Sources/Library/Networking/NetworkClient/Serializers/DUOSkillSerializer.swift b/DuolingoMobile/Sources/Library/Networking/NetworkClient/Serializers/DUOSkillSerializer.swift
index 54ca65dbb..da5aaeb8f 100644
--- a/DuolingoMobile/Sources/Library/Networking/NetworkClient/Serializers/DUOSkillSerializer.swift
+++ b/DuolingoMobile/Sources/Library/Networking/NetworkClient/Serializers/DUOSkillSerializer.swift
@@ -8,32 +8,33 @@
import Foundation
-extension DUOSkill {
- func duoEncoded() -> [String: NSObject] {
- return DUOSkillSerializer.jsonFromSkill(self)
- }
-}
+//extension DUOSkill {
+// func duoEncoded() -> [String: NSObject] {
+// return DUOSkillSerializer.jsonFromSkill(self)
+// }
+//}
+//
+//class DUOSkillSerializer: NSObject {
+// class func jsonFromSkill(_ skill: DUOSkill) -> JSONObject {
+// var json = JSONObject()
+// json["accessible"] = skill.isAccessible as NSNumber
+// json["bonus"] = skill.isBonusSkill as NSNumber
+//// json["explanation"] = skill.explanation as NSString?
+// json["finishedLessons"] = skill.finishedLessons as NSNumber
+// json["finishedLevels"] = skill.finishedLevels as NSNumber
+// json["fromLanguage"] = skill.fromLanguage.id as NSString
+// json["iconId"] = skill.iconId as NSNumber
+// json["id"] = skill.id as NSString
+// json["learningLanguage"] = skill.learningLanguage.id as NSString
+// json["lessonWords"] = skill.lessonWords as NSArray
+// json["lessons"] = skill.lessons as NSNumber
+// json["levels"] = skill.levels as NSNumber
+// json["name"] = skill.name as NSString?
+// json["shortName"] = skill.shortName as NSString
+// json["strength"] = skill.strength as NSNumber
+// json["urlName"] = skill.urlName as NSString?
+// json["weakWords"] = skill.weakWords as NSArray
+// return json
+// }
+//}
-class DUOSkillSerializer: NSObject {
- class func jsonFromSkill(_ skill: DUOSkill) -> JSONObject {
- var json = JSONObject()
- json["accessible"] = skill.isAccessible as NSNumber
- json["bonus"] = skill.isBonusSkill as NSNumber
- json["explanation"] = skill.explanation as NSString?
- json["finishedLessons"] = skill.finishedLessons as NSNumber
- json["finishedLevels"] = skill.finishedLevels as NSNumber
- json["fromLanguage"] = skill.fromLanguage.id as NSString
- json["iconId"] = skill.iconId as NSNumber
- json["id"] = skill.id as NSString
- json["learningLanguage"] = skill.learningLanguage.id as NSString
- json["lessonWords"] = skill.lessonWords as NSArray
- json["lessons"] = skill.lessons as NSNumber
- json["levels"] = skill.levels as NSNumber
- json["name"] = skill.name as NSString?
- json["shortName"] = skill.shortName as NSString
- json["strength"] = skill.strength as NSNumber
- json["urlName"] = skill.urlName as NSString?
- json["weakWords"] = skill.weakWords as NSArray
- return json
- }
-}
diff --git a/DuolingoMobile/Sources/Library/UI/Views/StrengthBarView.swift b/DuolingoMobile/Sources/Library/UI/Views/StrengthBarView.swift
index 244862bc4..bc4cf80d1 100644
--- a/DuolingoMobile/Sources/Library/UI/Views/StrengthBarView.swift
+++ b/DuolingoMobile/Sources/Library/UI/Views/StrengthBarView.swift
@@ -456,10 +456,10 @@ private struct ContinuousStrengthBar: StrengthBarDrawable {
func percentFilled(strength: Double) -> Double {
if strength <= 0 {
return 0
- } else if strength > DUOSkill.goldStrength {
+ } else if strength > DUOSkillSummary.goldStrength {
return 1
} else {
- return strength / DUOSkill.goldStrength
+ return strength / DUOSkillSummary.goldStrength
}
}
diff --git a/DuolingoMobile/Sources/Sessions/Controllers/Session End/DUOSessionCompleteController.m b/DuolingoMobile/Sources/Sessions/Controllers/Session End/DUOSessionCompleteController.m
index e478415f9..d89e3eef0 100644
--- a/DuolingoMobile/Sources/Sessions/Controllers/Session End/DUOSessionCompleteController.m
+++ b/DuolingoMobile/Sources/Sessions/Controllers/Session End/DUOSessionCompleteController.m
@@ -700,7 +700,7 @@ - (void)populateAwardViewControllers
UIViewController<DUOFlowAnimatable> *awardVC;
if (DUOStrengthBarExperiment.condition.useNewStrengthenedSkillVC) {
- double goldStrength = DUOSkill.goldStrength;
+ double goldStrength = DUOSkillSummary.goldStrength;
double emptyStrength = goldStrength * 0.1;
NSInteger maxSkills = 3;
NSInteger numberOfSkills = MIN(maxSkills, self.model.learnedSkills.count);
diff --git a/DuolingoMobile/Sources/Sessions/Controllers/Session End/StrengthenedSkillAwardVC.swift b/DuolingoMobile/Sources/Sessions/Controllers/Session End/StrengthenedSkillAwardVC.swift
index 127654c37..4e0a2a441 100644
--- a/DuolingoMobile/Sources/Sessions/Controllers/Session End/StrengthenedSkillAwardVC.swift
+++ b/DuolingoMobile/Sources/Sessions/Controllers/Session End/StrengthenedSkillAwardVC.swift
@@ -198,7 +198,7 @@ private func modifyIncreaseForAnimation(_ increase: SkillIncreaseModel) -> Skill
var before = Double(increase.strengthBefore)
var after = Double(increase.strengthAfter)
- let goldStrength = DUOSkill.goldStrength
+ let goldStrength = DUOSkillSummary.goldStrength
var beforePercent = before / goldStrength
var afterPercent = after / goldStrength
diff --git a/DuolingoMobile/Sources/Skills/Skill Tree/Views/DUOSkillTreeItem.m b/DuolingoMobile/Sources/Skills/Skill Tree/Views/DUOSkillTreeItem.m
index 80477019b..96df93d0b 100644
--- a/DuolingoMobile/Sources/Skills/Skill Tree/Views/DUOSkillTreeItem.m
+++ b/DuolingoMobile/Sources/Skills/Skill Tree/Views/DUOSkillTreeItem.m
@@ -162,7 +162,7 @@ - (void)setItemModel:(DUOSkillTreeItemModel *)itemModel
self.badgeView.hidden = (itemModel.skill.missingLessons == 0 || itemModel.skill.isLocked)
|| !DUOStrengthBarExperiment.condition.showsNotification;
- BOOL fullStrength = itemModel.skill.isLearned && [DUOSkill isFullStrength:itemModel.skill.strength];
+ BOOL fullStrength = itemModel.skill.isLearned && [DUOSkillSummary isFullStrength:itemModel.skill.strength];
if (![previousItemModel.skill.name isEqualToString:itemModel.skill.name] || self.skillWasLocked != itemModel.skill.isLocked || self.skillWasLearned != itemModel.skill.isLearned || self.skillWasFullStrength != fullStrength) {
NSInteger requestedIndex = itemModel.skill.iconIndex;
diff --git a/DuolingoMobile/Sources/Skills/Skill View/Controllers/DUOSkillViewController.m b/DuolingoMobile/Sources/Skills/Skill View/Controllers/DUOSkillViewController.m
index 9ff26f557..d2c824721 100644
--- a/DuolingoMobile/Sources/Skills/Skill View/Controllers/DUOSkillViewController.m
+++ b/DuolingoMobile/Sources/Skills/Skill View/Controllers/DUOSkillViewController.m
@@ -498,7 +498,7 @@ - (void)updateStrength
finishedWithLessons = finishedWithLessons && pathItemComplete;
}
- BOOL fullStrength = finishedWithLessons && [DUOSkill isFullStrength:self.skill.strength];
+ BOOL fullStrength = finishedWithLessons && [DUOSkillSummary isFullStrength:self.skill.strength];
self.icon.image = [[DUOGraphicsManager instance] iconForIconIndex:self.skill.iconIndex locked:self.skill.isLocked fullStrength:fullStrength];
self.skillColor = [[DUOGraphicsManager instance] paletteColorForIconColorType:self.skill.iconColorType locked:self.skill.isLocked fullStrength:fullStrength shiny:fullStrength];
self.backgroundShape.image = [[DUOGraphicsManager instance] ellipseForIconColorType:self.skill.iconColorType locked:self.skill.isLocked fullStrength:fullStrength shiny:fullStrength];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment