From 35a149435ee8df461d83e8a8b58270a3693523f1 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 10 Apr 2021 23:24:51 +0200 Subject: [PATCH] Share guidance metadata in Core --- Passepartout/App/iOS/Global/Theme.swift | 9 ---- .../iOS/Scenes/AccountViewController.swift | 50 +++++++++---------- .../App/macOS/Base.lproj/Service.storyboard | 2 +- Passepartout/App/macOS/CHANGELOG.md | 1 + .../Service/AccountViewController.swift | 31 ++++++------ Passepartout/Core/Sources/Utils.swift | 25 ++++++++++ 6 files changed, 66 insertions(+), 52 deletions(-) diff --git a/Passepartout/App/iOS/Global/Theme.swift b/Passepartout/App/iOS/Global/Theme.swift index 441a1c6f..4258407a 100644 --- a/Passepartout/App/iOS/Global/Theme.swift +++ b/Passepartout/App/iOS/Global/Theme.swift @@ -208,15 +208,6 @@ extension Infrastructure.Metadata { } return image } - - var guidanceString: String? { - let key = "account.sections.guidance.footer.infrastructure.\(name)" - let format = NSLocalizedString(key, tableName: "Core", bundle: Bundle(for: AppDelegate.self), comment: "") - guard format != key else { - return nil - } - return String(format: format, locale: .current, description) - } } extension PoolGroup { diff --git a/Passepartout/App/iOS/Scenes/AccountViewController.swift b/Passepartout/App/iOS/Scenes/AccountViewController.swift index ca1ba05b..1641761f 100644 --- a/Passepartout/App/iOS/Scenes/AccountViewController.swift +++ b/Passepartout/App/iOS/Scenes/AccountViewController.swift @@ -57,27 +57,6 @@ class AccountViewController: UIViewController, StrongTableHost { return Credentials(username, password).trimmed() } - private var guidanceString: String? { - guard let name = infrastructureName, let metadata = InfrastructureFactory.shared.metadata(forName: name) else { - return nil - } - return metadata.guidanceString - } - - private var guidanceURL: String? { - guard let name = infrastructureName else { - return nil - } - return AppConstants.URLs.guidances[name] - } - - private var referralURL: String? { - guard let name = infrastructureName else { - return nil - } - return AppConstants.URLs.referrals[name] - } - weak var delegate: AccountViewControllerDelegate? // MARK: StrongTableHost @@ -144,17 +123,17 @@ class AccountViewController: UIViewController, StrongTableHost { } private func openGuidanceURL() { - guard let urlString = guidanceURL else { + guard let url = guidanceURL else { return } - UIApplication.shared.open(URL(string: urlString)!, options: [:], completionHandler: nil) + UIApplication.shared.open(url, options: [:], completionHandler: nil) } private func openReferralURL() { - guard let urlString = referralURL else { + guard let url = referralURL else { return } - UIApplication.shared.open(URL(string: urlString)!, options: [:], completionHandler: nil) + UIApplication.shared.open(url, options: [:], completionHandler: nil) } @IBAction private func done() { @@ -286,3 +265,24 @@ extension AccountViewController: UITableViewDataSource, UITableViewDelegate, Fie } } } + +extension AccountViewController { + private var guidanceString: String? { + return metadata?.guidanceString + } + + private var guidanceURL: URL? { + return metadata?.guidanceURL + } + + private var referralURL: URL? { + return metadata?.referralURL + } + + private var metadata: Infrastructure.Metadata? { + guard let name = infrastructureName else { + return nil + } + return InfrastructureFactory.shared.metadata(forName: name) + } +} diff --git a/Passepartout/App/macOS/Base.lproj/Service.storyboard b/Passepartout/App/macOS/Base.lproj/Service.storyboard index 0b6bda26..58e2f711 100644 --- a/Passepartout/App/macOS/Base.lproj/Service.storyboard +++ b/Passepartout/App/macOS/Base.lproj/Service.storyboard @@ -805,7 +805,7 @@ DQ - + diff --git a/Passepartout/App/macOS/CHANGELOG.md b/Passepartout/App/macOS/CHANGELOG.md index 6a0da9d4..fdc825a7 100644 --- a/Passepartout/App/macOS/CHANGELOG.md +++ b/Passepartout/App/macOS/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Improved debug log appearance. +- Show information from provider metadata in account. ### Fixed diff --git a/Passepartout/App/macOS/Scenes/Service/AccountViewController.swift b/Passepartout/App/macOS/Scenes/Service/AccountViewController.swift index 8cad0d14..f200d591 100644 --- a/Passepartout/App/macOS/Scenes/Service/AccountViewController.swift +++ b/Passepartout/App/macOS/Scenes/Service/AccountViewController.swift @@ -88,7 +88,9 @@ class AccountViewController: NSViewController { } } - @IBAction private func openGuidance(_ sender: Any?) { + // MARK: Actions + + @IBAction private func openGuidanceURL(_ sender: Any?) { guard let url = guidanceURL else { return } @@ -126,27 +128,22 @@ class AccountViewController: NSViewController { } extension AccountViewController { - private var infrastructureName: Infrastructure.Name? { - guard let providerProfile = profile as? ProviderConnectionProfile else { - return nil - } - return providerProfile.name - } - private var guidanceString: String? { - guard let name = infrastructureName, let metadata = InfrastructureFactory.shared.metadata(forName: name) else { - return nil - } - return metadata.guidanceString + return metadata?.guidanceString } private var guidanceURL: URL? { - guard let name = infrastructureName else { + return metadata?.guidanceURL + } + + private var referralURL: URL? { + return metadata?.referralURL + } + + private var metadata: Infrastructure.Metadata? { + guard let providerProfile = profile as? ProviderConnectionProfile else { return nil } - guard let string = AppConstants.URLs.guidances[name] else { - return nil - } - return URL(string: string) + return InfrastructureFactory.shared.metadata(forName: providerProfile.name) } } diff --git a/Passepartout/Core/Sources/Utils.swift b/Passepartout/Core/Sources/Utils.swift index d49828b5..6227503c 100644 --- a/Passepartout/Core/Sources/Utils.swift +++ b/Passepartout/Core/Sources/Utils.swift @@ -198,3 +198,28 @@ public extension Array where Element: CustomStringConvertible { return sorted { $0.description.lowercased() < $1.description.lowercased() } } } + +public extension Infrastructure.Metadata { + var guidanceString: String? { + let key = "account.sections.guidance.footer.infrastructure.\(name)" + let format = NSLocalizedString(key, tableName: "Core", bundle: .main, comment: "") + guard format != key else { + return nil + } + return String(format: format, locale: .current, description) + } + + var guidanceURL: URL? { + guard let string = AppConstants.URLs.guidances[name] else { + return nil + } + return URL(string: string) + } + + var referralURL: URL? { + guard let string = AppConstants.URLs.referrals[name] else { + return nil + } + return URL(string: string) + } +}