Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
SynchronyFinancialWatchApp/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountDetailsInterfaceController.swift
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
57 lines (46 sloc)
1.93 KB
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
// | |
// 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) | |
} | |
} |