-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from rrk12005/SWF-10-account-details
Swf 10 account details
- Loading branch information
Showing
15 changed files
with
416 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! | ||
} |
57 changes: 57 additions & 0 deletions
57
...nyFinancial/SynchronyFinancial WatchKit Extension/AccountDetailsInterfaceController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.