@@ -13,78 +13,73 @@ struct RelayFilterCellFactory: @preconcurrency CellFactoryProtocol {
13
13
let tableView : UITableView
14
14
15
15
func makeCell( for item: RelayFilterDataSource . Item , indexPath: IndexPath ) -> UITableViewCell {
16
- let cell = tableView. dequeueReusableCell ( withIdentifier: item. reuseIdentifier. rawValue, for: indexPath)
16
+ let cell = tableView. dequeueReusableCell (
17
+ withIdentifier: RelayFilterDataSource . CellReuseIdentifiers. allCases [ indexPath. section] . rawValue,
18
+ for: indexPath
19
+ )
17
20
configureCell ( cell, item: item, indexPath: indexPath)
18
21
19
22
return cell
20
23
}
21
24
22
25
func configureCell( _ cell: UITableViewCell , item: RelayFilterDataSource . Item , indexPath: IndexPath ) {
23
- switch item {
26
+ switch item. type {
24
27
case . ownershipAny, . ownershipOwned, . ownershipRented:
25
- configureOwnershipCell ( cell, item: item)
28
+ configureOwnershipCell ( cell as? SelectableSettingsCell , item: item)
26
29
case . allProviders, . provider:
27
- configureProviderCell ( cell, item: item)
30
+ configureProviderCell ( cell as? CheckableSettingsCell , item: item)
28
31
}
29
32
}
30
33
31
- private func configureOwnershipCell( _ cell: UITableViewCell , item: RelayFilterDataSource . Item ) {
32
- guard let cell = cell as? SelectableSettingsCell else { return }
33
-
34
- var title = " "
35
- switch item {
36
- case . ownershipAny:
37
- title = " Any "
38
- cell. setAccessibilityIdentifier ( . ownershipAnyCell)
39
- case . ownershipOwned:
40
- title = " Mullvad owned only "
41
- cell. setAccessibilityIdentifier ( . ownershipMullvadOwnedCell)
42
- case . ownershipRented:
43
- title = " Rented only "
44
- cell. setAccessibilityIdentifier ( . ownershipRentedCell)
45
- default :
46
- assertionFailure ( " Item mismatch. Got: \( item) " )
47
- }
34
+ private func configureOwnershipCell( _ cell: SelectableSettingsCell ? , item: RelayFilterDataSource . Item ) {
35
+ guard let cell = cell else { return }
48
36
49
37
cell. titleLabel. text = NSLocalizedString (
50
38
" RELAY_FILTER_CELL_LABEL " ,
51
39
tableName: " Relay filter ownership cell " ,
52
- value: title ,
40
+ value: item . name ,
53
41
comment: " "
54
42
)
55
43
44
+ let accessibilityIdentifier : AccessibilityIdentifier
45
+ switch item. type {
46
+ case . ownershipAny:
47
+ accessibilityIdentifier = . ownershipAnyCell
48
+ case . ownershipOwned:
49
+ accessibilityIdentifier = . ownershipMullvadOwnedCell
50
+ case . ownershipRented:
51
+ accessibilityIdentifier = . ownershipRentedCell
52
+ default :
53
+ assertionFailure ( " Unexpected ownership item: \( item) " )
54
+ return
55
+ }
56
+
57
+ cell. setAccessibilityIdentifier ( accessibilityIdentifier)
56
58
cell. applySubCellStyling ( )
57
59
}
58
60
59
- private func configureProviderCell( _ cell: UITableViewCell , item: RelayFilterDataSource . Item ) {
60
- guard let cell = cell as? CheckableSettingsCell else { return }
61
-
62
- let title : String
63
-
64
- switch item {
65
- case . allProviders:
66
- title = " All providers "
67
- setFontWeight ( . semibold, to: cell. titleLabel)
68
- case let . provider( name) :
69
- title = name
70
- setFontWeight ( . regular, to: cell. titleLabel)
71
- default :
72
- title = " "
73
- assertionFailure ( " Item mismatch. Got: \( item) " )
74
- }
61
+ private func configureProviderCell( _ cell: CheckableSettingsCell ? , item: RelayFilterDataSource . Item ) {
62
+ guard let cell = cell else { return }
75
63
76
64
cell. titleLabel. text = NSLocalizedString (
77
65
" RELAY_FILTER_CELL_LABEL " ,
78
66
tableName: " Relay filter provider cell " ,
79
- value: title ,
67
+ value: item . name ,
80
68
comment: " "
81
69
)
82
70
71
+ if item. type == . allProviders {
72
+ setFontWeight ( . semibold, to: cell. titleLabel)
73
+ } else {
74
+ setFontWeight ( . regular, to: cell. titleLabel)
75
+ }
76
+
83
77
cell. applySubCellStyling ( )
84
78
cell. setAccessibilityIdentifier ( . relayFilterProviderCell)
79
+ cell. isEnabled = item. isEnabled
85
80
}
86
81
87
82
private func setFontWeight( _ weight: UIFont . Weight , to label: UILabel ) {
88
- label. font = UIFont . systemFont ( ofSize: label. font. pointSize, weight: . semibold )
83
+ label. font = UIFont . systemFont ( ofSize: label. font. pointSize, weight: weight )
89
84
}
90
85
}
0 commit comments