@@ -26,14 +26,15 @@ import Foundation
26
26
27
27
var doNotSellButton : SPNativeLongButton ?
28
28
29
+ var ccpaConsents : SPCCPAConsent ?
30
+ private var snapshot : CCPAPMConsentSnaptshot !
31
+
29
32
@IBOutlet weak var header : SPPMHeader !
30
33
31
34
var secondLayerData : CCPAPrivacyManagerViewResponse ?
32
35
33
36
let cellReuseIdentifier = " cell "
34
37
35
- var snapshot : CCPAPMConsentSnaptshot ?
36
-
37
38
override var preferredFocusedView : UIView ? { acceptButton }
38
39
39
40
override func setFocusGuides( ) {
@@ -55,8 +56,32 @@ import Foundation
55
56
loaded ( self )
56
57
}
57
58
59
+ func setDoNotSellButton( ) {
60
+ doNotSellButton = viewData. byId ( " DoNotSellButton " ) as? SPNativeLongButton
61
+ doNotSellTableView. register (
62
+ UINib ( nibName: " LongButtonViewCell " , bundle: Bundle . framework) ,
63
+ forCellReuseIdentifier: cellReuseIdentifier
64
+ )
65
+ doNotSellTableView. allowsSelection = true
66
+ doNotSellTableView. delegate = self
67
+ doNotSellTableView. dataSource = self
68
+ }
69
+
70
+ func initConsentsSnapshot( ) {
71
+ snapshot = CCPAPMConsentSnaptshot (
72
+ vendors: [ ] ,
73
+ categories: [ ] ,
74
+ rejectedVendors: ccpaConsents? . rejectedVendors,
75
+ rejectedCategories: ccpaConsents? . rejectedCategories,
76
+ consentStatus: ccpaConsents? . status)
77
+ snapshot. onConsentsChange = { [ weak self] in
78
+ self ? . doNotSellTableView. reloadData ( )
79
+ }
80
+ }
81
+
58
82
override func viewDidLoad( ) {
59
83
super. viewDidLoad ( )
84
+ initConsentsSnapshot ( )
60
85
setHeader ( )
61
86
loadTextView ( forComponentId: " PublisherDescription " , textView: descriptionTextView, bounces: false )
62
87
descriptionTextView. flashScrollIndicators ( )
@@ -67,17 +92,7 @@ import Foundation
67
92
loadButton ( forComponentId: " NavVendorsButton " , button: ourPartners)
68
93
loadButton ( forComponentId: " NavPrivacyPolicyButton " , button: privacyPolicyButton)
69
94
loadImage ( forComponentId: " LogoImage " , imageView: logoImageView)
70
- doNotSellButton = viewData. byId ( " DoNotSellButton " ) as? SPNativeLongButton
71
- doNotSellTableView. register (
72
- UINib ( nibName: " LongButtonViewCell " , bundle: Bundle . framework) ,
73
- forCellReuseIdentifier: cellReuseIdentifier
74
- )
75
- doNotSellTableView. allowsSelection = true
76
- doNotSellTableView. delegate = self
77
- doNotSellTableView. dataSource = self
78
- snapshot? . onConsentsChange = { [ weak self] in
79
- self ? . doNotSellTableView. reloadData ( )
80
- }
95
+ setDoNotSellButton ( )
81
96
setFocusGuidesForButtons ( )
82
97
disableMenuButton ( )
83
98
}
@@ -118,9 +133,19 @@ import Foundation
118
133
}
119
134
120
135
@IBAction func onSaveAndExitTap( _ sender: Any ) {
121
- let actionType : SPActionType = ( snapshot? . consentStatus == . RejectedAll) ? . RejectAll : . AcceptAll
136
+ var actionType : SPActionType
137
+ switch snapshot. consentStatus {
138
+ case . RejectedSome: actionType = . SaveAndExit
139
+ case . RejectedAll: actionType = . RejectAll
140
+ case . ConsentedAll, . RejectedNone: actionType = . AcceptAll
141
+ }
142
+
122
143
action (
123
- SPAction ( type: actionType, campaignType: campaignType) ,
144
+ SPAction (
145
+ type: actionType,
146
+ campaignType: campaignType,
147
+ pmPayload: snapshot. toPayload ( language: . English, pmId: messageId) . json ( ) ?? SPJson ( )
148
+ ) ,
124
149
from: self
125
150
)
126
151
}
@@ -142,15 +167,13 @@ import Foundation
142
167
delegate: self ,
143
168
nibName: " SPCCPAManagePreferenceViewController "
144
169
)
145
- if self ? . snapshot == nil {
146
- self ? . snapshot = CCPAPMConsentSnaptshot (
147
- vendors: Set < CCPAVendor > ( data. vendors) ,
148
- categories: Set < CCPACategory > ( data. categories) ,
149
- rejectedVendors: data. rejectedVendors,
150
- rejectedCategories: data. rejectedCategories,
151
- consentStatus: data. consentStatus
152
- )
153
- }
170
+ self ? . snapshot = CCPAPMConsentSnaptshot (
171
+ vendors: Set < CCPAVendor > ( data. vendors) ,
172
+ categories: Set < CCPACategory > ( data. categories) ,
173
+ rejectedVendors: data. rejectedVendors,
174
+ rejectedCategories: data. rejectedCategories,
175
+ consentStatus: data. consentStatus
176
+ )
154
177
controller. categories = data. categories
155
178
controller. consentsSnapshot = strongSelf. snapshot!
156
179
self ? . present ( controller, animated: true )
@@ -167,15 +190,6 @@ import Foundation
167
190
delegate: self ,
168
191
nibName: " SPManagePreferenceViewController "
169
192
)
170
- if snapshot == nil {
171
- snapshot = CCPAPMConsentSnaptshot (
172
- vendors: Set < CCPAVendor > ( secondLayerData. vendors) ,
173
- categories: Set < CCPACategory > ( secondLayerData. categories) ,
174
- rejectedVendors: secondLayerData. rejectedVendors,
175
- rejectedCategories: secondLayerData. rejectedCategories,
176
- consentStatus: secondLayerData. consentStatus
177
- )
178
- }
179
193
controller. categories = secondLayerData. categories
180
194
controller. consentsSnapshot = snapshot!
181
195
present ( controller, animated: true )
@@ -188,14 +202,12 @@ import Foundation
188
202
self ? . onError ( error)
189
203
case . success( let data) :
190
204
if let strongSelf = self {
191
- if self ? . snapshot == nil {
192
- self ? . snapshot = CCPAPMConsentSnaptshot (
193
- vendors: Set < CCPAVendor > ( data. vendors) ,
194
- categories: Set < CCPACategory > ( data. categories) ,
195
- rejectedVendors: data. rejectedVendors,
196
- rejectedCategories: data. rejectedCategories, consentStatus: data. consentStatus
197
- )
198
- }
205
+ self ? . snapshot = CCPAPMConsentSnaptshot (
206
+ vendors: Set < CCPAVendor > ( data. vendors) ,
207
+ categories: Set < CCPACategory > ( data. categories) ,
208
+ rejectedVendors: data. rejectedVendors,
209
+ rejectedCategories: data. rejectedCategories, consentStatus: data. consentStatus
210
+ )
199
211
let controller = SPCCPAPartnersViewController (
200
212
messageId: strongSelf. messageId,
201
213
campaignType: strongSelf. campaignType,
@@ -267,7 +279,7 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDataSource {
267
279
cell. labelText = doNotSellButton? . settings. text
268
280
cell. selectable = false
269
281
cell. isCustom = false
270
- cell. isOn = snapshot? . consentStatus == . RejectedAll
282
+ cell. isOn = snapshot. consentStatus == . RejectedAll
271
283
cell. setup ( from: doNotSellButton)
272
284
cell. loadUI ( )
273
285
return cell
@@ -285,6 +297,6 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDelegate {
285
297
}
286
298
287
299
func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
288
- snapshot? . onDoNotSellToggle ( )
300
+ snapshot. onDoNotSellToggle ( )
289
301
}
290
302
}
0 commit comments