@@ -6,17 +6,17 @@ extension UIColor {
6
6
if hex. hasPrefix ( " # " ) {
7
7
let start = hex. index ( hex. startIndex, offsetBy: 1 )
8
8
let hexColor = String ( hex [ start... ] )
9
-
9
+
10
10
if hexColor. count == 8 {
11
11
let scanner = Scanner ( string: hexColor)
12
12
var hexNumber : UInt64 = 0
13
-
13
+
14
14
if scanner. scanHexInt64 ( & hexNumber) {
15
15
r = CGFloat ( ( hexNumber & 0xff000000 ) >> 24 ) / 255
16
16
g = CGFloat ( ( hexNumber & 0x00ff0000 ) >> 16 ) / 255
17
17
b = CGFloat ( ( hexNumber & 0x0000ff00 ) >> 8 ) / 255
18
18
a = CGFloat ( hexNumber & 0x000000ff ) / 255
19
-
19
+
20
20
self . init ( red: r, green: g, blue: b, alpha: a)
21
21
return
22
22
}
@@ -53,7 +53,7 @@ public struct ConsentStyleConfiguration {
53
53
let barBackgroundOpacity = ( json [ \. bar_background_opacity_percentage] . double ?? 100.0 ) / 100.0
54
54
let buttonBackgroundColor = json [ \. bar_text_color] . string ?? " #FFFFFF "
55
55
let buttonTextColor = json [ \. button_text_color] . string ?? " #000000 "
56
-
56
+
57
57
let it = json [ \. consent_detail] . json
58
58
let icon = it [ \. popup_main_icon] . string
59
59
let primaryColor = it [ \. primary_color] . string ?? " #FFFFFF "
@@ -66,7 +66,7 @@ public struct ConsentStyleConfiguration {
66
66
secondaryColor: UIColor ( hex: secondaryColor) ,
67
67
buttonTextColor: UIColor ( hex: dialogButtonTextColor) ,
68
68
textColor: UIColor ( hex: dialogTextColor) )
69
-
69
+
70
70
return ConsentStyleConfiguration ( backgroundColor: UIColor ( hex: backgroundColor) ,
71
71
textColor: UIColor ( hex: textColor) ,
72
72
barBackgroundOpacity: barBackgroundOpacity,
@@ -128,29 +128,38 @@ public struct ConsentMessage: BaseConsentMessage{
128
128
public let defaultLanguage : String
129
129
public var permission : [ ConsentPermission ]
130
130
131
- public func acceptAll ( ) {
131
+ public func allowAll ( ) {
132
132
for var item in permission{
133
- item. accept = true
133
+ item. allow = true
134
134
}
135
135
}
136
+
136
137
public func denyAll( ) {
137
138
for var item in permission{
138
- item. accept = false
139
+ item. allow = false
139
140
}
140
141
}
141
-
142
+
143
+ public func setPermission( name: ConsentPermissionName , isAllow: Bool ) {
144
+ for var item in self . permission{
145
+ if item. name. rawValue == name. rawValue {
146
+ item. allow = false
147
+ }
148
+ }
149
+ }
150
+
142
151
public func validate( ) -> ValidationResult {
143
152
var pass = true
144
153
var errorField : [ String ] ?
145
154
var errorMessage : String ?
146
155
147
156
for p in permission{
148
- if ( p. require && !p. accept ) {
157
+ if ( p. require && !p. allow ) {
149
158
pass = false
150
159
if errorField == nil {
151
160
errorField = [ ]
152
161
}
153
- errorField? . append ( p. name)
162
+ errorField? . append ( p. name. nameStr )
154
163
}
155
164
}
156
165
if ( !pass) {
@@ -208,20 +217,20 @@ public struct ConsentMessage: BaseConsentMessage{
208
217
209
218
210
219
return ConsentMessage ( id: id,
211
- type: type,
212
- name: name,
213
- description: description,
214
- style: style,
215
- version: version,
216
- revision: revision,
217
- displayText: displayText,
218
- acceptButtonText: acceptButtonText,
219
- consentDetailTitle: consentDetailTitle,
220
- availableLanguages: availableLanguages,
221
- defaultLanguage: defaultLanguage,
222
- permission: permissions)
220
+ type: type,
221
+ name: name,
222
+ description: description,
223
+ style: style,
224
+ version: version,
225
+ revision: revision,
226
+ displayText: displayText,
227
+ acceptButtonText: acceptButtonText,
228
+ consentDetailTitle: consentDetailTitle,
229
+ availableLanguages: availableLanguages,
230
+ defaultLanguage: defaultLanguage,
231
+ permission: permissions)
223
232
}
224
-
233
+
225
234
}
226
235
227
236
@@ -232,14 +241,12 @@ public struct ConsentMessageError: BaseConsentMessage{
232
241
233
242
public struct ConsentPermission {
234
243
235
- public let name : String
236
- public let key : String
244
+ public let name : ConsentPermissionName
237
245
public let shortDescription : Text ?
238
246
public let fullDescription : Text ?
239
247
public let fullDescriptionEnabled : Bool
240
248
public let require : Bool
241
- public var accept : Bool
242
- public var allow = true
249
+ public var allow = false
243
250
244
251
private static func getText( _ json: Json ? ) -> Text ? {
245
252
guard let json = json else { return nil }
@@ -248,84 +255,83 @@ public struct ConsentPermission{
248
255
th: json [ \. th] . string
249
256
)
250
257
}
251
-
252
- private static func parsePermission( json: Json ? , key: String , name : String , require: Bool ) -> ConsentPermission ? {
258
+
259
+ private static func parsePermission( json: Json ? , key: ConsentPermissionName , require: Bool ) -> ConsentPermission ? {
253
260
254
- if let item = json ? [ dynamicMember: key] . json {
261
+ if let item = json ? [ dynamicMember: key. key ] . json {
255
262
256
263
let shortDescription = item [ \. brief_description] . json
257
264
let fullDescription = item [ \. full_description] . json
258
265
let fullDescriptionEnabled = item [ \. is_full_description_enabled] . bool ?? false
259
-
260
- return ConsentPermission ( name: name,
261
- key: key,
266
+
267
+ return ConsentPermission ( name: key,
262
268
shortDescription: ConsentPermission . getText ( shortDescription) ,
263
269
fullDescription: ConsentPermission . getText ( fullDescription) ,
264
270
fullDescriptionEnabled: fullDescriptionEnabled,
265
271
require: require,
266
- accept : true )
272
+ allow : true )
267
273
}
268
-
274
+
269
275
return nil
270
276
}
271
-
277
+
272
278
static public func parse( json: Json ? ) -> [ ConsentPermission ] {
273
279
var list : [ ConsentPermission ] = [ ]
274
-
275
- if let perm = parsePermission ( json: json, key: " terms_and_conditions " , name : " Terms and Conditions " , require: true ) {
280
+
281
+ if let perm = parsePermission ( json: json, key: . termsAndConditions , require: true ) {
276
282
list. append ( perm)
277
283
}
278
284
279
- if let perm = parsePermission ( json: json, key: " privacy_overview " , name : " Privacy overview " , require: true ) {
285
+ if let perm = parsePermission ( json: json, key: . privacyOverview , require: true ) {
280
286
list. append ( perm)
281
287
}
282
-
283
- if let perm = parsePermission ( json: json, key: " necessary_cookies " , name : " Necessary cookies " , require: true ) {
288
+
289
+ if let perm = parsePermission ( json: json, key: . necessaryCookies , require: true ) {
284
290
list. append ( perm)
285
291
}
286
292
287
- if let perm = parsePermission ( json: json, key: " preferences_cookies " , name : " Preferences cookies " , require: false ) {
293
+ if let perm = parsePermission ( json: json, key: . preferencesCookies , require: false ) {
288
294
list. append ( perm)
289
295
}
290
296
291
- if let perm = parsePermission ( json: json, key: " analytics_cookies " , name : " Analytics cookies " , require: false ) {
297
+ if let perm = parsePermission ( json: json, key: . analyticsCookies , require: false ) {
292
298
list. append ( perm)
293
299
}
294
300
295
- if let perm = parsePermission ( json: json, key: " marketing_cookies " , name : " Marketing cookies " , require: false ) {
301
+ if let perm = parsePermission ( json: json, key: . marketingCookies , require: false ) {
296
302
list. append ( perm)
297
303
}
298
304
299
- if let perm = parsePermission ( json: json, key: " social_media_cookies " , name : " Social media cookies " , require: false ) {
305
+ if let perm = parsePermission ( json: json, key: . socialMediaCookies , require: false ) {
300
306
list. append ( perm)
301
307
}
302
-
303
- if let perm = parsePermission ( json: json, key: " email " , name : " Email " , require: false ) {
308
+
309
+ if let perm = parsePermission ( json: json, key: . email, require: false ) {
304
310
list. append ( perm)
305
311
}
306
312
307
- if let perm = parsePermission ( json: json, key: " sms " , name : " SMS " , require: false ) {
313
+ if let perm = parsePermission ( json: json, key: . sms, require: false ) {
308
314
list. append ( perm)
309
315
}
310
316
311
- if let perm = parsePermission ( json: json, key: " line " , name : " LINE " , require: false ) {
317
+ if let perm = parsePermission ( json: json, key: . line, require: false ) {
312
318
list. append ( perm)
313
319
}
314
-
315
- if let perm = parsePermission ( json: json, key: " facebook_messenger " , name : " Facebook Messenger " , require: false ) {
320
+
321
+ if let perm = parsePermission ( json: json, key: . facebookMessenger , require: false ) {
316
322
list. append ( perm)
317
323
}
318
324
319
- if let perm = parsePermission ( json: json, key: " push_notification " , name : " Push notification " , require: false ) {
325
+ if let perm = parsePermission ( json: json, key: . pushNotification , require: false ) {
320
326
list. append ( perm)
321
327
}
322
-
328
+
323
329
return list
324
330
}
325
-
331
+
326
332
327
333
public func getSubmitKey( ) -> String {
328
- return " _allow_ \( key ) "
334
+ return " _allow_ \( name ) "
329
335
}
330
336
}
331
337
0 commit comments