Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SWF-17 clean up how we receive data for utilization
- added some validation to ensure we get the value we want
- else, we have changed score to not be optional
- removed unused overridden boilerplate functions
  • Loading branch information
ahm11003 committed Apr 23, 2019
1 parent 17dd1df commit a949599
Showing 1 changed file with 9 additions and 35 deletions.
Expand Up @@ -12,58 +12,32 @@ import Foundation
class UtilizationInterfaceController: WKInterfaceController {
var didAnimate: Bool = false
var util: Double = 0
var score: Int?
var score: Int = 0

@IBOutlet weak var image3: WKInterfaceImage!
override func awake(withContext context: Any?) {
super.awake(withContext: context)

guard let util = context as? Int else {
NSLog("Error getting Utilization metric.")
return
}

// resize according to screen size so we can display button below
image3.setHeight(contentFrame.height / 2)
image3.setWidth(contentFrame.height / 2)
image3.setHorizontalAlignment(.center)
score = context as? Int

// get plist data to generate utilization metric
/*var plistValues = PlistUtil.readPlist(for: .balance)
let balance = plistValues[0][0]
let credit = plistValues[0][1] > 0 ? plistValues[0][1] : 1
util = round((Double(balance)/Double(credit)) * 100)
switch util {
case 0...10:
score = 100
case 11...20:
score = Int(round((100 - util) * 0.9))
case 21...30:
score = Int(round((100 - util) * 0.85))
case 31...60:
score = Int(round((100 - util) * 0.725))
case 61...90:
score = Int(round((100 - util) * 0.6))
default:
score = 1
}*/
score = util
}

override func didAppear() {
if !didAnimate {
image3.setImageNamed("scores")
image3.startAnimatingWithImages(in: NSRange(location: 1, length: score ?? 0), duration: 1.5, repeatCount: 1)
image3.startAnimatingWithImages(in: NSRange(location: 1, length: score), duration: 1.5, repeatCount: 1)
didAnimate = true
}
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

@IBAction func showDetails() {
presentAlert(withTitle: "Utilization Details", message: Defaults.UTIL, preferredStyle: .alert, actions: [WKAlertAction(title: "Done", style: .default, handler: {})])
}
Expand Down

0 comments on commit a949599

Please sign in to comment.