-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathSettingsCellFactory.swift
97 lines (81 loc) · 3.24 KB
/
SettingsCellFactory.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
//
// SettingsCellFactory.swift
// MullvadVPN
//
// Created by Jon Petersson on 2023-03-09.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import UIKit
struct SettingsCellFactory: CellFactoryProtocol {
let tableView: UITableView
private let interactor: SettingsInteractor
init(tableView: UITableView, interactor: SettingsInteractor) {
self.tableView = tableView
self.interactor = interactor
}
func makeCell(for item: SettingsDataSource.Item, indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: item.reuseIdentifier.rawValue, for: indexPath)
configureCell(cell, item: item, indexPath: indexPath)
return cell
}
// swiftlint:disable:next function_body_length
func configureCell(_ cell: UITableViewCell, item: SettingsDataSource.Item, indexPath: IndexPath) {
switch item {
case .vpnSettings:
guard let cell = cell as? SettingsCell else { return }
cell.titleLabel.text = NSLocalizedString(
"VPN_SETTINGS_CELL_LABEL",
tableName: "Settings",
value: "VPN settings",
comment: ""
)
cell.detailTitleLabel.text = nil
cell.accessibilityIdentifier = item.accessibilityIdentifier
cell.disclosureType = .chevron
case .version:
guard let cell = cell as? SettingsCell else { return }
cell.titleLabel.text = NSLocalizedString(
"APP_VERSION_CELL_LABEL",
tableName: "Settings",
value: "App version",
comment: ""
)
cell.detailTitleLabel.text = Bundle.main.productVersion
cell.accessibilityIdentifier = item.accessibilityIdentifier
cell.disclosureType = .none
case .problemReport:
guard let cell = cell as? SettingsCell else { return }
cell.titleLabel.text = NSLocalizedString(
"REPORT_PROBLEM_CELL_LABEL",
tableName: "Settings",
value: "Report a problem",
comment: ""
)
cell.detailTitleLabel.text = nil
cell.accessibilityIdentifier = item.accessibilityIdentifier
cell.disclosureType = .chevron
case .faq:
guard let cell = cell as? SettingsCell else { return }
cell.titleLabel.text = NSLocalizedString(
"FAQ_AND_GUIDES_CELL_LABEL",
tableName: "Settings",
value: "FAQs & Guides",
comment: ""
)
cell.detailTitleLabel.text = nil
cell.accessibilityIdentifier = item.accessibilityIdentifier
cell.disclosureType = .externalLink
case .apiAccess:
guard let cell = cell as? SettingsCell else { return }
cell.titleLabel.text = NSLocalizedString(
"API_ACCESS_CELL_LABEL",
tableName: "Settings",
value: "API access",
comment: ""
)
cell.detailTitleLabel.text = nil
cell.accessibilityIdentifier = item.accessibilityIdentifier
cell.disclosureType = .chevron
}
}
}