From 15f23dd4488e9399618f16955011d3e1a020a217 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 21 Mar 2019 10:42:51 +0100 Subject: [PATCH] Retain Pool.name internally but show .localizedName Use name from API if available (XXX: not localized). Make it private to avoid unintended use in app. --- .../ShortcutsConnectToViewController.swift | 2 +- .../Scenes/ProviderPoolViewController.swift | 2 +- .../Scenes/ServiceViewController.swift | 2 +- .../Sources/Intents/IntentDispatcher.swift | 2 +- Passepartout/Sources/Services/Pool.swift | 21 ++++++++----------- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift b/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift index 301e1d3d..0d05eca2 100644 --- a/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/ShortcutsConnectToViewController.swift @@ -166,7 +166,7 @@ extension ShortcutsConnectToViewController { let intent = MoveToLocationIntent() intent.providerId = provider.id intent.poolId = pool.id - intent.poolName = pool.name + intent.poolName = pool.localizedName addShortcut(with: intent) } diff --git a/Passepartout-iOS/Scenes/ProviderPoolViewController.swift b/Passepartout-iOS/Scenes/ProviderPoolViewController.swift index ee12618a..db03f6a8 100644 --- a/Passepartout-iOS/Scenes/ProviderPoolViewController.swift +++ b/Passepartout-iOS/Scenes/ProviderPoolViewController.swift @@ -76,7 +76,7 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate let pool = pools[indexPath.row] let cell = Cells.setting.dequeue(from: tableView, for: indexPath) - cell.leftText = pool.name + cell.leftText = pool.localizedName // cell.rightText = pool.area cell.applyChecked(pool.id == currentPoolId, Theme.current) cell.isTappable = true diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index aa2d6762..79bfd05c 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -620,7 +620,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog case .providerPool: let cell = Cells.setting.dequeue(from: tableView, for: indexPath) cell.leftText = L10n.Service.Cells.Provider.Pool.caption - cell.rightText = uncheckedProviderProfile.pool?.name + cell.rightText = uncheckedProviderProfile.pool?.localizedName return cell case .providerPreset: diff --git a/Passepartout/Sources/Intents/IntentDispatcher.swift b/Passepartout/Sources/Intents/IntentDispatcher.swift index a611e311..8daaa826 100644 --- a/Passepartout/Sources/Intents/IntentDispatcher.swift +++ b/Passepartout/Sources/Intents/IntentDispatcher.swift @@ -49,7 +49,7 @@ public class IntentDispatcher { let intent = MoveToLocationIntent() intent.providerId = profile.id intent.poolId = pool.id - intent.poolName = pool.name + intent.poolName = pool.localizedName genericIntent = intent } else { let intent = ConnectVPNIntent() diff --git a/Passepartout/Sources/Services/Pool.swift b/Passepartout/Sources/Services/Pool.swift index 32de7874..0b6118fd 100644 --- a/Passepartout/Sources/Services/Pool.swift +++ b/Passepartout/Sources/Services/Pool.swift @@ -45,7 +45,7 @@ public struct Pool: Codable, Comparable, CustomStringConvertible { public let id: String - public let name: String + private let name: String public let country: String @@ -74,16 +74,7 @@ public struct Pool: Codable, Comparable, CustomStringConvertible { // MARK: Comparable public static func <(lhs: Pool, rhs: Pool) -> Bool { - if lhs.name == rhs.name { - guard let larea = lhs.area else { - return true - } - guard let rarea = rhs.area else { - return false - } - return larea < rarea - } - return lhs.name < rhs.name + return lhs.localizedName < rhs.localizedName } // MARK: CustomStringConvertible @@ -100,7 +91,13 @@ extension Pool { return Utils.localizedCountry(country) } - public var name: String { + public var localizedName: String { + + // XXX: name from API is not localized + if !name.isEmpty { + return name + } + let countryString = localizedCountry guard let area = area else { return countryString