RemoveAdvertViewController.swift
3.21 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
//
// RemoveAdvertViewController.swift
// browser
//
// Created by Artem Talko on 27.09.2023.
//
import UIKit
final class RemoveAdvertViewController: UIViewController {
private let mainView = RemoveAdvertView()
private let removeTableViewCellsData: [String]
override func viewDidLoad() {
super.viewDidLoad()
initViewController()
}
private func initViewController() {
view.backgroundColor = ColorConstants.lightGray
setupTableView()
addTargets()
}
override func loadView() {
view = mainView
}
init() {
removeTableViewCellsData = StringConstants.removeAdvertTableViewData
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//MARK: - Table View
extension RemoveAdvertViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return removeTableViewCellsData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: RemoveAdvertTableViewCell.cellID) as?
RemoveAdvertTableViewCell else {
return UITableViewCell()
}
cell.advantagesCellLabel.text = removeTableViewCellsData[indexPath.row]
cell.selectionStyle = .none
return cell
}
}
//MARK: - Action
extension RemoveAdvertViewController {
@objc
private func shieldButtonTapped(_ sender: UIButton) {
UIView.animate(withDuration: 0.2) {
sender.transform = CGAffineTransform(scaleX: 1.1, y: 1.1)
sender.alpha = 0.7
}
let userDefaultsAdBlockerValue = CachingManager.shared.isAdBlocking
if userDefaultsAdBlockerValue {
mainView.shieldView.setImage(.shieldInactive, for: .normal)
mainView.tapActionLabel.text = StringConstants.turnOff
CachingManager.shared.isAdBlocking = false
} else {
mainView.shieldView.setImage(.shieldActive, for: .normal)
mainView.tapActionLabel.text = StringConstants.turnOn
CachingManager.shared.isAdBlocking = true
}
UIView.animate(withDuration: 0.2, delay: 0.2) {
sender.transform = .identity
sender.alpha = 1.0
}
}
@objc
private func closeViewController(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
}
//MARK: Helpers
extension RemoveAdvertViewController {
private func addTargets() {
mainView.shieldView.addTarget(self, action: #selector(shieldButtonTapped(_ :)), for: .touchUpInside)
mainView.closeButton.addTarget(self, action: #selector(closeViewController(_ :)), for: .touchUpInside)
}
private func setupTableView() {
mainView.advantagesTableView.dataSource = self
mainView.advantagesTableView.delegate = self
mainView.advantagesTableView.register(RemoveAdvertTableViewCell.self, forCellReuseIdentifier: RemoveAdvertTableViewCell.cellID)
}
}