Convert table model to PoolGroup
This commit is contained in:
parent
97a72c7c02
commit
8d3a5d747d
|
@ -89,7 +89,7 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
|
|||
guard let provider = selectedProfile as? ProviderConnectionProfile else {
|
||||
return
|
||||
}
|
||||
vc.pools = provider.sortedPools()
|
||||
vc.setPools(provider.pools())
|
||||
vc.delegate = self
|
||||
}
|
||||
|
||||
|
|
|
@ -33,12 +33,21 @@ protocol ProviderPoolViewControllerDelegate: class {
|
|||
class ProviderPoolViewController: UIViewController {
|
||||
@IBOutlet private weak var tableView: UITableView!
|
||||
|
||||
var pools: [Pool] = []
|
||||
private var poolsByGroup: [PoolGroup: [Pool]] = [:]
|
||||
|
||||
private var sortedGroups: [PoolGroup] = []
|
||||
|
||||
var currentPoolId: String?
|
||||
|
||||
weak var delegate: ProviderPoolViewControllerDelegate?
|
||||
|
||||
func setPools(_ pools: [Pool]) {
|
||||
for p in pools {
|
||||
poolsByGroup[p.group()] = [p]
|
||||
}
|
||||
sortedGroups = poolsByGroup.keys.sorted()
|
||||
}
|
||||
|
||||
// MARK: UIViewController
|
||||
|
||||
override func awakeFromNib() {
|
||||
|
@ -62,18 +71,26 @@ class ProviderPoolViewController: UIViewController {
|
|||
|
||||
extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate {
|
||||
private var selectedIndexPath: IndexPath? {
|
||||
guard let row = pools.index(where: { $0.id == currentPoolId }) else {
|
||||
return nil
|
||||
for entries in poolsByGroup.enumerated() {
|
||||
guard let _ = entries.element.value.index(where: { $0.id == currentPoolId }) else {
|
||||
continue
|
||||
}
|
||||
guard let row = sortedGroups.index(of: entries.element.key) else {
|
||||
continue
|
||||
}
|
||||
return IndexPath(row: row, section: 0)
|
||||
}
|
||||
return IndexPath(row: row, section: 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return pools.count
|
||||
return sortedGroups.count
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let pool = pools[indexPath.row]
|
||||
let group = sortedGroups[indexPath.row]
|
||||
let groupPools = poolsByGroup[group]
|
||||
let pool = groupPools!.first!
|
||||
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
cell.imageView?.image = pool.logo
|
||||
|
@ -85,7 +102,10 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
|
|||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
let pool = pools[indexPath.row]
|
||||
let group = sortedGroups[indexPath.row]
|
||||
let groupPools = poolsByGroup[group]
|
||||
let pool = groupPools!.first!
|
||||
|
||||
currentPoolId = pool.id
|
||||
delegate?.providerPoolController(self, didSelectPool: pool)
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ class ServiceViewController: UIViewController, TableModelHost {
|
|||
|
||||
case .providerPoolSegueIdentifier:
|
||||
let vc = destination as? ProviderPoolViewController
|
||||
vc?.pools = uncheckedProviderProfile.sortedPools()
|
||||
vc?.setPools(uncheckedProviderProfile.pools())
|
||||
vc?.currentPoolId = uncheckedProviderProfile.poolId
|
||||
vc?.delegate = self
|
||||
|
||||
|
|
|
@ -72,8 +72,8 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
|
|||
presetId = infrastructure.defaults.preset
|
||||
}
|
||||
|
||||
public func sortedPools() -> [Pool] {
|
||||
return infrastructure.pools.sorted()
|
||||
public func pools() -> [Pool] {
|
||||
return infrastructure.pools
|
||||
}
|
||||
|
||||
private func validateEndpoint() {
|
||||
|
|
Loading…
Reference in New Issue