Tunnels list: Show data from the tunnels manager
This commit is contained in:
parent
052ece53a3
commit
0593a77d7a
|
@ -10,6 +10,8 @@ import UIKit
|
||||||
|
|
||||||
class TunnelsListTableViewController: UITableViewController {
|
class TunnelsListTableViewController: UITableViewController {
|
||||||
|
|
||||||
|
var tunnelsManager: TunnelsManager? = nil
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
super.init(style: .plain)
|
super.init(style: .plain)
|
||||||
}
|
}
|
||||||
|
@ -23,6 +25,14 @@ class TunnelsListTableViewController: UITableViewController {
|
||||||
self.title = "WireGuard"
|
self.title = "WireGuard"
|
||||||
let addButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButtonTapped(sender:)))
|
let addButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButtonTapped(sender:)))
|
||||||
self.navigationItem.rightBarButtonItem = addButtonItem
|
self.navigationItem.rightBarButtonItem = addButtonItem
|
||||||
|
|
||||||
|
self.tableView.register(TunnelsListTableViewCell.self, forCellReuseIdentifier: TunnelsListTableViewCell.id)
|
||||||
|
|
||||||
|
TunnelsManager.create { [weak self] tunnelsManager in
|
||||||
|
guard let tunnelsManager = tunnelsManager else { return }
|
||||||
|
self?.tunnelsManager = tunnelsManager
|
||||||
|
self?.tableView.reloadData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func addButtonTapped(sender: UIBarButtonItem!) {
|
@objc func addButtonTapped(sender: UIBarButtonItem!) {
|
||||||
|
@ -34,10 +44,40 @@ class TunnelsListTableViewController: UITableViewController {
|
||||||
|
|
||||||
extension TunnelsListTableViewController {
|
extension TunnelsListTableViewController {
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
return 0
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
return 0
|
return (tunnelsManager?.numberOfTunnels() ?? 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelsListTableViewCell.id, for: indexPath) as! TunnelsListTableViewCell
|
||||||
|
if let tunnelsManager = tunnelsManager {
|
||||||
|
let tunnel = tunnelsManager.tunnel(at: indexPath.row)
|
||||||
|
cell.tunnelName = tunnel.name
|
||||||
|
}
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TunnelsListTableViewCell: UITableViewCell {
|
||||||
|
static let id: String = "TunnelsListTableViewCell"
|
||||||
|
var tunnelName: String {
|
||||||
|
get { return textLabel?.text ?? "" }
|
||||||
|
set(value) { textLabel?.text = value }
|
||||||
|
}
|
||||||
|
|
||||||
|
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
|
||||||
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||||
|
self.accessoryType = .disclosureIndicator
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override func prepareForReuse() {
|
||||||
|
super.prepareForReuse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue