From 70957914283263a8e8572fa585a1e4f27e32d7e7 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 22 Apr 2022 09:57:13 +0200 Subject: [PATCH] Extend styles for VPN status description --- Passepartout/App/L10n/Core+L10n.swift | 33 ++++++++++++++++---- Passepartout/App/Views/ProfileView+VPN.swift | 2 +- Passepartout/App/Views/VPNStatusText.swift | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Passepartout/App/L10n/Core+L10n.swift b/Passepartout/App/L10n/Core+L10n.swift index 6dd595d3..19ce0776 100644 --- a/Passepartout/App/L10n/Core+L10n.swift +++ b/Passepartout/App/L10n/Core+L10n.swift @@ -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 } } diff --git a/Passepartout/App/Views/ProfileView+VPN.swift b/Passepartout/App/Views/ProfileView+VPN.swift index 6137b5dd..c2f1cb3c 100644 --- a/Passepartout/App/Views/ProfileView+VPN.swift +++ b/Passepartout/App/Views/ProfileView+VPN.swift @@ -92,7 +92,7 @@ extension ProfileView { Text(L10n.Profile.Items.ConnectionStatus.caption) .withTrailingText(currentVPNState.localizedStatusDescription( withErrors: true, - withDataCount: true + style: .dataCountOrStatus )) } } diff --git a/Passepartout/App/Views/VPNStatusText.swift b/Passepartout/App/Views/VPNStatusText.swift index 8beb67a9..fde87b01 100644 --- a/Passepartout/App/Views/VPNStatusText.swift +++ b/Passepartout/App/Views/VPNStatusText.swift @@ -41,7 +41,7 @@ struct VPNStatusText: View { private var statusDescription: String { return currentVPNState.localizedStatusDescription( withErrors: false, - withDataCount: true + style: .statusAndDataCount ) } }