From 337c002dc79350caf675e91f5964f80d86c7da5c Mon Sep 17 00:00:00 2001 From: Paul B Date: Fri, 28 May 2021 16:04:45 +0200 Subject: [PATCH] wip: open source licenses (#65) shows open source licenses in settings adds opensourcenotices to app removes link to github --- DGCAWallet.xcodeproj/project.pbxproj | 20 ++ DGCAWallet/Components/LicenseCell.swift | 41 ++++ .../Base.lproj/Settings.storyboard | 139 +++++++++++--- DGCAWallet/Storyboards/Licenses.storyboard | 176 ++++++++++++++++++ .../SupportingFiles/OpenSourceNotices.json | 24 +++ DGCAWallet/ViewControllers/LicenseList.swift | 104 +++++++++++ DGCAWallet/ViewControllers/LicenseVC.swift | 68 +++++++ DGCAWallet/ViewControllers/Settings.swift | 14 +- 8 files changed, 544 insertions(+), 42 deletions(-) create mode 100644 DGCAWallet/Components/LicenseCell.swift create mode 100644 DGCAWallet/Storyboards/Licenses.storyboard create mode 100644 DGCAWallet/SupportingFiles/OpenSourceNotices.json create mode 100644 DGCAWallet/ViewControllers/LicenseList.swift create mode 100644 DGCAWallet/ViewControllers/LicenseVC.swift diff --git a/DGCAWallet.xcodeproj/project.pbxproj b/DGCAWallet.xcodeproj/project.pbxproj index d512f58..7d26657 100644 --- a/DGCAWallet.xcodeproj/project.pbxproj +++ b/DGCAWallet.xcodeproj/project.pbxproj @@ -45,6 +45,11 @@ CEE9DA55263C7D4000A31532 /* CertCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE9DA54263C7D4000A31532 /* CertCode.swift */; }; CEE9DA5D263C865200A31532 /* Brightness.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE9DA5C263C865200A31532 /* Brightness.swift */; }; CEFAD87F262714C4009AFEF9 /* EHNTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFAD87E262714C4009AFEF9 /* EHNTests.swift */; }; + DA01661C265541C0005B73A1 /* LicenseList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA01661B265541C0005B73A1 /* LicenseList.swift */; }; + DA01661E26554992005B73A1 /* OpenSourceNotices.json in Resources */ = {isa = PBXBuildFile; fileRef = DA01661D26554992005B73A1 /* OpenSourceNotices.json */; }; + DA01662026554E02005B73A1 /* LicenseCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA01661F26554E02005B73A1 /* LicenseCell.swift */; }; + DA01662226558B2F005B73A1 /* LicenseVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA01662126558B2F005B73A1 /* LicenseVC.swift */; }; + DA017DE626552259006E4D49 /* Licenses.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DA017DE526552259006E4D49 /* Licenses.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -105,6 +110,11 @@ CEE9DA54263C7D4000A31532 /* CertCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertCode.swift; sourceTree = ""; }; CEE9DA5C263C865200A31532 /* Brightness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Brightness.swift; sourceTree = ""; }; CEFAD87E262714C4009AFEF9 /* EHNTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EHNTests.swift; sourceTree = ""; }; + DA01661B265541C0005B73A1 /* LicenseList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseList.swift; sourceTree = ""; }; + DA01661D26554992005B73A1 /* OpenSourceNotices.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = OpenSourceNotices.json; sourceTree = ""; }; + DA01661F26554E02005B73A1 /* LicenseCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseCell.swift; sourceTree = ""; }; + DA01662126558B2F005B73A1 /* LicenseVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseVC.swift; sourceTree = ""; }; + DA017DE526552259006E4D49 /* Licenses.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Licenses.storyboard; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -144,6 +154,7 @@ CEA6D6F1261F8D2700715333 /* Main.storyboard */, CE4BD25A264FF39D00689FD6 /* CertificateViewer.storyboard */, CE4BD257264FF39400689FD6 /* Settings.storyboard */, + DA017DE526552259006E4D49 /* Licenses.storyboard */, ); path = Storyboards; sourceTree = ""; @@ -178,6 +189,8 @@ CEDABD48263C70EF007A9B97 /* CertPages.swift */, CEDABD3F263C5FF4007A9B97 /* CertTable.swift */, CE4BD253264FF28900689FD6 /* Settings.swift */, + DA01661B265541C0005B73A1 /* LicenseList.swift */, + DA01662126558B2F005B73A1 /* LicenseVC.swift */, ); path = ViewControllers; sourceTree = ""; @@ -190,6 +203,7 @@ CE260F55263DD1720083A200 /* WalletCell.swift */, CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */, CEA1556F262F79DE0024B7AC /* InfoCell.swift */, + DA01661F26554E02005B73A1 /* LicenseCell.swift */, ); path = Components; sourceTree = ""; @@ -205,6 +219,7 @@ CEA6D6F9261F8D2900715333 /* Info.plist */, CE6D4A46264835F100A5D33D /* Localizable.strings */, CEC7FEDE264C5A41005561BA /* context.jsonc */, + DA01661D26554992005B73A1 /* OpenSourceNotices.json */, ); path = SupportingFiles; sourceTree = ""; @@ -410,8 +425,10 @@ CE4BD255264FF39400689FD6 /* Settings.storyboard in Resources */, CEC7FEDF264C5A41005561BA /* context.jsonc in Resources */, CE81533A263FF7EC0030D777 /* README.md in Resources */, + DA01661E26554992005B73A1 /* OpenSourceNotices.json in Resources */, CEA6D6F5261F8D2900715333 /* Assets.xcassets in Resources */, CEA6D6F3261F8D2700715333 /* Main.storyboard in Resources */, + DA017DE626552259006E4D49 /* Licenses.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -471,12 +488,15 @@ CE56BC07264068110044FD3F /* GatewayConnection.swift in Sources */, CEA6D6F0261F8D2700715333 /* Scan.swift in Sources */, CE13CF23262DDF810070C80E /* RoundedButton.swift in Sources */, + DA01662026554E02005B73A1 /* LicenseCell.swift in Sources */, CEA6D6EC261F8D2700715333 /* AppDelegate.swift in Sources */, + DA01661C265541C0005B73A1 /* LicenseList.swift in Sources */, CE891305263581D900CB92AF /* Home.swift in Sources */, CEA15563262F6DAB0024B7AC /* CertViewerDelegate.swift in Sources */, CE260F56263DD1720083A200 /* WalletCell.swift in Sources */, CEA15570262F79DE0024B7AC /* InfoCell.swift in Sources */, CED949CA263B50CE00883558 /* List.swift in Sources */, + DA01662226558B2F005B73A1 /* LicenseVC.swift in Sources */, CEA6D6EE261F8D2700715333 /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/DGCAWallet/Components/LicenseCell.swift b/DGCAWallet/Components/LicenseCell.swift new file mode 100644 index 0000000..e0f7ecc --- /dev/null +++ b/DGCAWallet/Components/LicenseCell.swift @@ -0,0 +1,41 @@ +// +/*- + * ---license-start + * eu-digital-green-certificates / dgca-wallet-app-ios + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ +// +// LicenseCell.swift +// DGCAWallet +// +// Created by Paul Ballmann on 19.05.21. +// + +import UIKit +import SwiftDGC +import SwiftyJSON + +class LicenseCell: UITableViewCell { + @IBOutlet weak var cellLabel: UILabel! + + public var licenseObject: JSON = [] + + public func drawLabel(_ licenseObject: JSON) { + self.licenseObject = licenseObject + self.cellLabel.text = licenseObject["name"].string + } +} diff --git a/DGCAWallet/Storyboards/Base.lproj/Settings.storyboard b/DGCAWallet/Storyboards/Base.lproj/Settings.storyboard index 9956cac..c4f34fd 100644 --- a/DGCAWallet/Storyboards/Base.lproj/Settings.storyboard +++ b/DGCAWallet/Storyboards/Base.lproj/Settings.storyboard @@ -5,6 +5,7 @@ + @@ -16,7 +17,7 @@ - + @@ -43,37 +44,14 @@ - - - - - - - - - - - - - - - - - - - + - + + + - + @@ -143,6 +124,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -169,8 +250,8 @@ - - + + diff --git a/DGCAWallet/Storyboards/Licenses.storyboard b/DGCAWallet/Storyboards/Licenses.storyboard new file mode 100644 index 0000000..8dedba2 --- /dev/null +++ b/DGCAWallet/Storyboards/Licenses.storyboard @@ -0,0 +1,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DGCAWallet/SupportingFiles/OpenSourceNotices.json b/DGCAWallet/SupportingFiles/OpenSourceNotices.json new file mode 100644 index 0000000..a551754 --- /dev/null +++ b/DGCAWallet/SupportingFiles/OpenSourceNotices.json @@ -0,0 +1,24 @@ +{ + "licenses": [ + { + "name": "Alamofire", + "licenseUrl": "https://raw.githubusercontent.com/Alamofire/Alamofire/master/LICENSE" + }, + { + "name": "Floating Panel", + "licenseUrl": "https://raw.githubusercontent.com/scenee/FloatingPanel/master/LICENSE" + }, + { + "name": "JSON Schema", + "licenseUrl": "https://raw.githubusercontent.com/eu-digital-green-certificates/JSONSchema.swift/master/LICENSE" + }, + { + "name": "Swift CBOR", + "licenseUrl": "https://raw.githubusercontent.com/unrelentingtech/SwiftCBOR/master/UNLICENSE" + }, + { + "name": "Swifty JSON", + "licenseUrl": "https://raw.githubusercontent.com/SwiftyJSON/SwiftyJSON/master/LICENSE" + } + ] +} diff --git a/DGCAWallet/ViewControllers/LicenseList.swift b/DGCAWallet/ViewControllers/LicenseList.swift new file mode 100644 index 0000000..48f6d12 --- /dev/null +++ b/DGCAWallet/ViewControllers/LicenseList.swift @@ -0,0 +1,104 @@ +// +/*- + * ---license-start + * eu-digital-green-certificates / dgca-wallet-app-ios + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ +// +// Licenses.swift +// DGCAWallet +// +// Created by Paul Ballmann on 19.05.21. +// + +import Foundation +import UIKit +import FloatingPanel +import SwiftDGC +import SwiftyJSON + +class LicenseList: UINavigationController { + + override func viewDidLoad() { + super.viewDidLoad() + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + } + +} + +class LicenseTableVC: UITableViewController { + public var licenses: [JSON] = [] + private var selectedLicense: JSON = [] + + override func viewDidLoad() { + super.viewDidLoad() + self.loadLicenses() + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.destination is LicenseVC { + if let destVC = segue.destination as? LicenseVC { + destVC.licenseObject = self.selectedLicense + } + } + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let cell = tableView.dequeueReusableCell(withIdentifier: "LicenseCell", for: indexPath) as? LicenseCell + else { + return UITableViewCell() + } + let index = indexPath.row + cell.drawLabel(self.licenses[index]) + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + if let cell = tableView.cellForRow(at: indexPath) as? LicenseCell { + self.selectedLicense = cell.licenseObject + } + // segue to the vc + performSegue(withIdentifier: "licenseSegue", sender: nil) + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.licenses.count + } + + private func loadLicenses() { + do { + guard let licenseFileLocation = Bundle.main.path(forResource: "OpenSourceNotices", ofType: "json") + else { + return + } + guard let jsonData = try String(contentsOfFile: licenseFileLocation).data(using: .utf8) + else { + return + } + let jsonDoc = try JSON(data: jsonData) + self.licenses = jsonDoc["licenses"].array ?? [] + } catch { + print(error) + return + } + + print(self.licenses) + } +} diff --git a/DGCAWallet/ViewControllers/LicenseVC.swift b/DGCAWallet/ViewControllers/LicenseVC.swift new file mode 100644 index 0000000..8294f5c --- /dev/null +++ b/DGCAWallet/ViewControllers/LicenseVC.swift @@ -0,0 +1,68 @@ +// +/*- + * ---license-start + * eu-digital-green-certificates / dgca-wallet-app-ios + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ +// +// LicenseVC.swift +// DGCAWallet +// +// Created by Paul Ballmann on 19.05.21. +// + +import UIKit +import SwiftyJSON +import WebKit + +class LicenseVC: UIViewController, WKNavigationDelegate { + @IBOutlet weak var packageNameLabel: UILabel! + @IBOutlet weak var licenseWebView: WKWebView! + @IBOutlet weak var githubUrlLabel: UILabel! + @IBOutlet weak var activityIndicator: UIActivityIndicatorView! + + var licenseObject: JSON = [] + + override func viewDidLoad() { + super.viewDidLoad() + self.packageNameLabel.text = licenseObject["name"].string + self.licenseWebView.isUserInteractionEnabled = false + self.licenseWebView.navigationDelegate = self + + if let licenseUrl = licenseObject["licenseUrl"].string { + loadWebView(licenseUrl) + } + } + + func loadWebView(_ packageLink: String) { + DispatchQueue.main.async { + let request = URLRequest(url: URL(string: packageLink)!) + self.licenseWebView?.load(request) + } + + self.activityIndicator.startAnimating() + self.licenseWebView.navigationDelegate = self + } + + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + self.activityIndicator.stopAnimating() + } + + func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { + self.activityIndicator.stopAnimating() + } +} diff --git a/DGCAWallet/ViewControllers/Settings.swift b/DGCAWallet/ViewControllers/Settings.swift index 1effb7d..7ff30ad 100644 --- a/DGCAWallet/ViewControllers/Settings.swift +++ b/DGCAWallet/ViewControllers/Settings.swift @@ -55,15 +55,8 @@ class SettingsTableVC: UITableViewController { } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - switch indexPath.row { - case 0: + if indexPath.row == 0 { openPrivacyDoc() - case 1: - openEuCertDoc() - case 2: - openGitHubSource() - default: - return } } @@ -77,11 +70,6 @@ class SettingsTableVC: UITableViewController { openUrl(link) } - func openGitHubSource() { - let link = "https://github.com/eu-digital-green-certificates" - openUrl(link) - } - func openUrl(_ string: String!) { if let url = URL(string: string) { UIApplication.shared.open(url)