From 0e6e71f6f833dd370cac567a5b75379b146deae7 Mon Sep 17 00:00:00 2001 From: Yannick Spreen Date: Tue, 20 Apr 2021 23:23:44 +0200 Subject: [PATCH] Start adding info table. --- PatientScannerDemo.xcodeproj/project.pbxproj | 8 ++ PatientScannerDemo/Components/InfoCell.swift | 18 +++++ .../Components/SelfSizedTableView.swift | 25 ++++++ PatientScannerDemo/Models/HCert.swift | 15 +++- .../Storyboards/CertificateViewer.storyboard | 80 ++++++++++++++++--- .../ViewControllers/CertificateViewer.swift | 30 ++++++- PatientScannerDemo/ViewControllers/Scan.swift | 10 +-- 7 files changed, 167 insertions(+), 19 deletions(-) create mode 100644 PatientScannerDemo/Components/InfoCell.swift create mode 100644 PatientScannerDemo/Components/SelfSizedTableView.swift diff --git a/PatientScannerDemo.xcodeproj/project.pbxproj b/PatientScannerDemo.xcodeproj/project.pbxproj index 79a6c99..8b8225e 100644 --- a/PatientScannerDemo.xcodeproj/project.pbxproj +++ b/PatientScannerDemo.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ CEA15558262F639C0024B7AC /* JSONSchema in Frameworks */ = {isa = PBXBuildFile; productRef = CEA15557262F639C0024B7AC /* JSONSchema */; }; CEA1555D262F63B30024B7AC /* EuDgcSchema.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA1555C262F63B30024B7AC /* EuDgcSchema.swift */; }; CEA15563262F6DAB0024B7AC /* ChildDismissedDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA15562262F6DAB0024B7AC /* ChildDismissedDelegate.swift */; }; + CEA1556B262F784E0024B7AC /* SelfSizedTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */; }; + CEA15570262F79DE0024B7AC /* InfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA1556F262F79DE0024B7AC /* InfoCell.swift */; }; CEA6D6EC261F8D2700715333 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA6D6EB261F8D2700715333 /* AppDelegate.swift */; }; CEA6D6EE261F8D2700715333 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA6D6ED261F8D2700715333 /* SceneDelegate.swift */; }; CEA6D6F0261F8D2700715333 /* Scan.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA6D6EF261F8D2700715333 /* Scan.swift */; }; @@ -71,6 +73,8 @@ CE3CC9432628C2130079FB78 /* CBOR.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CBOR.swift; sourceTree = ""; }; CEA1555C262F63B30024B7AC /* EuDgcSchema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EuDgcSchema.swift; sourceTree = ""; }; CEA15562262F6DAB0024B7AC /* ChildDismissedDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChildDismissedDelegate.swift; sourceTree = ""; }; + CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizedTableView.swift; sourceTree = ""; }; + CEA1556F262F79DE0024B7AC /* InfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoCell.swift; sourceTree = ""; }; CEA6D6E8261F8D2700715333 /* PatientScannerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PatientScannerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; CEA6D6EB261F8D2700715333 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; CEA6D6ED261F8D2700715333 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -174,6 +178,8 @@ children = ( CE13CF0E262DD0D80070C80E /* FullFloatingPanelLayout.swift */, CE13CF22262DDF810070C80E /* RoundedButton.swift */, + CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */, + CEA1556F262F79DE0024B7AC /* InfoCell.swift */, ); path = Components; sourceTree = ""; @@ -410,6 +416,7 @@ CEC2C4C42625ED030056E406 /* Base45.swift in Sources */, CE3CC9442628C2130079FB78 /* CBOR.swift in Sources */, CE13CF0F262DD0D80070C80E /* FullFloatingPanelLayout.swift in Sources */, + CEA1556B262F784E0024B7AC /* SelfSizedTableView.swift in Sources */, CE157F81262E1F7A00FE4821 /* Date.swift in Sources */, CE1BDF99262A4CD600766F97 /* X509.swift in Sources */, CEA1555D262F63B30024B7AC /* EuDgcSchema.swift in Sources */, @@ -422,6 +429,7 @@ CEA15563262F6DAB0024B7AC /* ChildDismissedDelegate.swift in Sources */, CEFAD8722625F29E009AFEF9 /* String+JSON.swift in Sources */, CEC2C4C22625ED030056E406 /* ZLib.swift in Sources */, + CEA15570262F79DE0024B7AC /* InfoCell.swift in Sources */, CEA6D6EE261F8D2700715333 /* SceneDelegate.swift in Sources */, CE157F9B262E2A9F00FE4821 /* SwiftCBOR.CBOR.swift in Sources */, ); diff --git a/PatientScannerDemo/Components/InfoCell.swift b/PatientScannerDemo/Components/InfoCell.swift new file mode 100644 index 0000000..c72de62 --- /dev/null +++ b/PatientScannerDemo/Components/InfoCell.swift @@ -0,0 +1,18 @@ +// +// InfoCell.swift +// PatientScannerDemo +// +// Created by Yannick Spreen on 4/20/21. +// + +import UIKit + +class InfoCell: UITableViewCell { + @IBOutlet weak var headerLabel: UILabel! + @IBOutlet weak var contentLabel: UILabel! + + func draw(_ info: InfoSection) { + headerLabel?.text = info.header + contentLabel?.text = info.content + } +} diff --git a/PatientScannerDemo/Components/SelfSizedTableView.swift b/PatientScannerDemo/Components/SelfSizedTableView.swift new file mode 100644 index 0000000..81cda48 --- /dev/null +++ b/PatientScannerDemo/Components/SelfSizedTableView.swift @@ -0,0 +1,25 @@ +// +// SelfSizedTableView.swift +// PatientScannerDemo +// +// Created by Yannick Spreen on 4/20/21. +// +// https://dushyant37.medium.com/swift-4-recipe-self-sizing-table-view-2635ac3df8ab +// + +import UIKit + +class SelfSizedTableView: UITableView { + var maxHeight: CGFloat = UIScreen.main.bounds.size.height + + override func reloadData() { + super.reloadData() + self.invalidateIntrinsicContentSize() + self.layoutIfNeeded() + } + + override var intrinsicContentSize: CGSize { + let height = min(contentSize.height, maxHeight) + return CGSize(width: contentSize.width, height: height) + } +} diff --git a/PatientScannerDemo/Models/HCert.swift b/PatientScannerDemo/Models/HCert.swift index 4b39e00..cf53f18 100644 --- a/PatientScannerDemo/Models/HCert.swift +++ b/PatientScannerDemo/Models/HCert.swift @@ -9,6 +9,11 @@ import Foundation import SwiftyJSON import JSONSchema +struct InfoSection { + var header: String + var content: String +} + struct HCert { init?(from cborData: Data) { let headerStr = CBOR.header(from: cborData)?.toString() ?? "{}" @@ -100,8 +105,14 @@ struct HCert { var body: JSON var fullName: String { - let first = body["-259"]["1"]["sub"]["gn"].string ?? "" - let last = body["-259"]["1"]["sub"]["fn"].string ?? "" + let first = body["sub"]["gn"].string ?? "" + let last = body["sub"]["fn"].string ?? "" return "\(first) \(last)" } + + var info: [InfoSection] { + [ + InfoSection(header: "Test", content: "Test Test") + ] + } } diff --git a/PatientScannerDemo/Storyboards/CertificateViewer.storyboard b/PatientScannerDemo/Storyboards/CertificateViewer.storyboard index dc5efc0..4e982ae 100644 --- a/PatientScannerDemo/Storyboards/CertificateViewer.storyboard +++ b/PatientScannerDemo/Storyboards/CertificateViewer.storyboard @@ -28,7 +28,7 @@