@@ -13,78 +13,77 @@ 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 }
63
+ let alpha = item. isEnabled ? 1.0 : 0.5
75
64
76
65
cell. titleLabel. text = NSLocalizedString (
77
66
" RELAY_FILTER_CELL_LABEL " ,
78
67
tableName: " Relay filter provider cell " ,
79
- value: title ,
68
+ value: item . name ,
80
69
comment: " "
81
70
)
71
+ cell. detailTitleLabel. text = item. description
72
+
73
+ if item. type == . allProviders {
74
+ setFontWeight ( . semibold, to: cell. titleLabel)
75
+ } else {
76
+ setFontWeight ( . regular, to: cell. titleLabel)
77
+ }
82
78
83
79
cell. applySubCellStyling ( )
84
80
cell. setAccessibilityIdentifier ( . relayFilterProviderCell)
81
+ cell. titleLabel. alpha = alpha
82
+ cell. detailTitleLabel. alpha = alpha
83
+ cell. detailTitleLabel. textColor = cell. titleLabel. textColor
85
84
}
86
85
87
86
private func setFontWeight( _ weight: UIFont . Weight , to label: UILabel ) {
88
- label. font = UIFont . systemFont ( ofSize: label. font. pointSize, weight: . semibold )
87
+ label. font = UIFont . systemFont ( ofSize: label. font. pointSize, weight: weight )
89
88
}
90
89
}
0 commit comments