Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIA-1537 Fix Do not sell button not working #400

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ConsentViewController/Classes/SPConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import UIKit
delegate: self
)
controller.delegate = self
controller.snapshot = CCPAPMConsentSnaptshot()
controller.ccpaConsents = userData.ccpa?.consents
return controller
}
return nil
Expand Down Expand Up @@ -428,7 +428,7 @@ import UIKit
delegate: self
)
pmViewController.delegate = self
// pmViewController.snapshot = CCPAPMConsentSnaptshot(withStatus: self?.userData.ccpa?.consents?.status)
pmViewController.ccpaConsents = self?.userData.ccpa?.consents
self?.loaded(pmViewController)
case .failure(let error):
self?.onError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import Foundation

var doNotSellButton: SPNativeLongButton?

var ccpaConsents: SPCCPAConsent?
private var snapshot: CCPAPMConsentSnaptshot!

@IBOutlet weak var header: SPPMHeader!

var secondLayerData: CCPAPrivacyManagerViewResponse?

let cellReuseIdentifier = "cell"

var snapshot: CCPAPMConsentSnaptshot?

override var preferredFocusedView: UIView? { acceptButton }

override func setFocusGuides() {
Expand All @@ -55,8 +56,32 @@ import Foundation
loaded(self)
}

func setDoNotSellButton() {
doNotSellButton = viewData.byId("DoNotSellButton") as? SPNativeLongButton
doNotSellTableView.register(
UINib(nibName: "LongButtonViewCell", bundle: Bundle.framework),
forCellReuseIdentifier: cellReuseIdentifier
)
doNotSellTableView.allowsSelection = true
doNotSellTableView.delegate = self
doNotSellTableView.dataSource = self
}

func initConsentsSnapshot() {
snapshot = CCPAPMConsentSnaptshot(
vendors: [],
categories: [],
rejectedVendors: ccpaConsents?.rejectedVendors,
rejectedCategories: ccpaConsents?.rejectedCategories,
consentStatus: ccpaConsents?.status)
snapshot.onConsentsChange = { [weak self] in
self?.doNotSellTableView.reloadData()
}
}

override func viewDidLoad() {
super.viewDidLoad()
initConsentsSnapshot()
setHeader()
loadTextView(forComponentId: "PublisherDescription", textView: descriptionTextView, bounces: false)
descriptionTextView.flashScrollIndicators()
Expand All @@ -67,17 +92,7 @@ import Foundation
loadButton(forComponentId: "NavVendorsButton", button: ourPartners)
loadButton(forComponentId: "NavPrivacyPolicyButton", button: privacyPolicyButton)
loadImage(forComponentId: "LogoImage", imageView: logoImageView)
doNotSellButton = viewData.byId("DoNotSellButton") as? SPNativeLongButton
doNotSellTableView.register(
UINib(nibName: "LongButtonViewCell", bundle: Bundle.framework),
forCellReuseIdentifier: cellReuseIdentifier
)
doNotSellTableView.allowsSelection = true
doNotSellTableView.delegate = self
doNotSellTableView.dataSource = self
snapshot?.onConsentsChange = { [weak self] in
self?.doNotSellTableView.reloadData()
}
setDoNotSellButton()
setFocusGuidesForButtons()
disableMenuButton()
}
Expand Down Expand Up @@ -115,9 +130,19 @@ import Foundation
}

@IBAction func onSaveAndExitTap(_ sender: Any) {
let actionType: SPActionType = (snapshot?.consentStatus == .RejectedAll) ? .RejectAll : .AcceptAll
var actionType: SPActionType
switch snapshot.consentStatus {
case .RejectedSome: actionType = .SaveAndExit
case .RejectedAll: actionType = .RejectAll
case .ConsentedAll, .RejectedNone: actionType = . AcceptAll
}

action(
SPAction(type: actionType, campaignType: campaignType),
SPAction(
type: actionType,
campaignType: campaignType,
pmPayload: snapshot.toPayload(language: .English, pmId: messageId).json() ?? SPJson()
),
from: self
)
}
Expand All @@ -139,15 +164,13 @@ import Foundation
delegate: self,
nibName: "SPCCPAManagePreferenceViewController"
)
if self?.snapshot == nil {
self?.snapshot = CCPAPMConsentSnaptshot(
vendors: Set<CCPAVendor>(data.vendors),
categories: Set<CCPACategory>(data.categories),
rejectedVendors: data.rejectedVendors,
rejectedCategories: data.rejectedCategories,
consentStatus: data.consentStatus
)
}
self?.snapshot = CCPAPMConsentSnaptshot(
vendors: Set<CCPAVendor>(data.vendors),
categories: Set<CCPACategory>(data.categories),
rejectedVendors: data.rejectedVendors,
rejectedCategories: data.rejectedCategories,
consentStatus: data.consentStatus
)
controller.categories = data.categories
controller.consentsSnapshot = strongSelf.snapshot!
self?.present(controller, animated: true)
Expand All @@ -164,15 +187,6 @@ import Foundation
delegate: self,
nibName: "SPManagePreferenceViewController"
)
if snapshot == nil {
snapshot = CCPAPMConsentSnaptshot(
vendors: Set<CCPAVendor>(secondLayerData.vendors),
categories: Set<CCPACategory>(secondLayerData.categories),
rejectedVendors: secondLayerData.rejectedVendors,
rejectedCategories: secondLayerData.rejectedCategories,
consentStatus: secondLayerData.consentStatus
)
}
controller.categories = secondLayerData.categories
controller.consentsSnapshot = snapshot!
present(controller, animated: true)
Expand All @@ -185,14 +199,12 @@ import Foundation
self?.onError(error)
case .success(let data):
if let strongSelf = self {
if self?.snapshot == nil {
self?.snapshot = CCPAPMConsentSnaptshot(
vendors: Set<CCPAVendor>(data.vendors),
categories: Set<CCPACategory>(data.categories),
rejectedVendors: data.rejectedVendors,
rejectedCategories: data.rejectedCategories, consentStatus: data.consentStatus
)
}
self?.snapshot = CCPAPMConsentSnaptshot(
vendors: Set<CCPAVendor>(data.vendors),
categories: Set<CCPACategory>(data.categories),
rejectedVendors: data.rejectedVendors,
rejectedCategories: data.rejectedCategories, consentStatus: data.consentStatus
)
let controller = SPCCPAPartnersViewController(
messageId: strongSelf.messageId,
campaignType: strongSelf.campaignType,
Expand Down Expand Up @@ -264,7 +276,7 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDataSource {
cell.labelText = doNotSellButton?.settings.text
cell.selectable = false
cell.isCustom = false
cell.isOn = snapshot?.consentStatus == .RejectedAll
cell.isOn = snapshot.consentStatus == .RejectedAll
cell.setup(from: doNotSellButton)
cell.loadUI()
return cell
Expand All @@ -282,6 +294,6 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDelegate {
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
snapshot?.onDoNotSellToggle()
snapshot.onDoNotSellToggle()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ extension SPCCPAPartnersViewController: UITableViewDataSource, UITableViewDelega

let vendor = vendors[indexPath.row]
cell.labelText = vendor.name
cell.isOn = !consentsSnapshot.toggledVendorsIds.contains(vendor._id)
switch consentsSnapshot.consentStatus {
case .ConsentedAll, .RejectedNone: cell.isOn = true
case .RejectedAll: cell.isOn = false
case .RejectedSome: cell.isOn = !consentsSnapshot.toggledVendorsIds.contains(vendor._id)
}
cell.selectable = true
cell.isCustom = false
cell.setup(from: nativeLongButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "http://github.com/SourcePointUSA/ios-cmp-app.git",
"state" : {
"revision" : "7f145c21be033ad5cc9d608ab60344b2bc7f2bd3",
"version" : "6.7.2-pre.1"
"revision" : "a393158541f331fe6f2ec460246ee5f59df45fae",
"version" : "6.7.2"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Example/NativePMExampleApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ViewController: UIViewController {
}

@IBAction func onCCPATap(_ sender: Any) {
consentManager.loadCCPAPrivacyManager(withId: "713327")
consentManager.loadCCPAPrivacyManager(withId: "750805")
}

lazy var consentManager: SPConsentManager = { SPConsentManager(
Expand Down