Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PList Functions
- change plist structure to array for easier reading from plist
- populate radial indicators with values
- set up check to only animate once
  • Loading branch information
ahm11003 committed Mar 6, 2019
1 parent 5d7cb80 commit 10e6442
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 47 deletions.
@@ -1,24 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Account1</key>
<array>
<array>
<integer>2000</integer>
<integer>8000</integer>
<integer>2</integer>
</array>
<key>Account2</key>
<array>
<integer>1300</integer>
<real>5000</real>
<integer>5</integer>
</array>
<key>Account 3</key>
<array>
<integer>4000</integer>
<integer>10000</integer>
<integer>3</integer>
</array>
</dict>
</array>
</plist>
Expand Up @@ -11,20 +11,27 @@ import Foundation


class BalanceInterfaceController: WKInterfaceController {
var util: Int?
var didAnimate: Bool = false

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

// get plist data to generate balance metric
var plistValues = PlistUtil.readPlist(for: .balance)
let balance = plistValues[0][0]
let credit = plistValues[0][1] > 0 ? plistValues[0][1] : 1

util = Int(round((Double(balance)/Double(credit)) * 100))
}

override func didAppear() {
// Called when watch interface is visible to user
/*var plistValues = [String]()
plistValues = PlistUtil.readPlist(namePlist: "PropertyList", key: "Account1")
let balance: Int = Int(plistValues[0])!
let credit: Int = Int(plistValues[1])!
let util = (balance/credit * 10)*/
image2.setImageNamed("scores")
image2.startAnimatingWithImages(in: NSRange(location: 0, length: 66), duration: 1.5, repeatCount: 1)
if !didAnimate {
image2.startAnimatingWithImages(in: NSRange(location: 0, length: util ?? 0), duration: 1.5, repeatCount: 1)
didAnimate = true
}
//image2.stopAnimating()
}

Expand Down
Expand Up @@ -8,36 +8,27 @@
import Foundation

public enum PlistDataType: String {
case balance = "BalanceInfo"
case transaction = "Transcation"
case account = "Account"
}

class PlistUtil {

static func readPlist(namePlist: String, key: String) -> [String]{
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) as NSArray
let documentsDirectory = paths.object(at: 0) as! NSString
let path = documentsDirectory.appendingPathComponent(namePlist+".plist")

var output:AnyObject = false as AnyObject

if let dict = NSMutableDictionary(contentsOfFile: path){
output = dict.object(forKey: key)! as AnyObject
}else{
if let privPath = Bundle.main.path(forResource: namePlist, ofType: "plist"){
if let dict = NSMutableDictionary(contentsOfFile: privPath){
output = dict.object(forKey: key)! as AnyObject
}else{
output = false as AnyObject
print("error_read")
}
}else{
output = false as AnyObject
print("error_read")
static func readPlist(for data: PlistDataType) -> [[Int]] {
var balances = [[Int]]()
if let file = Bundle.main.path(forResource: data.rawValue, ofType: "plist"),
let array = NSArray.init(contentsOfFile: file) {
array.forEach {
guard let balance = $0 as? [AnyHashable],
let b = balance[0] as? Int,
let credit = balance[1] as? Int,
let age = balance[2] as? Int else { return }
balances.append([b, credit, age])
}
}
print("plist_read \(output)")
return output as! [String]

return balances
}


}

/*Borrowed from
https://github.com/soonin/IOS-Swift-PlistReadAndWrite/blob/master/IOS-Swift-PlistReadAndWrite/PlistReadAndWrite.swift */
Expand Up @@ -9,18 +9,29 @@
import WatchKit
import Foundation


class UtilizationInterfaceController: WKInterfaceController {
var didAnimate: Bool = false
var util: Int?

@IBOutlet weak var image3: WKInterfaceImage!

override func awake(withContext context: Any?) {
super.awake(withContext: context)

// 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 = Int(round((Double(balance)/Double(credit)) * 100))
}

override func didAppear() {
// Called when watch interface is visible to user
image3.setImageNamed("scores")
image3.startAnimatingWithImages(in: NSRange(location: 0, length: 46), duration: 1.5, repeatCount: 1)
if !didAnimate {
image3.setImageNamed("scores")
image3.startAnimatingWithImages(in: NSRange(location: 1, length: util ?? 0), duration: 1.5, repeatCount: 1)
didAnimate = true
}
}

override func willActivate() {
Expand Down
Expand Up @@ -26,7 +26,7 @@
67C8DD8321ED323B0063A01B /* CircleIndicator.sks in Resources */ = {isa = PBXBuildFile; fileRef = 67C8DD8221ED323B0063A01B /* CircleIndicator.sks */; };
67C8DD8521ED3B5A0063A01B /* WellnessInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67C8DD8421ED3B5A0063A01B /* WellnessInterfaceController.swift */; };
9BCE39732227138E00B7A992 /* BalanceInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BCE39722227138E00B7A992 /* BalanceInterfaceController.swift */; };
9BCE39752227712500B7A992 /* Property List.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9BCE39742227712500B7A992 /* Property List.plist */; };
9BCE39752227712500B7A992 /* BalanceInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9BCE39742227712500B7A992 /* BalanceInfo.plist */; };
9BCE39772227731800B7A992 /* UtilizationfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BCE39762227731800B7A992 /* UtilizationfaceController.swift */; };
9BCE39792227839B00B7A992 /* AccountNumberInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BCE39782227839B00B7A992 /* AccountNumberInterfaceController.swift */; };
9BCE397D222F5A2800B7A992 /* PlistUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BCE397C222F5A2800B7A992 /* PlistUtil.swift */; };
Expand Down Expand Up @@ -99,7 +99,7 @@
67C8DD8221ED323B0063A01B /* CircleIndicator.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = CircleIndicator.sks; sourceTree = "<group>"; };
67C8DD8421ED3B5A0063A01B /* WellnessInterfaceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WellnessInterfaceController.swift; sourceTree = "<group>"; };
9BCE39722227138E00B7A992 /* BalanceInterfaceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BalanceInterfaceController.swift; sourceTree = "<group>"; };
9BCE39742227712500B7A992 /* Property List.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Property List.plist"; sourceTree = "<group>"; };
9BCE39742227712500B7A992 /* BalanceInfo.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = BalanceInfo.plist; sourceTree = "<group>"; };
9BCE39762227731800B7A992 /* UtilizationfaceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilizationfaceController.swift; sourceTree = "<group>"; };
9BCE39782227839B00B7A992 /* AccountNumberInterfaceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountNumberInterfaceController.swift; sourceTree = "<group>"; };
9BCE397C222F5A2800B7A992 /* PlistUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlistUtil.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -192,7 +192,7 @@
9BCE397C222F5A2800B7A992 /* PlistUtil.swift */,
67BAC291219E254900713FEF /* Assets.xcassets */,
67BAC293219E254900713FEF /* Info.plist */,
9BCE39742227712500B7A992 /* Property List.plist */,
9BCE39742227712500B7A992 /* BalanceInfo.plist */,
);
path = "SynchronyFinancial WatchKit Extension";
sourceTree = "<group>";
Expand Down Expand Up @@ -335,7 +335,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9BCE39752227712500B7A992 /* Property List.plist in Resources */,
9BCE39752227712500B7A992 /* BalanceInfo.plist in Resources */,
67BAC292219E254900713FEF /* Assets.xcassets in Resources */,
67C8DD8321ED323B0063A01B /* CircleIndicator.sks in Resources */,
);
Expand Down

0 comments on commit 10e6442

Please sign in to comment.