Extend styles for VPN status description

This commit is contained in:
Davide De Rosa 2022-04-22 09:57:13 +02:00
parent 867b415b6b
commit 7095791428
3 changed files with 29 additions and 8 deletions

View File

@ -49,7 +49,15 @@ extension PassepartoutError {
}
extension VPNManager.ObservableState {
func localizedStatusDescription(withErrors: Bool, withDataCount: Bool) -> String {
enum LocalizedStyle {
case statusOnly
case dataCountOrStatus
case statusAndDataCount
}
func localizedStatusDescription(withErrors: Bool, style: LocalizedStyle) -> String {
guard isEnabled else {
// report application errors even if VPN is disabled
@ -66,12 +74,25 @@ extension VPNManager.ObservableState {
return errorDescription
}
}
if withDataCount {
if vpnStatus == .connected, let dataCount = dataCount {
return dataCount.localizedDescription
}
let statusDescription = vpnStatus.localizedDescription
var dataCountDescription: String?
if vpnStatus == .connected, let dataCount = dataCount {
dataCountDescription = dataCount.localizedDescription
}
switch style {
case .statusOnly:
return statusDescription
case .dataCountOrStatus:
return dataCountDescription ?? statusDescription
case .statusAndDataCount:
var comps: [String] = [statusDescription]
if let dataCountDescription = dataCountDescription {
comps.append(dataCountDescription)
}
return comps.joined(separator: " ")
}
return vpnStatus.localizedDescription
}
}

View File

@ -92,7 +92,7 @@ extension ProfileView {
Text(L10n.Profile.Items.ConnectionStatus.caption)
.withTrailingText(currentVPNState.localizedStatusDescription(
withErrors: true,
withDataCount: true
style: .dataCountOrStatus
))
}
}

View File

@ -41,7 +41,7 @@ struct VPNStatusText: View {
private var statusDescription: String {
return currentVPNState.localizedStatusDescription(
withErrors: false,
withDataCount: true
style: .statusAndDataCount
)
}
}