@@ -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
}
@@ -115,9 +130,19 @@ import Foundation
115
130
}
116
131
117
132
@IBAction func onSaveAndExitTap( _ sender: Any ) {
118
- let actionType : SPActionType = ( snapshot? . consentStatus == . RejectedAll) ? . RejectAll : . AcceptAll
133
+ var actionType : SPActionType
134
+ switch snapshot. consentStatus {
135
+ case . RejectedSome: actionType = . SaveAndExit
136
+ case . RejectedAll: actionType = . RejectAll
137
+ case . ConsentedAll, . RejectedNone: actionType = . AcceptAll
138
+ }
139
+
119
140
action (
120
- SPAction ( type: actionType, campaignType: campaignType) ,
141
+ SPAction (
142
+ type: actionType,
143
+ campaignType: campaignType,
144
+ pmPayload: snapshot. toPayload ( language: . English, pmId: messageId) . json ( ) ?? SPJson ( )
145
+ ) ,
121
146
from: self
122
147
)
123
148
}
@@ -139,15 +164,13 @@ import Foundation
139
164
delegate: self ,
140
165
nibName: " SPCCPAManagePreferenceViewController "
141
166
)
142
- if self ? . snapshot == nil {
143
- self ? . snapshot = CCPAPMConsentSnaptshot (
144
- vendors: Set < CCPAVendor > ( data. vendors) ,
145
- categories: Set < CCPACategory > ( data. categories) ,
146
- rejectedVendors: data. rejectedVendors,
147
- rejectedCategories: data. rejectedCategories,
148
- consentStatus: data. consentStatus
149
- )
150
- }
167
+ self ? . snapshot = CCPAPMConsentSnaptshot (
168
+ vendors: Set < CCPAVendor > ( data. vendors) ,
169
+ categories: Set < CCPACategory > ( data. categories) ,
170
+ rejectedVendors: data. rejectedVendors,
171
+ rejectedCategories: data. rejectedCategories,
172
+ consentStatus: data. consentStatus
173
+ )
151
174
controller. categories = data. categories
152
175
controller. consentsSnapshot = strongSelf. snapshot!
153
176
self ? . present ( controller, animated: true )
@@ -164,15 +187,6 @@ import Foundation
164
187
delegate: self ,
165
188
nibName: " SPManagePreferenceViewController "
166
189
)
167
- if snapshot == nil {
168
- snapshot = CCPAPMConsentSnaptshot (
169
- vendors: Set < CCPAVendor > ( secondLayerData. vendors) ,
170
- categories: Set < CCPACategory > ( secondLayerData. categories) ,
171
- rejectedVendors: secondLayerData. rejectedVendors,
172
- rejectedCategories: secondLayerData. rejectedCategories,
173
- consentStatus: secondLayerData. consentStatus
174
- )
175
- }
176
190
controller. categories = secondLayerData. categories
177
191
controller. consentsSnapshot = snapshot!
178
192
present ( controller, animated: true )
@@ -185,14 +199,12 @@ import Foundation
185
199
self ? . onError ( error)
186
200
case . success( let data) :
187
201
if let strongSelf = self {
188
- if self ? . snapshot == nil {
189
- self ? . snapshot = CCPAPMConsentSnaptshot (
190
- vendors: Set < CCPAVendor > ( data. vendors) ,
191
- categories: Set < CCPACategory > ( data. categories) ,
192
- rejectedVendors: data. rejectedVendors,
193
- rejectedCategories: data. rejectedCategories, consentStatus: data. consentStatus
194
- )
195
- }
202
+ self ? . snapshot = CCPAPMConsentSnaptshot (
203
+ vendors: Set < CCPAVendor > ( data. vendors) ,
204
+ categories: Set < CCPACategory > ( data. categories) ,
205
+ rejectedVendors: data. rejectedVendors,
206
+ rejectedCategories: data. rejectedCategories, consentStatus: data. consentStatus
207
+ )
196
208
let controller = SPCCPAPartnersViewController (
197
209
messageId: strongSelf. messageId,
198
210
campaignType: strongSelf. campaignType,
@@ -264,7 +276,7 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDataSource {
264
276
cell. labelText = doNotSellButton? . settings. text
265
277
cell. selectable = false
266
278
cell. isCustom = false
267
- cell. isOn = snapshot? . consentStatus == . RejectedAll
279
+ cell. isOn = snapshot. consentStatus == . RejectedAll
268
280
cell. setup ( from: doNotSellButton)
269
281
cell. loadUI ( )
270
282
return cell
@@ -282,6 +294,6 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDelegate {
282
294
}
283
295
284
296
func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
285
- snapshot? . onDoNotSellToggle ( )
297
+ snapshot. onDoNotSellToggle ( )
286
298
}
287
299
}
0 commit comments