Skip to content
Permalink
 
 
Cannot retrieve contributors at this time
68 lines (56 sloc) 2.29 KB
//
// PayBillInterfaceController.swift
// SynchronyFinancial
//
// Created by Alan Maynard on 3/13/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import WatchKit
import Foundation
class PayBillInterfaceController: WKInterfaceController {
var acct: Account?
var payDict: [String: Any] = [:]
@IBOutlet weak var balanceLabel: WKInterfaceLabel!
@IBOutlet weak var payBalanceButton: WKInterfaceButton!
@IBOutlet weak var minimumLabel: WKInterfaceLabel!
@IBOutlet weak var payMinimumButton: WKInterfaceButton!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
guard let data = context as? [String: Account] else {
NSLog("Error receiving context containing selected account in AccountDetailInterfaceController")
return
}
acct = data["acct"]
configure()
}
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()
}
override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? {
if segueIdentifier == "PayMinimum" {
payDict.updateValue(Double(acct?.minPayDue ?? 0.0), forKey: "payment_amount")
} else if segueIdentifier == "PayAll" {
payDict.updateValue(Double(acct?.curBalance ?? 0.0), forKey: "payment_amount")
}
return payDict
}
private func configure() {
if let valid = acct {
payDict.updateValue(valid, forKey: "acct")
let balanceFormatted = String(format: "$%.2f", valid.curBalance)
balanceLabel.setText("Balance: \(balanceFormatted)")
payBalanceButton.setTitle("Pay \(balanceFormatted)")
let minimumFormatted = String(format: "$%.2f", valid.minPayDue)
minimumLabel.setText("Minimum Payment:\n\(minimumFormatted)")
payMinimumButton.setTitle("Pay \(minimumFormatted)")
payMinimumButton.setEnabled(valid.minPayDue > 0.0)
payBalanceButton.setEnabled(valid.curBalance > 0.0)
}
}
}
You can’t perform that action at this time.