Skip to content

Commit

Permalink
Address change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alpavanoglu committed Jul 6, 2023
1 parent ed3dd44 commit 7c86df4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def wordpress_ui
end

def wordpress_kit
pod 'WordPressKit', '~> 8.5.0-beta.3'
pod 'WordPressKit', '~> 8.5-beta.3'
# pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: ''
# pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: ''
# pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: ''
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ DEPENDENCIES:
- SwiftLint (~> 0.50)
- WordPress-Editor-iOS (~> 1.19.8)
- WordPressAuthenticator (~> 6.1-beta)
- WordPressKit (~> 8.5.0-beta.3)
- WordPressKit (~> 8.5-beta.3)
- WordPressShared (~> 2.2-beta)
- WordPressUI (~> 1.12.5)
- WPMediaPicker (~> 1.8-beta)
Expand Down Expand Up @@ -895,6 +895,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37

PODFILE CHECKSUM: 7be6a8ed524025ed4acf2454718cab08a0b9e310
PODFILE CHECKSUM: 66f009c76957bfeaeeb56fd48cb877edb372951c

COCOAPODS: 1.12.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import WordPressKit

final class ComplianceLocationService {
func getIPCountryCode(completion: @escaping (Result<String, Error>) -> Void) {
IPLocationRemote().fetchIPCountryCode { result in
switch result {
case .success(let countryCode):
completion(.success(countryCode))
case .failure(let error):
completion(.failure(error))
}
}
IPLocationRemote().fetchIPCountryCode(completion: completion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ private enum Strings {

static let subtitle = NSLocalizedString(
"compliance.analytics.popover.subtitle",
value: """
We process your personal data to optimize our website and
marketing activities based on your consent and our legitimate interest.
""",
value: "We process your personal data to optimize our website and marketing activities based on your consent and our legitimate interest.",
comment: "Subtitle for the privacy compliance popover."
)

Expand All @@ -126,10 +123,7 @@ private enum Strings {

static let footnote = NSLocalizedString(
"compliance.analytics.popover.footnote",
value: """
These cookies allow us to optimize performance by collecting
information on how users interact with our websites.
""",
value: "These cookies allow us to optimize performance by collecting information on how users interact with our websites.",
comment: "Footnote for the privacy compliance popover."
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import UIKit

final class CompliancePopoverCoordinator {
fileprivate enum Constants {
static let shouldShowCompliancePopup = "shouldShowCompliancePopup"
}

private let viewController: UIViewController
private let complianceService = ComplianceLocationService()
Expand All @@ -19,28 +16,20 @@ final class CompliancePopoverCoordinator {
return
}
complianceService.getIPCountryCode { [weak self] result in
switch result {
case .success(let countryCode):
if case .success(let countryCode) = result {
guard let self, self.shouldShowPrivacyBanner(countryCode: countryCode) else {
return
}
DispatchQueue.main.async {
let complianceViewModel = CompliancePopoverViewModel(defaults: self.defaults)
complianceViewModel.coordinator = self
let complianceViewController = CompliancePopoverViewController(viewModel: complianceViewModel)
let bottomSheetViewController = BottomSheetViewController(childViewController: complianceViewController, customHeaderSpacing: 0)

bottomSheetViewController.show(from: self.viewController)
self.presentPopover()
}
case .failure(let error):
()
}
}
}

func shouldShowPrivacyBanner(countryCode: String) -> Bool {
let isCountryInEU = Self.gdprCountryCodes.contains(countryCode)
return isCountryInEU && defaults.shouldShowCompliancePopup
return isCountryInEU && !defaults.didShowCompliancePopup
}

func navigateToSettings() {
Expand All @@ -52,6 +41,15 @@ final class CompliancePopoverCoordinator {
func dismiss() {
viewController.dismiss(animated: true)
}

private func presentPopover() {
let complianceViewModel = CompliancePopoverViewModel(defaults: self.defaults)
complianceViewModel.coordinator = self
let complianceViewController = CompliancePopoverViewController(viewModel: complianceViewModel)
let bottomSheetViewController = BottomSheetViewController(childViewController: complianceViewController, customHeaderSpacing: 0)

bottomSheetViewController.show(from: self.viewController)
}
}

private extension CompliancePopoverCoordinator {
Expand Down Expand Up @@ -94,11 +92,13 @@ private extension CompliancePopoverCoordinator {
}

extension UserDefaults {
@objc dynamic var shouldShowCompliancePopup: Bool {
static let didShowCompliancePopupKey = "didShowCompliancePopup"

@objc var didShowCompliancePopup: Bool {
get {
bool(forKey: CompliancePopoverCoordinator.Constants.shouldShowCompliancePopup)
bool(forKey: Self.didShowCompliancePopupKey)
} set {
set(newValue, forKey: CompliancePopoverCoordinator.Constants.shouldShowCompliancePopup)
set(newValue, forKey: Self.didShowCompliancePopupKey)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import WordPressUI
final class CompliancePopoverViewController: UIViewController {

// MARK: - Views
private lazy var hostingController: UIHostingController = {
let controller = UIHostingController(rootView: CompliancePopover(viewModel: self.viewModel))
controller.view.translatesAutoresizingMaskIntoConstraints = true
return controller
}()
private let hostingController: UIHostingController<CompliancePopover>

private var contentView: UIView {
return hostingController.view
Expand All @@ -20,6 +16,7 @@ final class CompliancePopoverViewController: UIViewController {

init(viewModel: CompliancePopoverViewModel) {
self.viewModel = viewModel
hostingController = UIHostingController(rootView: CompliancePopover(viewModel: self.viewModel))
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -31,6 +28,7 @@ final class CompliancePopoverViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.addContentView()
hostingController.view.translatesAutoresizingMaskIntoConstraints = true
hostingController.rootView.goToSettingsAction = {
self.viewModel.didTapSettings()
}
Expand All @@ -46,10 +44,8 @@ final class CompliancePopoverViewController: UIViewController {
self.contentView.frame = .init(origin: .zero, size: contentViewSize)
self.preferredContentSize = contentView.bounds.size

DispatchQueue.main.async {
self.hostingController.rootView.screenHeight = self.view.frame.height
self.hostingController.rootView.shouldScroll = (contentViewSize.height + 100) > self.view.frame.height
}
self.hostingController.rootView.screenHeight = self.view.frame.height
self.hostingController.rootView.shouldScroll = (contentViewSize.height + 100) > self.view.frame.height
}

private func addContentView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ final class CompliancePopoverViewModel: ObservableObject {

func didTapSettings() {
coordinator?.navigateToSettings()
defaults.shouldShowCompliancePopup = false
defaults.didShowCompliancePopup = true
}

func didTapSave() {
let appAnalytics = WordPressAppDelegate.shared?.analytics
appAnalytics?.setUserHasOptedOut(!isAnalyticsEnabled)

let account = ContextManager.shared.performQuery { context -> WPAccount? in
let (accountID, restAPI) = ContextManager.shared.performQuery { context -> (NSNumber?, WordPressComRestApi?) in
let account = try? WPAccount.lookupDefaultWordPressComAccount(in: context)
return account
return (account?.userID, account?.wordPressComRestApi)
}

guard let account else {
guard let accountID, let restAPI else {
return
}

let change = AccountSettingsChange.tracksOptOut(!isAnalyticsEnabled)
AccountSettingsService(userID: account.userID.intValue, api: account.wordPressComRestApi).saveChange(change)
AccountSettingsService(userID: accountID.intValue, api: restAPI).saveChange(change)
coordinator?.dismiss()
defaults.shouldShowCompliancePopup = false
defaults.didShowCompliancePopup = true
}
}

0 comments on commit 7c86df4

Please sign in to comment.