Add extended provider location description
- Profile: Below location row - Menu: On top of server list
This commit is contained in:
parent
7975ddd194
commit
1005a12a66
|
@ -62,6 +62,8 @@ class DefaultLightProviderLocation: LightProviderLocation {
|
|||
class DefaultLightProviderServer: LightProviderServer {
|
||||
let description: String
|
||||
|
||||
let longDescription: String
|
||||
|
||||
let categoryName: String
|
||||
|
||||
let locationId: String
|
||||
|
@ -70,6 +72,7 @@ class DefaultLightProviderServer: LightProviderServer {
|
|||
|
||||
init(_ server: ProviderServer) {
|
||||
description = server.localizedShortDescriptionWithDefault
|
||||
longDescription = server.localizedLongDescription
|
||||
categoryName = server.categoryName
|
||||
locationId = server.locationId
|
||||
serverId = server.id
|
||||
|
|
|
@ -56,6 +56,7 @@ extension ProfileView {
|
|||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var mainView: some View {
|
||||
Section {
|
||||
NavigationLink(isActive: $isProviderLocationPresented) {
|
||||
|
@ -71,6 +72,12 @@ extension ProfileView {
|
|||
currentProviderCountryImage
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
currentProviderFullName.map(Text.init)
|
||||
} footer: {
|
||||
currentProviderServerDescription.map(Text.init)
|
||||
}
|
||||
Section {
|
||||
NavigationLink {
|
||||
ProviderPresetView(currentProfile: currentProfile)
|
||||
} label: {
|
||||
|
@ -80,8 +87,6 @@ extension ProfileView {
|
|||
Button(action: refreshInfrastructure) {
|
||||
Text(L10n.Profile.Items.Provider.Refresh.caption)
|
||||
}.withTrailingProgress(when: isRefreshingInfrastructure)
|
||||
} header: {
|
||||
currentProviderFullName.map(Text.init)
|
||||
} footer: {
|
||||
lastInfrastructureUpdate.map {
|
||||
Text(L10n.Profile.Sections.ProviderInfrastructure.footer($0))
|
||||
|
@ -90,8 +95,8 @@ extension ProfileView {
|
|||
}
|
||||
|
||||
private var currentProviderFullName: String? {
|
||||
guard let name = currentProfile.value.header.providerName else {
|
||||
assertionFailure("Provider name accessed but profile is not a provider (isPlaceholder? \(currentProfile.value.isPlaceholder))")
|
||||
guard let name = profile.header.providerName else {
|
||||
assertionFailure("Provider name accessed but profile is not a provider (isPlaceholder? \(profile.isPlaceholder))")
|
||||
return nil
|
||||
}
|
||||
guard let metadata = providerManager.provider(withName: name) else {
|
||||
|
@ -101,28 +106,29 @@ extension ProfileView {
|
|||
return metadata.fullName
|
||||
}
|
||||
|
||||
// private var currentProviderLocation: String? {
|
||||
// return providerManager.localizedLocation(forProfile: profile)
|
||||
// }
|
||||
private var currentProviderServerDescription: String? {
|
||||
return profile.providerServer(providerManager)?.localizedLongDescription
|
||||
}
|
||||
|
||||
private var currentProviderCountryImage: Image? {
|
||||
guard let code = currentProfile.value.providerServer(providerManager)?.countryCode else {
|
||||
guard let code = profile.providerServer(providerManager)?.countryCode else {
|
||||
return nil
|
||||
}
|
||||
return themeAssetsCountryImage(code).asAssetImage
|
||||
}
|
||||
|
||||
private var currentProviderPreset: String? {
|
||||
return providerManager.localizedPreset(forProfile: currentProfile.value)
|
||||
return providerManager.localizedPreset(forProfile: profile)
|
||||
}
|
||||
|
||||
private var lastInfrastructureUpdate: String? {
|
||||
return providerManager.localizedInfrastructureUpdate(forProfile: currentProfile.value)
|
||||
return providerManager.localizedInfrastructureUpdate(forProfile: profile)
|
||||
}
|
||||
|
||||
private func refreshInfrastructure() {
|
||||
isRefreshingInfrastructure = true
|
||||
Task {
|
||||
try await providerManager.fetchRemoteProviderPublisher(forProfile: currentProfile.value).async()
|
||||
try await providerManager.fetchRemoteProviderPublisher(forProfile: profile).async()
|
||||
isRefreshingInfrastructure = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ extension ProviderServer {
|
|||
localizedShortDescription.map {
|
||||
comps.append($0)
|
||||
}
|
||||
return comps.joined(separator: " - ")
|
||||
return comps.joined(separator: ", ")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ public protocol LightProviderLocation {
|
|||
public protocol LightProviderServer {
|
||||
var description: String { get }
|
||||
|
||||
var longDescription: String { get }
|
||||
|
||||
var categoryName: String { get }
|
||||
|
||||
var locationId: String { get }
|
||||
|
|
|
@ -78,13 +78,24 @@ struct ProviderProfileItem: Item {
|
|||
menu.addItem(toggleItem)
|
||||
menu.addItem(.separator())
|
||||
|
||||
if let currentServerDescription = viewModel.profile.providerServer?.longDescription {
|
||||
let currentItem = NSMenuItem()
|
||||
currentItem.title = currentServerDescription
|
||||
currentItem.isEnabled = false
|
||||
menu.addItem(currentItem)
|
||||
}
|
||||
|
||||
if categories.count > 1 {
|
||||
viewModel.categories.forEach {
|
||||
menu.addItem(categoryItem(with: $0, parent: menu))
|
||||
let item = categoryItem(with: $0, parent: menu)
|
||||
item.indentationLevel = 1
|
||||
menu.addItem(item)
|
||||
}
|
||||
} else {
|
||||
viewModel.categories.first?.locations.forEach {
|
||||
menu.addItem(locationItem(with: $0, parent: menu))
|
||||
let item = locationItem(with: $0, parent: menu)
|
||||
item.indentationLevel = 1
|
||||
menu.addItem(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue