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() popupLocation.removeAllItems()
sortedGroupsByCategory[category.name]?.forEach { sortedGroupsByCategory[category.name]?.forEach {
guard let pool = $0.pools.first else { let item = NSMenuItem(title: $0.localizedCountry, action: nil, keyEquivalent: "")
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: "")
item.image = $0.logo item.image = $0.logo
menu.addItem(item) menu.addItem(item)
} }
@ -240,10 +225,11 @@ class ProviderServiceView: NSView {
// FIXME: inefficient, cache sorted pools // FIXME: inefficient, cache sorted pools
currentSortedPools = group.pools.sortedPools() currentSortedPools = group.pools.sortedPools()
currentSortedPools.forEach { currentSortedPools.forEach {
guard !$0.secondaryId.isEmpty else { guard !$0.secondaryId.isEmpty || currentSortedPools.count > 1 else {
return 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 { if let extraCountry = $0.extraCountries?.first {
item.image = extraCountry.image item.image = extraCountry.image
} }

View File

@ -164,16 +164,22 @@ extension Pool {
public extension Array where Element: Pool { public extension Array where Element: Pool {
func sortedPools() -> [Element] { func sortedPools() -> [Element] {
return sorted { return sorted {
guard let lnum = $0.num else { guard let larea = $0.area else {
return true 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 return false
} }
guard lnum != rnum else { return larea < rarea
return $0.secondaryId < $1.secondaryId
}
return lnum < rnum
} }
} }
} }