Skip to content
Permalink
00d3583f8e
Go to file
 
 
Cannot retrieve contributors at this time
113 lines (97 sloc) 4.15 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] = [:]
var transactionDict: [String: [Transaction]] = [:]
@IBOutlet var loadingLabel: WKInterfaceLabel!
@IBOutlet var activityIndicator: WKInterfaceImage!
@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 var nextPaymentTitleLabel: WKInterfaceLabel!
@IBOutlet weak var nextPaymentDueLabel: WKInterfaceLabel!
@IBAction func payBillTapped() {
if let acct = selectedAccount {
dictForAcct.updateValue(acct, forKey: "acct")
}
pushController(withName: "PayMinimum", context: dictForAcct)
}
@IBAction func recentButtonTapped() {
configureInterfaceObjects(true)
activityIndicator.configureForActivityIndicator()
if let alias = selectedAccount?.accountAlias {
FetchData.fetchTransactionsFor(accountAlias: alias) { transactions, error in
guard error == nil else {
NSLog("Error retrieving transactions for account.")
return
}
self.transactionDict.updateValue(transactions, forKey: "transactions")
self.pushController(withName: "Transactions", context: self.transactionDict)
self.configureInterfaceObjects(false)
self.activityIndicator.stopAnimatingAsIndicator()
}
}
}
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.curBalance)
let availableFormatted = String(format: "%.2f", acct.creditLimit - acct.curBalance)
let date = DateFormatter.localizedString(from: acct.paymentDueDate, dateStyle: .medium, timeStyle: .none)
accountNameLabel.setText(acct.accountName)
balanceLabel.setText("Balance: $\(balanceFormatted)")
availableFundsLabel.setText("Available: $\(availableFormatted)")
nextPaymentDueLabel.setText(date)
}
private func configureInterfaceObjects(_ hide: Bool) {
transactionsButton.setHidden(hide)
payButton.setHidden(hide)
balanceLabel.setHidden(hide)
availableFundsLabel.setHidden(hide)
accountNameLabel.setHidden(hide)
nextPaymentDueLabel.setHidden(hide)
nextPaymentTitleLabel.setHidden(hide)
loadingLabel.setVerticalAlignment(.center)
loadingLabel.setHidden(!hide)
}
}
You can’t perform that action at this time.