Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SWF-21 move fetch transactions call
- we now fetch transactions when the Recents button is tapped from AccountDetails
- created convenience method to show/hide all interface objects when showing activity indicator
  • Loading branch information
ahm11003 committed Mar 29, 2019
1 parent 28a7fc1 commit 3ee46a5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
Expand Up @@ -91,7 +91,6 @@
<objects>
<controller hidesWhenLoading="NO" id="Rpu-25-8st" customClass="AccountTableInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<imageView alignment="left" hidden="YES" id="juz-bW-tJj"/>
<label width="1" alignment="center" text="Accounts" textAlignment="center" id="JYm-yy-xrH"/>
<table alignment="left" id="To8-Ze-tMX">
<items>
Expand All @@ -110,7 +109,6 @@
</items>
<connections>
<outlet property="accountTable" destination="To8-Ze-tMX" id="oJb-Ry-7xR"/>
<outlet property="activityIndicator" destination="juz-bW-tJj" id="Coh-Qr-sk7"/>
<outlet property="titleLabel" destination="JYm-yy-xrH" id="V1g-ul-i8Y"/>
</connections>
</controller>
Expand All @@ -122,6 +120,7 @@
<objects>
<controller identifier="AccountDetails" id="yrN-yp-gkH" customClass="AccountDetailsInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<imageView alignment="left" hidden="YES" id="diX-Fh-Why"/>
<label width="1" alignment="left" text="Label" textAlignment="center" id="qzl-GE-bpZ">
<fontDescription key="font" style="UICTFontTextStyleHeadline"/>
</label>
Expand All @@ -139,17 +138,19 @@
</button>
<button width="64" alignment="right" title="Recent" id="0HI-HK-yDl">
<connections>
<segue destination="Jfd-Hv-PHe" kind="push" identifier="showTransactions" id="bjb-v1-scE"/>
<action selector="recentButtonTapped" destination="yrN-yp-gkH" id="8Rp-SG-lGZ"/>
</connections>
</button>
</items>
</group>
</items>
<connections>
<outlet property="accountNameLabel" destination="qzl-GE-bpZ" id="6jA-KZ-quX"/>
<outlet property="activityIndicator" destination="diX-Fh-Why" id="Syr-8v-cTP"/>
<outlet property="availableFundsLabel" destination="q0b-tb-dAb" id="rcl-Tl-bDh"/>
<outlet property="balanceLabel" destination="mdb-QX-GuO" id="2Dj-nO-AM8"/>
<outlet property="nextPaymentDueLabel" destination="CPc-qk-Z2y" id="AzY-pn-EMY"/>
<outlet property="nextPaymentTitleLabel" destination="rxs-Zb-naU" id="IDH-8E-WWm"/>
<outlet property="payButton" destination="zeF-ky-mkm" id="v5U-Y5-shh"/>
<outlet property="transactionsButton" destination="0HI-HK-yDl" id="L5Z-M9-wgO"/>
</connections>
Expand Down
Expand Up @@ -12,12 +12,15 @@ import Foundation
class AccountDetailsInterfaceController: WKInterfaceController {
var selectedAccount: Account?
var dictForAcct: [String: Account] = [:]
var transactionDict: [String: [Transaction]] = [:]

@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() {
Expand All @@ -27,6 +30,24 @@ class AccountDetailsInterfaceController: WKInterfaceController {
pushController(withName: "PayMinimum", context: dictForAcct)
}

@IBAction func recentButtonTapped() {
configureInterfaceObjects(false)
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)
Expand Down Expand Up @@ -76,4 +97,14 @@ class AccountDetailsInterfaceController: WKInterfaceController {
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)
}
}
Expand Up @@ -15,8 +15,8 @@ class AccountTableInterfaceController: WKInterfaceController {
var transactionDict: [String: [Transaction]] = [:]

@IBOutlet var titleLabel: WKInterfaceLabel!
@IBOutlet var activityIndicator: WKInterfaceImage!
@IBOutlet weak var accountTable: WKInterfaceTable!

override func awake(withContext context: Any?) {
super.awake(withContext: context)

Expand All @@ -37,30 +37,9 @@ class AccountTableInterfaceController: WKInterfaceController {
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")
// acctDict.updateValue(transactions, forKey: "transactions")
return [acctDict]
}
return nil
}

override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
accountTable.setHidden(true)
titleLabel.setHidden(true)
activityIndicator.configureForActivityIndicator()
acctDict.updateValue(accounts[rowIndex], forKey: "acct")
FetchData.fetchTransactionsFor(accountAlias: accounts[rowIndex].accountAlias) { transactions, error in
guard error == nil else { return }
self.transactionDict.updateValue(transactions, forKey: "transactions")
self.presentController(withNames: ["AccountDetails", "Transactions"], contexts: [self.acctDict, self.transactionDict])
self.accountTable.setHidden(false)
self.titleLabel.setHidden(false)
self.activityIndicator.stopAnimatingAsIndicator()
}
pushController(withName: "AccountDetails", context: acctDict)
}

private func configureRows() {
Expand Down

0 comments on commit 3ee46a5

Please sign in to comment.