COVIDSafe code from version 2.0 (#37)

This commit is contained in:
COVIDSafe Support 2020-12-19 16:13:44 +11:00 committed by GitHub
parent cf93ea43c0
commit 8b75c1fc6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 4624 additions and 1117 deletions

View file

@ -0,0 +1,73 @@
//
// CSGenericContentViewController.swift
// CovidSafe
//
// Copyright © 2020 Australian Government. All rights reserved.
//
import UIKit
import SafariServices
class CSGenericContentViewController: UIViewController {
@IBOutlet weak var stepCounterLabel: UILabel!
@IBOutlet weak var contentIllustration: UIImageView!
@IBOutlet weak var contentTitleLabel: UILabel!
@IBOutlet weak var contentDescriptionText: UITextView!
@IBOutlet weak var actionButton: UIButton!
var contentViewModel: CSGenericContentViewModel?
override func viewDidLoad() {
super.viewDidLoad()
guard let viewModel = contentViewModel else {
return
}
// set the step counter
if let contentStep = viewModel.contentStepNumber, let contentTotal = viewModel.contentStepTotal {
stepCounterLabel.text = String.localizedStringWithFormat( "stepCounter".localizedString(),
contentStep,
contentTotal
)
} else {
stepCounterLabel.text = ""
stepCounterLabel.isHidden = true
}
// set the illustration
if let illustration = viewModel.contentIllustration {
contentIllustration.image = illustration
}
// set title and content
contentTitleLabel.text = viewModel.viewTitle
contentDescriptionText.attributedText = viewModel.viewContentDescription
contentDescriptionText.parseHTMLTags()
contentDescriptionText.addAllBold(enclosedIn: "#")
//set button label and action
actionButton.setTitle(viewModel.buttonLabel, for: .normal)
actionButton.addTarget(self, action: #selector(pressed), for: .touchUpInside)
}
@objc func pressed(sender: UIButton!) {
guard let viewModel = contentViewModel else {
return
}
viewModel.buttonCallback()
}
}
struct CSGenericContentViewModel {
var viewTitle: String
var viewContentDescription: NSAttributedString
var buttonLabel: String
var buttonCallback: () -> Void
var contentIllustration: UIImage?
var contentStepNumber: Int?
var contentStepTotal: Int?
}