Skip to content
Permalink
ed03465b66
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
79 lines (66 sloc) 2.73 KB
//
// AccountDetailsInterfaceController.swift
// SynchronyFinancial WatchKit Extension
//
// Created by Alan Maynard on 3/6/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import WatchKit
import Foundation
class AccountDetailsInterfaceController: WKInterfaceController {
var selectedAccount: Account?
var dictForAcct: [String: Account] = [:]
@IBOutlet weak var transactionsButton: WKInterfaceButton!
@IBOutlet weak var payButton: WKInterfaceButton!
@IBOutlet weak var balanceLabel: WKInterfaceLabel!
@IBOutlet weak var availableFundsLabel: WKInterfaceLabel!
@IBOutlet weak var accountNameLabel: WKInterfaceLabel!
@IBOutlet weak var nextPaymentDueLabel: WKInterfaceLabel!
@IBAction func payBillTapped() {
if let acct = selectedAccount {
dictForAcct.updateValue(acct, forKey: "acct")
}
pushController(withName: "PayMinimum", context: dictForAcct)
}
override func awake(withContext context: Any?) {
super.awake(withContext: context)
payButton.setWidth(self.contentFrame.width / 2)
transactionsButton.setWidth(self.contentFrame.width / 2)
guard let data = context as? [String: Account] else {
NSLog("Error receiving context containing selected account in AccountDetailInterfaceController")
return
}
selectedAccount = data["acct"]
configureForAccount()
}
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 == "payBill" {
if let acct = selectedAccount {
dictForAcct.updateValue(acct, forKey: "acct")
return dictForAcct
}
}
return nil
}
private func configureForAccount() {
guard selectedAccount != nil, let acct = selectedAccount else {
NSLog("Error configuring AccountDetails. selectedAccount is nil")
return
}
let balanceFormatted = String(format: "%.2f", acct.balance)
let availableFormatted = String(format: "%.2f", acct.limit - acct.balance)
let date = DateFormatter.localizedString(from: acct.paymentDueDate, dateStyle: .medium, timeStyle: .none)
accountNameLabel.setText(acct.accountNumber)
balanceLabel.setText("Balance: $\(balanceFormatted)")
availableFundsLabel.setText("Available: $\(availableFormatted)")
nextPaymentDueLabel.setText(date)
}
}