Adjust provider popups to country groups

- Use "Default" for no-area pools (count > 1)
- Otherwise, omit area selector (count == 1)
This commit is contained in:
Davide De Rosa 2021-01-03 15:09:24 +01:00
parent 038281b19c
commit e8c91fe00c
2 changed files with 17 additions and 25 deletions

View File

@ -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
}

View File

@ -164,6 +164,7 @@ extension Pool {
public extension Array where Element: Pool {
func sortedPools() -> [Element] {
return sorted {
guard let larea = $0.area else {
guard let lnum = $0.num else {
return true
}
@ -175,5 +176,10 @@ public extension Array where Element: Pool {
}
return lnum < rnum
}
guard let rarea = $1.area else {
return false
}
return larea < rarea
}
}
}