mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-19 21:15:21 +00:00
COVIDSafe code from version 2.4 (#45)
This commit is contained in:
parent
f14aa60482
commit
377bc0009b
63 changed files with 3096 additions and 372 deletions
|
@ -9,20 +9,13 @@ import UIKit
|
|||
|
||||
let statisticsStateTerritorySelectedKey = "statisticsStateTerritorySelectedKey"
|
||||
|
||||
class SelectStateTerritoryViewController: UITableViewController {
|
||||
class SelectableTableViewController<T>: UITableViewController where T:SimpleCellObject {
|
||||
|
||||
var delegate: StateTerritorySelectionDelegate?
|
||||
var delegate: TableSelectionDelegate?
|
||||
|
||||
lazy var stateTerritoryConfig: StateTerritory = {
|
||||
guard let value = UserDefaults.standard.string(forKey: statisticsStateTerritorySelectedKey) else {
|
||||
return StateTerritory.AU
|
||||
}
|
||||
return StateTerritory(rawValue: value)!
|
||||
}(){
|
||||
didSet {
|
||||
UserDefaults.standard.set(stateTerritoryConfig.rawValue, forKey: statisticsStateTerritorySelectedKey)
|
||||
}
|
||||
}
|
||||
var selectedValue: T?
|
||||
var data:[[T]] = []
|
||||
var sectionTitles: [String] = []
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
@ -50,16 +43,17 @@ class SelectStateTerritoryViewController: UITableViewController {
|
|||
}
|
||||
|
||||
// MARK: - Table view data source
|
||||
|
||||
fileprivate func getNumberOfSections() -> Int {
|
||||
return data.count
|
||||
}
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 2
|
||||
return getNumberOfSections()
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
if section == 0 {
|
||||
return 1
|
||||
}
|
||||
return 8
|
||||
return data[section].count
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,86 +61,74 @@ class SelectStateTerritoryViewController: UITableViewController {
|
|||
let cell = tableView.dequeueReusableCell(withIdentifier: "StateTerritoryCell", for: indexPath) as! StateTerritoryTableViewCell
|
||||
|
||||
// Configure the cell...
|
||||
if indexPath.section == 0 {
|
||||
cell.stateTerritoryLabel.text = "country_region_name_au".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.AU
|
||||
} else {
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
cell.stateTerritoryLabel.text = "australian_capital_territory".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.ACT
|
||||
case 1:
|
||||
cell.stateTerritoryLabel.text = "new_south_wales".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.NSW
|
||||
case 2:
|
||||
cell.stateTerritoryLabel.text = "northern_territory".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.NT
|
||||
case 3:
|
||||
cell.stateTerritoryLabel.text = "queensland".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.QLD
|
||||
case 4:
|
||||
cell.stateTerritoryLabel.text = "south_australia".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.SA
|
||||
case 5:
|
||||
cell.stateTerritoryLabel.text = "tasmania".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.TAS
|
||||
case 6:
|
||||
cell.stateTerritoryLabel.text = "victoria".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.VIC
|
||||
case 7:
|
||||
cell.stateTerritoryLabel.text = "western_australia".localizedString()
|
||||
cell.isSelectedTickView.isHidden = stateTerritoryConfig != StateTerritory.WA
|
||||
default:
|
||||
cell.stateTerritoryLabel.text = ""
|
||||
cell.setSelected(false, animated: false)
|
||||
}
|
||||
}
|
||||
let sectionValues = data[indexPath.section]
|
||||
let rowValue = sectionValues[indexPath.row]
|
||||
|
||||
cell.stateTerritoryLabel.text = rowValue.getCellTitle()
|
||||
cell.isSelectedTickView.isHidden = selectedValue?.getCellTitle() != rowValue.getCellTitle()
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
if section == 0 {
|
||||
return nil
|
||||
if sectionTitles.count > section {
|
||||
return sectionTitles[section]
|
||||
}
|
||||
|
||||
return "states_territories".localizedString()
|
||||
return nil
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
if indexPath.section == 0 {
|
||||
stateTerritoryConfig = StateTerritory.AU
|
||||
} else {
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
stateTerritoryConfig = StateTerritory.ACT
|
||||
case 1:
|
||||
stateTerritoryConfig = StateTerritory.NSW
|
||||
case 2:
|
||||
stateTerritoryConfig = StateTerritory.NT
|
||||
case 3:
|
||||
stateTerritoryConfig = StateTerritory.QLD
|
||||
case 4:
|
||||
stateTerritoryConfig = StateTerritory.SA
|
||||
case 5:
|
||||
stateTerritoryConfig = StateTerritory.TAS
|
||||
case 6:
|
||||
stateTerritoryConfig = StateTerritory.VIC
|
||||
case 7:
|
||||
stateTerritoryConfig = StateTerritory.WA
|
||||
default:
|
||||
stateTerritoryConfig = StateTerritory.AU
|
||||
}
|
||||
}
|
||||
delegate?.didChangeStateTerritory(selectedState: stateTerritoryConfig)
|
||||
|
||||
let sectionValues = data[indexPath.section]
|
||||
let selectedValue = sectionValues[indexPath.row]
|
||||
|
||||
delegate?.didChangeSelectedValue(selectedValue: selectedValue)
|
||||
dismissView()
|
||||
}
|
||||
}
|
||||
|
||||
protocol SimpleCellObject {
|
||||
func getCellTitle() -> String
|
||||
}
|
||||
|
||||
enum StateTerritory: String {
|
||||
case AU, ACT, NSW, NT, QLD, SA, TAS, VIC, WA
|
||||
}
|
||||
|
||||
protocol StateTerritorySelectionDelegate {
|
||||
func didChangeStateTerritory( selectedState: StateTerritory )
|
||||
extension StateTerritory {
|
||||
|
||||
func stateTerritoryFullName() -> String {
|
||||
switch self {
|
||||
case .ACT:
|
||||
return "australian_capital_territory".localizedString()
|
||||
case .NSW:
|
||||
return "new_south_wales".localizedString()
|
||||
case .NT:
|
||||
return "northern_territory".localizedString()
|
||||
case .QLD:
|
||||
return "queensland".localizedString()
|
||||
case .SA:
|
||||
return "south_australia".localizedString()
|
||||
case .TAS:
|
||||
return "tasmania".localizedString()
|
||||
case .VIC:
|
||||
return "victoria".localizedString()
|
||||
case .WA:
|
||||
return "western_australia".localizedString()
|
||||
default:
|
||||
return "country_region_name_au".localizedString()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension StateTerritory: SimpleCellObject {
|
||||
|
||||
func getCellTitle() -> String {
|
||||
return stateTerritoryFullName()
|
||||
}
|
||||
}
|
||||
|
||||
protocol TableSelectionDelegate {
|
||||
func didChangeSelectedValue( selectedValue: Any )
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue