diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard b/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard index 3ceb897..d2f0a7a 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard +++ b/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard @@ -100,7 +100,7 @@ - + @@ -116,9 +116,25 @@ - + + + + + + + + + + + - + diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountDetailsInterfaceController.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountDetailsInterfaceController.swift index 1a51ac6..f0782ea 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountDetailsInterfaceController.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountDetailsInterfaceController.swift @@ -10,11 +10,23 @@ import WatchKit import Foundation class AccountDetailsInterfaceController: WKInterfaceController { + var selectedAccount: Account? + + @IBOutlet weak var balanceLabel: WKInterfaceLabel! + @IBOutlet weak var availableFundsLabel: WKInterfaceLabel! + @IBOutlet weak var accountNameLabel: WKInterfaceLabel! + @IBOutlet weak var nextPaymentDueLabel: WKInterfaceLabel! 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 + } + + selectedAccount = data["acct"] + configureForAccount() } override func willActivate() { @@ -27,4 +39,16 @@ class AccountDetailsInterfaceController: WKInterfaceController { super.didDeactivate() } + private func configureForAccount() { + guard selectedAccount != nil, let acct = selectedAccount else { + NSLog("Error configuring AccountDetails. selectedAccount is nil") + return + } + + accountNameLabel.setText(acct.accountNumber) + balanceLabel.setText("Balance: $\(acct.balance)") + availableFundsLabel.setText("Available: $\(acct.limit - acct.balance)") + let date = DateFormatter.localizedString(from: acct.paymentDueDate, dateStyle: .medium, timeStyle: .none) + nextPaymentDueLabel.setText(date) + } } diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift index 563adab..b3ac09d 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift @@ -31,15 +31,11 @@ class AccountTableInterfaceController: WKInterfaceController { super.didDeactivate() } - override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) { - acctDict["acct"] = accounts[rowIndex] - } - - override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? { + override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? { if segueIdentifier == "showAccountDetails" { + acctDict.updateValue(accounts[rowIndex], forKey: "acct") return acctDict } - return nil }