-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPasscodeView.swift
More file actions
116 lines (88 loc) · 3.23 KB
/
Copy pathPasscodeView.swift
File metadata and controls
116 lines (88 loc) · 3.23 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Copyright (c) 2026 Related Code - https://relatedcode.com
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import UIKit
class PasscodeView: UIViewController {
@IBOutlet private var tableView: UITableView!
@IBOutlet private var cellTurnPasscode: UITableViewCell!
@IBOutlet private var cellChangePasscode: UITableViewCell!
@IBOutlet private var cellBiometric: UITableViewCell!
@IBOutlet private var switchBiometric: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
title = "Passcode"
switchBiometric.addTarget(self, action: #selector(actionBiometric), for: .valueChanged)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateViewDetails()
}
}
// MARK: - User actions
extension PasscodeView {
func actionTurnPasscode() {
if (PasscodeKit.enabled()) {
PasscodeKit.removePasscode(self)
} else {
PasscodeKit.createPasscode(self)
}
}
func actionChangePasscode() {
if (PasscodeKit.enabled()) {
PasscodeKit.changePasscode(self)
}
}
@objc func actionBiometric() {
PasscodeKit.biometric(switchBiometric.isOn)
}
}
// MARK: - Helper methods
extension PasscodeView {
func updateViewDetails() {
if (PasscodeKit.enabled()) {
cellTurnPasscode.textLabel?.text = "Turn Passcode Off"
cellChangePasscode.textLabel?.textColor = UIColor.systemBlue
} else {
cellTurnPasscode.textLabel?.text = "Turn Passcode On"
cellChangePasscode.textLabel?.textColor = UIColor.lightGray
}
switchBiometric.isOn = PasscodeKit.biometric()
tableView.reloadData()
}
}
// MARK: - UITableViewDataSource
extension PasscodeView: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return PasscodeKit.enabled() ? 2 : 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0) { return 2 }
if (section == 1) { return 1 }
return 0
}
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if (section == 1) { return "Allow to use Face ID (or Touch ID) to unlock the app." }
return nil
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0) && (indexPath.row == 0) { return cellTurnPasscode }
if (indexPath.section == 0) && (indexPath.row == 1) { return cellChangePasscode }
if (indexPath.section == 1) && (indexPath.row == 0) { return cellBiometric }
return UITableViewCell()
}
}
// MARK: - UITableViewDelegate
extension PasscodeView: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if (indexPath.section == 0) && (indexPath.row == 0) { actionTurnPasscode() }
if (indexPath.section == 0) && (indexPath.row == 1) { actionChangePasscode() }
}
}