Set current pool atomically with pools

This commit is contained in:
Davide De Rosa 2019-04-06 16:07:54 +02:00
parent 8d3a5d747d
commit 8db2b70e65
3 changed files with 7 additions and 8 deletions

View File

@ -89,7 +89,7 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
guard let provider = selectedProfile as? ProviderConnectionProfile else { guard let provider = selectedProfile as? ProviderConnectionProfile else {
return return
} }
vc.setPools(provider.pools()) vc.setPools(provider.pools(), currentPoolId: nil)
vc.delegate = self vc.delegate = self
} }

View File

@ -37,11 +37,11 @@ class ProviderPoolViewController: UIViewController {
private var sortedGroups: [PoolGroup] = [] private var sortedGroups: [PoolGroup] = []
var currentPoolId: String? private var currentPool: Pool?
weak var delegate: ProviderPoolViewControllerDelegate? weak var delegate: ProviderPoolViewControllerDelegate?
func setPools(_ pools: [Pool]) { func setPools(_ pools: [Pool], currentPoolId: String?) {
for p in pools { for p in pools {
poolsByGroup[p.group()] = [p] poolsByGroup[p.group()] = [p]
} }
@ -72,7 +72,7 @@ class ProviderPoolViewController: UIViewController {
extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate { extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate {
private var selectedIndexPath: IndexPath? { private var selectedIndexPath: IndexPath? {
for entries in poolsByGroup.enumerated() { for entries in poolsByGroup.enumerated() {
guard let _ = entries.element.value.index(where: { $0.id == currentPoolId }) else { guard let _ = entries.element.value.index(where: { $0.id == currentPool?.id }) else {
continue continue
} }
guard let row = sortedGroups.index(of: entries.element.key) else { guard let row = sortedGroups.index(of: entries.element.key) else {
@ -96,7 +96,7 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
cell.imageView?.image = pool.logo cell.imageView?.image = pool.logo
cell.leftText = pool.localizedName cell.leftText = pool.localizedName
cell.rightText = pool.areaId?.uppercased() cell.rightText = pool.areaId?.uppercased()
cell.applyChecked(pool.id == currentPoolId, Theme.current) cell.applyChecked(pool.id == currentPool?.id, Theme.current)
cell.isTappable = true cell.isTappable = true
return cell return cell
} }
@ -106,7 +106,7 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
let groupPools = poolsByGroup[group] let groupPools = poolsByGroup[group]
let pool = groupPools!.first! let pool = groupPools!.first!
currentPoolId = pool.id currentPool = pool
delegate?.providerPoolController(self, didSelectPool: pool) delegate?.providerPoolController(self, didSelectPool: pool)
} }
} }

View File

@ -151,8 +151,7 @@ class ServiceViewController: UIViewController, TableModelHost {
case .providerPoolSegueIdentifier: case .providerPoolSegueIdentifier:
let vc = destination as? ProviderPoolViewController let vc = destination as? ProviderPoolViewController
vc?.setPools(uncheckedProviderProfile.pools()) vc?.setPools(uncheckedProviderProfile.pools(), currentPoolId: uncheckedProviderProfile.poolId)
vc?.currentPoolId = uncheckedProviderProfile.poolId
vc?.delegate = self vc?.delegate = self
case .endpointSegueIdentifier: case .endpointSegueIdentifier: