SettingsViewController.swift
3.7 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
//
// SettingsViewController.swift
// InterQR-Internship
//
// Created by Дмитрий Тимофеев on 08.06.2022.
//
import UIKit
class SettingsViewController: UIViewController {
var mainView = SettingsView()
var networkManager = AuthService()
let settingsModel = SettingsModel.allCases
override func loadView() {
view = mainView
}
override func viewDidLoad() {
super.viewDidLoad()
initViewController()
}
private func initViewController() {
mainView.settingsTableView.delegate = self
mainView.settingsTableView.dataSource = self
mainView.settingsTableView.registerReusableCell(DisplayNameCell.self)
mainView.settingsTableView.registerReusableCell(SettingsSwitchCell.self)
mainView.settingsTableView.registerReusableCell(SettingsTableViewCell.self)
mainView.backButton.addTarget(self, action: #selector(didShowHomeVC), for: .touchUpInside)
mainView.logoutButton.addTarget(self, action: #selector(didLogoutAndShowVerificationVC), for: .touchUpInside)
}
}
//MARK: - Delegate
extension SettingsViewController {
@objc private func didShowHomeVC() {
navigationController?.popViewController(animated: true)
}
@objc private func didLogoutAndShowVerificationVC() {
networking()
let vc = VerificationViewController()
navigationController?.pushViewController(vc, animated: true)
}
func networking() {
guard let logoutModel = logoutModelFilling() else { return }
AuthService.share.logoutRequest(model: logoutModel) { response in
print("5️⃣❇️\(response.message ?? "Data not received!")❇️")
} fail: { error in
print("5️⃣❗️\(error)❗️")
}
}
func logoutModelFilling() -> LogoutRequestModel? {
guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {
return nil
}
return LogoutRequestModel(deviceUUID: deviceUUID)
}
}
//MARK: tableView delegate and datasource
extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return settingsModel.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = indexPath.row
let model: SettingsModel = settingsModel[row]
switch model {
case .displayName:
let cell: DisplayNameCell = tableView.dequeueReusableCell(for: indexPath)
cell.titleLabel.text = model.getTitle()
cell.descriptionLabel.text = model.getDescription()
cell.settingsIcon.image = model.getIcon()
return cell
case .doNotDisturb, .ringtone:
let cell: SettingsSwitchCell = tableView.dequeueReusableCell(for: indexPath)
cell.titleLabel.text = model.getTitle()
cell.descriptionLabel.text = model.getDescription()
cell.settingsIcon.image = model.getIcon()
return cell
case .editResidents, .widgetLock:
let cell: SettingsTableViewCell = tableView.dequeueReusableCell(for: indexPath)
cell.titleLabel.text = model.getTitle()
cell.descriptionLabel.text = model.getDescription()
cell.settingsIcon.image = model.getIcon()
return cell
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 3 {
let vc = ChooseApartmentsViewController()
navigationController?.pushViewController(vc, animated: true)
}
}
}