BlueWallet/ios/BlueWalletWatch Extension/InterfaceController.swift

47 lines
1.3 KiB
Swift
Raw Normal View History

2019-05-02 16:33:03 -04:00
//
// InterfaceController.swift
// BlueWalletWatch Extension
//
// Created by Marcos Rodriguez on 3/6/19.
//
import WatchKit
import WatchConnectivity
import Foundation
class InterfaceController: WKInterfaceController {
2019-05-02 16:33:03 -04:00
@IBOutlet weak var walletsTable: WKInterfaceTable!
@IBOutlet weak var noWalletsAvailableLabel: WKInterfaceLabel!
2019-05-02 16:33:03 -04:00
override func willActivate() {
super.willActivate()
2024-01-25 00:39:01 -04:00
updateUI()
NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: Notifications.dataUpdated.name, object: nil)
2019-05-02 16:33:03 -04:00
}
2024-01-25 00:39:01 -04:00
@objc private func updateUI() {
let wallets = WatchDataSource.shared.wallets
let isEmpty = wallets.isEmpty
noWalletsAvailableLabel.setHidden(!isEmpty)
walletsTable.setHidden(isEmpty)
2019-05-02 16:33:03 -04:00
2024-01-25 00:39:01 -04:00
if isEmpty { return }
walletsTable.setNumberOfRows(wallets.count, withRowType: WalletInformation.identifier)
for index in 0..<wallets.count {
updateRow(at: index, with: wallets[index])
2019-05-02 16:33:03 -04:00
}
}
2024-01-25 00:39:01 -04:00
private func updateRow(at index: Int, with wallet: Wallet) {
guard let controller = walletsTable.rowController(at: index) as? WalletInformation else { return }
controller.configure(with: wallet)
2019-05-02 16:33:03 -04:00
}
2024-01-25 00:39:01 -04:00
override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? {
return rowIndex
}
2023-10-26 23:45:55 -04:00
2019-05-02 16:33:03 -04:00
}