-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathBlockListGroupViewController.swift
98 lines (77 loc) · 3.14 KB
/
BlockListGroupViewController.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// BlockListGroupViewController.swift
// Lockdown
//
// Copyright © 2019 Confirmed Inc. All rights reserved.
//
import UIKit
class BlockListGroupViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {
var lockdownGroup: LockdownGroup?
@IBOutlet var warningContainer: UIView!
@IBOutlet var warningLabel: UILabel!
@IBOutlet var lockdownEnabled: UISwitch!
@IBOutlet var groupTitle: UILabel!
// weak var blockListVC: BlockListViewController?
weak var blockListVC: CuratedListsViewController?
override func viewDidLoad() {
super.viewDidLoad()
if let lockdown = lockdownGroup {
self.groupTitle?.text = lockdown.name
self.lockdownEnabled?.isOn = lockdown.enabled
}
warningLabel.text = lockdownGroup?.warning
if lockdownGroup?.warning != nil {
warningContainer.isHidden = false
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return (lockdownGroup?.domains.count)!
}
return 0
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 32
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView(frame: CGRect.init(x: 0, y: 0, width: tableView.frame.size.width, height: 32))
view.backgroundColor = UIColor.groupTableViewBackground
let label = UILabel(frame: CGRect.init(x: 12, y: 6, width: tableView.frame.size.width, height: 24))
label.font = fontMedium14
label.textColor = UIColor.darkGray
if section == 0 {
label.text = NSLocalizedString("Blocked Domains", comment: "")
}
view.addSubview(label)
return view
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "BlockListGroupCell", for: indexPath) as! BlockListGroupCell
if indexPath.section == 0 {
if let domainKeys = lockdownGroup?.domains {
let keys = domainKeys.keys.sorted {$0 < $1}
cell.cellTitle?.text = keys[indexPath.row]
}
}
return cell
}
@IBAction func toggleLockdown(sender: UISwitch) {
setIsLockdownEnabled(sender.isOn)
}
private func setIsLockdownEnabled(_ isEnabled: Bool) {
if let vc = self.blockListVC {
vc.didMakeChange = true
}
lockdownGroup?.enabled = isEnabled
var ldDefaults = getLockdownBlockedDomains()
ldDefaults.lockdownDefaults[(lockdownGroup?.internalID)!] = lockdownGroup
defaults.set(try? PropertyListEncoder().encode(ldDefaults), forKey: kLockdownBlockedDomains)
}
@IBAction func dismiss() {
blockListVC?.reloadTableView()
self.navigationController?.popViewController(animated: true)
}
}