-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathRequirePasscodeIntervalViewController.swift
77 lines (62 loc) · 3.03 KB
/
RequirePasscodeIntervalViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
import Shared
import SwiftKeychainWrapper
/// Screen presented to the user when selecting the time interval before requiring a passcode
class RequirePasscodeIntervalViewController: UITableViewController {
let intervalOptions: [PasscodeInterval] = [
.immediately,
.oneMinute,
.fiveMinutes,
.tenMinutes,
.fifteenMinutes,
.oneHour
]
fileprivate let BasicCheckmarkCell = "BasicCheckmarkCell"
fileprivate var authenticationInfo: AuthenticationKeychainInfo?
init() {
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
title = AuthenticationStrings.requirePasscode
tableView.accessibilityIdentifier = "AuthenticationManager.passcodeIntervalTableView"
tableView.register(UITableViewCell.self, forCellReuseIdentifier: BasicCheckmarkCell)
tableView.backgroundColor = SettingsUX.TableViewHeaderBackgroundColor
let headerFooterFrame = CGRect(width: self.view.frame.width, height: SettingsUX.TableViewHeaderFooterHeight)
let headerView = SettingsTableSectionHeaderFooterView(frame: headerFooterFrame)
headerView.showTopBorder = false
headerView.showBottomBorder = true
let footerView = SettingsTableSectionHeaderFooterView(frame: headerFooterFrame)
footerView.showTopBorder = true
footerView.showBottomBorder = false
tableView.tableHeaderView = headerView
tableView.tableFooterView = footerView
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.authenticationInfo = KeychainWrapper.sharedAppContainerKeychain.authenticationInfo()
tableView.reloadData()
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: BasicCheckmarkCell, for: indexPath)
let option = intervalOptions[indexPath.row]
let intervalTitle = NSAttributedString.tableRowTitle(option.settingTitle, enabled: true)
cell.textLabel?.attributedText = intervalTitle
cell.accessoryType = authenticationInfo?.requiredPasscodeInterval == option ? .checkmark : .none
return cell
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return intervalOptions.count
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
authenticationInfo?.updateRequiredPasscodeInterval(intervalOptions[indexPath.row])
KeychainWrapper.sharedAppContainerKeychain.setAuthenticationInfo(authenticationInfo)
tableView.reloadData()
}
}