Permalink
Browse files
Merge pull request #8 from rrk12005/SWF-10-account-details
Swf 10 account details
- Loading branch information
Showing
with
416 additions
and 17 deletions.
- +102 −3 SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard
- +14 −0 SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountCell.swift
- +57 −0 SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountDetailsInterfaceController.swift
- +61 −0 SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift
- +10 −0 ...l WatchKit Extension/Assets.xcassets/Complication.complicationset/Circular.imageset/Contents.json
- +10 −0 ...atchKit Extension/Assets.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json
- +10 −0 ...chKit Extension/Assets.xcassets/Complication.complicationset/Graphic Bezel.imageset/Contents.json
- +10 −0 ...it Extension/Assets.xcassets/Complication.complicationset/Graphic Circular.imageset/Contents.json
- +10 −0 ...hKit Extension/Assets.xcassets/Complication.complicationset/Graphic Corner.imageset/Contents.json
- +10 −0 ...ion/Assets.xcassets/Complication.complicationset/Graphic Large Rectangular.imageset/Contents.json
- +10 −0 ...al WatchKit Extension/Assets.xcassets/Complication.complicationset/Modular.imageset/Contents.json
- +10 −0 ...atchKit Extension/Assets.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json
- +16 −0 SynchronyFinancial/SynchronyFinancial WatchKit Extension/TransactionCell.swift
- +48 −0 SynchronyFinancial/SynchronyFinancial WatchKit Extension/TransactionsInterfaceController.swift
- +38 −14 SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj
@@ -0,0 +1,14 @@ | ||
// | ||
// Account.swift | ||
// SynchronyFinancial WatchKit Extension | ||
// | ||
// Created by Monday on 2019/02/13. | ||
// Copyright © 2019 Alan Maynard. All rights reserved. | ||
// | ||
import Foundation | ||
import WatchKit | ||
|
||
class AccountCell: NSObject { | ||
@IBOutlet weak var accountName: WKInterfaceLabel! | ||
} |
@@ -0,0 +1,57 @@ | ||
// | ||
// 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? | ||
|
||
@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) | ||
|
||
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() | ||
} | ||
|
||
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) | ||
} | ||
} |
@@ -0,0 +1,61 @@ | ||
// | ||
// AccountTableInterfaceController.swift | ||
// SynchronyFinancial WatchKit Extension | ||
// | ||
// Created by Monday on 2019/02/13. | ||
// Copyright © 2019 Alan Maynard. All rights reserved. | ||
// | ||
import WatchKit | ||
import Foundation | ||
|
||
class AccountTableInterfaceController: WKInterfaceController { | ||
var accounts: [Account] = [] | ||
var acctDict: [String: Account] = [:] | ||
|
||
@IBOutlet weak var accountTable: WKInterfaceTable! | ||
override func awake(withContext context: Any?) { | ||
super.awake(withContext: context) | ||
|
||
populateDemoData() | ||
configureRows() | ||
} | ||
|
||
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 contextsForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> [Any]? { | ||
if segueIdentifier == "showAccountDetails" { | ||
// account data is passed to the first interface controller in our new navigation stack | ||
// if we want to pass to subsequent interface controllers, we would add them in corresponding order | ||
acctDict.updateValue(accounts[rowIndex], forKey: "acct") | ||
return [acctDict] | ||
} | ||
return nil | ||
} | ||
|
||
private func configureRows() { | ||
accountTable.setNumberOfRows(accounts.count, withRowType: "account") | ||
|
||
for index in 0..<accountTable.numberOfRows { | ||
if let row = accountTable.rowController(at: index) as? AccountCell { | ||
row.accountName.setText(accounts[index].accountNumber) | ||
} | ||
} | ||
} | ||
|
||
private func populateDemoData() { | ||
//swiftlint:disable line_length | ||
accounts.append(Account(accountNumber: "TD Bank", limit: 500.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date())) | ||
accounts.append(Account(accountNumber: "Care Credit", limit: 10000.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date())) | ||
accounts.append(Account(accountNumber: "People's Bank", limit: 500.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date())) | ||
accounts.append(Account(accountNumber: "Bank of America", limit: 10000.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date())) | ||
} | ||
} |

Oops, something went wrong.