Skip to content

Commit

Permalink
Add certificate list screens (#7)
Browse files Browse the repository at this point in the history
* Blue color scheme.

* Add wallet viewer.

* Add pages.

* Add code prefetching.

* Set brightness.

* Add data model for certificate storage.

* Add list.
  • Loading branch information
yspreen authored May 3, 2021
1 parent e8eb4e7 commit 83053e8
Show file tree
Hide file tree
Showing 13 changed files with 653 additions and 146 deletions.
20 changes: 20 additions & 0 deletions DGCAWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CE13CF23262DDF810070C80E /* RoundedButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE13CF22262DDF810070C80E /* RoundedButton.swift */; };
CE1D1EF6263597A2004C8919 /* LocalData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE1D1EF5263597A2004C8919 /* LocalData.swift */; };
CE1F155C2639F9E700736D48 /* SwiftyJSON in Frameworks */ = {isa = PBXBuildFile; productRef = CE1F155B2639F9E700736D48 /* SwiftyJSON */; };
CE260F56263DD1720083A200 /* WalletCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE260F55263DD1720083A200 /* WalletCell.swift */; };
CE37B643263867D700DEE13D /* SecureBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE37B642263867D700DEE13D /* SecureBackground.swift */; };
CE56B5052639F48E00FB31B1 /* SwiftDGC in Frameworks */ = {isa = PBXBuildFile; productRef = CE56B5042639F48E00FB31B1 /* SwiftDGC */; };
CE8096D9263B07BB00A65AD6 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE8096D8263B07BB00A65AD6 /* UIColor.swift */; };
Expand All @@ -33,6 +34,10 @@
CEA6D70E261F8D2900715333 /* DGCAWalletUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEA6D70D261F8D2900715333 /* DGCAWalletUITests.swift */; };
CED2726026398683003D47A9 /* UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = CED2725F26398683003D47A9 /* UIFont.swift */; };
CED949CA263B50CE00883558 /* List.swift in Sources */ = {isa = PBXBuildFile; fileRef = CED949C9263B50CE00883558 /* List.swift */; };
CEDABD40263C5FF4007A9B97 /* CertTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDABD3F263C5FF4007A9B97 /* CertTable.swift */; };
CEDABD49263C70EF007A9B97 /* CertPages.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDABD48263C70EF007A9B97 /* CertPages.swift */; };
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 */; };
/* End PBXBuildFile section */

Expand All @@ -59,6 +64,7 @@
CE13CF0E262DD0D80070C80E /* FullFloatingPanelLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullFloatingPanelLayout.swift; sourceTree = "<group>"; };
CE13CF22262DDF810070C80E /* RoundedButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedButton.swift; sourceTree = "<group>"; };
CE1D1EF5263597A2004C8919 /* LocalData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalData.swift; sourceTree = "<group>"; };
CE260F55263DD1720083A200 /* WalletCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletCell.swift; sourceTree = "<group>"; };
CE37B642263867D700DEE13D /* SecureBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureBackground.swift; sourceTree = "<group>"; };
CE8096D8263B07BB00A65AD6 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
CE891304263581D900CB92AF /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = "<group>"; };
Expand All @@ -82,8 +88,12 @@
CEA6D70F261F8D2900715333 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CED2725F26398683003D47A9 /* UIFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIFont.swift; sourceTree = "<group>"; };
CED949C9263B50CE00883558 /* List.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = List.swift; sourceTree = "<group>"; };
CEDABD3F263C5FF4007A9B97 /* CertTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertTable.swift; sourceTree = "<group>"; };
CEDABD48263C70EF007A9B97 /* CertPages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertPages.swift; sourceTree = "<group>"; };
CEDCA7972639E6E700FCB83E /* SwiftDGC */ = {isa = PBXFileReference; lastKnownFileType = folder; name = SwiftDGC; path = "../dgca-app-core-ios"; sourceTree = "<group>"; };
CEDCA79B2639E77800FCB83E /* Package.resolved */ = {isa = PBXFileReference; lastKnownFileType = text; name = Package.resolved; path = DGCAWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved; sourceTree = SOURCE_ROOT; };
CEE9DA54263C7D4000A31532 /* CertCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertCode.swift; sourceTree = "<group>"; };
CEE9DA5C263C865200A31532 /* Brightness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Brightness.swift; sourceTree = "<group>"; };
CEFAD87E262714C4009AFEF9 /* EHNTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EHNTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -130,6 +140,7 @@
isa = PBXGroup;
children = (
CE37B642263867D700DEE13D /* SecureBackground.swift */,
CEE9DA5C263C865200A31532 /* Brightness.swift */,
);
path = Services;
sourceTree = "<group>";
Expand All @@ -149,7 +160,10 @@
CE13CF09262DCDDA0070C80E /* CertificateViewer.swift */,
CED949C9263B50CE00883558 /* List.swift */,
CEA6D6EF261F8D2700715333 /* Scan.swift */,
CEE9DA54263C7D4000A31532 /* CertCode.swift */,
CE891304263581D900CB92AF /* Home.swift */,
CEDABD48263C70EF007A9B97 /* CertPages.swift */,
CEDABD3F263C5FF4007A9B97 /* CertTable.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand All @@ -159,6 +173,7 @@
children = (
CE13CF0E262DD0D80070C80E /* FullFloatingPanelLayout.swift */,
CE13CF22262DDF810070C80E /* RoundedButton.swift */,
CE260F55263DD1720083A200 /* WalletCell.swift */,
CEA1556A262F784E0024B7AC /* SelfSizedTableView.swift */,
CEA1556F262F79DE0024B7AC /* InfoCell.swift */,
);
Expand Down Expand Up @@ -399,19 +414,24 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CEE9DA5D263C865200A31532 /* Brightness.swift in Sources */,
CE13CF0A262DCDDA0070C80E /* CertificateViewer.swift in Sources */,
CEDABD40263C5FF4007A9B97 /* CertTable.swift in Sources */,
CE37B643263867D700DEE13D /* SecureBackground.swift in Sources */,
CE13CF0F262DD0D80070C80E /* FullFloatingPanelLayout.swift in Sources */,
CEA1556B262F784E0024B7AC /* SelfSizedTableView.swift in Sources */,
CE8096D9263B07BB00A65AD6 /* UIColor.swift in Sources */,
CEDABD49263C70EF007A9B97 /* CertPages.swift in Sources */,
CE1D1EF6263597A2004C8919 /* LocalData.swift in Sources */,
CED2726026398683003D47A9 /* UIFont.swift in Sources */,
CEE9DA55263C7D4000A31532 /* CertCode.swift in Sources */,
CEA1555D262F63B30024B7AC /* EuDgcSchema.swift in Sources */,
CEA6D6F0261F8D2700715333 /* Scan.swift in Sources */,
CE13CF23262DDF810070C80E /* RoundedButton.swift in Sources */,
CEA6D6EC261F8D2700715333 /* AppDelegate.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 */,
CEA6D6EE261F8D2700715333 /* SceneDelegate.swift in Sources */,
Expand Down
44 changes: 44 additions & 0 deletions DGCAWallet/Components/WalletCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*-
* ---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
*/
//
// InfoCell.swift
// DGCAWallet
//
// Created by Yannick Spreen on 4/20/21.
//

import UIKit
import SwiftDGC

class WalletCell: UITableViewCell {
@IBOutlet weak var typeLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!

func draw(_ dated: DatedCertString) {
guard let cert = dated.cert else {
return
}

typeLabel.text = cert.certTypeString
nameLabel.text = cert.fullName
dateLabel.text = "scanned \(dated.date.dateString)"
}
}
45 changes: 15 additions & 30 deletions DGCAWallet/Models/LocalData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,38 @@
import Foundation
import SwiftDGC

struct LocalData: Codable {
static var sharedInstance = LocalData()

var encodedPublicKeys = [String: String]()
var resumeToken: String?
var lastFetch_: Date?
var lastFetch: Date {
get {
lastFetch_ ?? .init(timeIntervalSince1970: 0)
}
set(v) {
lastFetch_ = v
}
struct DatedCertString: Codable {
var date: Date
var certString: String
var cert: HCert? {
HCert(from: certString)
}
}

mutating func add(encodedPublicKey: String) {
let kid = KID.from(encodedPublicKey)
let kidStr = KID.string(from: kid)

encodedPublicKeys[kidStr] = encodedPublicKey
}
struct LocalData: Codable {
static var sharedInstance = LocalData()

static func set(resumeToken: String) {
sharedInstance.resumeToken = resumeToken
}
var certStrings = [DatedCertString]()

public func save() {
Self.storage.save(self)
}

public static func add(_ cert: HCert) {
sharedInstance.certStrings.append(.init(date: Date(), certString: cert.payloadString))
sharedInstance.save()
}

static let storage = SecureStorage<LocalData>()

static func initialize(completion: @escaping () -> Void) {
storage.loadOverride(fallback: LocalData.sharedInstance) { success in
guard let result = success else {
return
}
print("\(result.encodedPublicKeys.count) certs loaded.")
print("\(result.certStrings.count) certs loaded.")
LocalData.sharedInstance = result
completion()
}
HCert.publicKeyStorageDelegate = LocalDataDelegate()
}
}

struct LocalDataDelegate: PublicKeyStorageDelegate {
func getEncodedPublicKey(for kidStr: String) -> String? {
LocalData.sharedInstance.encodedPublicKeys[kidStr]
}
}
54 changes: 54 additions & 0 deletions DGCAWallet/Services/Brightness.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
/*-
* ---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
*/
//
// Brightness.swift
// DGCAWallet
//
// Created by Yannick Spreen on 4/30/21.
//


import Foundation
import UIKit

struct Brightness {
static var fallback: CGFloat?

static func setTo(_ val: CGFloat) {
UIScreen.main.brightness = val
}

public static func forceFull() {
if fallback != nil {
return
}
fallback = UIScreen.main.brightness
setTo(1.0)
}

public static func reset() {
guard let val = fallback else {
return
}
fallback = nil
setTo(val)
}
}
Loading

0 comments on commit 83053e8

Please sign in to comment.