From a949599b37065766d4d8bddc7efd3eb5facb2f29 Mon Sep 17 00:00:00 2001 From: Alan Maynard Date: Tue, 23 Apr 2019 19:24:39 -0400 Subject: [PATCH] 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 --- .../UtilizationfaceController.swift | 44 ++++--------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/UtilizationfaceController.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/UtilizationfaceController.swift index 1347ff1..2a11108 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/UtilizationfaceController.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/UtilizationfaceController.swift @@ -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: {})]) }