From e8c91fe00c1be50bd2d97c6f36d03713b0550f47 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 3 Jan 2021 15:09:24 +0100 Subject: [PATCH] Adjust provider popups to country groups - Use "Default" for no-area pools (count > 1) - Otherwise, omit area selector (count == 1) --- .../Scenes/Service/ProviderServiceView.swift | 22 ++++--------------- Passepartout/Core/Sources/Services/Pool.swift | 20 +++++++++++------ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Passepartout/App/macOS/Scenes/Service/ProviderServiceView.swift b/Passepartout/App/macOS/Scenes/Service/ProviderServiceView.swift index 8907d52e..629e1538 100644 --- a/Passepartout/App/macOS/Scenes/Service/ProviderServiceView.swift +++ b/Passepartout/App/macOS/Scenes/Service/ProviderServiceView.swift @@ -205,22 +205,7 @@ class ProviderServiceView: NSView { popupLocation.removeAllItems() sortedGroupsByCategory[category.name]?.forEach { - guard let pool = $0.pools.first else { - return - } - - var title = $0.localizedCountry - let subtitle: String? - if $0.pools.count > 1 { - subtitle = pool.area?.uppercased() - } else { - subtitle = pool.secondaryId - } - if !(subtitle?.isEmpty ?? true) { - title.append(" - \(subtitle!)") - } - - let item = NSMenuItem(title: title, action: nil, keyEquivalent: "") + let item = NSMenuItem(title: $0.localizedCountry, action: nil, keyEquivalent: "") item.image = $0.logo menu.addItem(item) } @@ -240,10 +225,11 @@ class ProviderServiceView: NSView { // FIXME: inefficient, cache sorted pools currentSortedPools = group.pools.sortedPools() currentSortedPools.forEach { - guard !$0.secondaryId.isEmpty else { + guard !$0.secondaryId.isEmpty || currentSortedPools.count > 1 else { return } - let item = NSMenuItem(title: $0.secondaryId, action: nil, keyEquivalent: "") + let title = !$0.secondaryId.isEmpty ? $0.secondaryId : "Default" + let item = NSMenuItem(title: title, action: nil, keyEquivalent: "") if let extraCountry = $0.extraCountries?.first { item.image = extraCountry.image } diff --git a/Passepartout/Core/Sources/Services/Pool.swift b/Passepartout/Core/Sources/Services/Pool.swift index e836da97..9307431b 100644 --- a/Passepartout/Core/Sources/Services/Pool.swift +++ b/Passepartout/Core/Sources/Services/Pool.swift @@ -164,16 +164,22 @@ extension Pool { public extension Array where Element: Pool { func sortedPools() -> [Element] { return sorted { - guard let lnum = $0.num else { - return true + guard let larea = $0.area else { + guard let lnum = $0.num else { + return true + } + guard let rnum = $1.num else { + return false + } + guard lnum != rnum else { + return $0.secondaryId < $1.secondaryId + } + return lnum < rnum } - guard let rnum = $1.num else { + guard let rarea = $1.area else { return false } - guard lnum != rnum else { - return $0.secondaryId < $1.secondaryId - } - return lnum < rnum + return larea < rarea } } }