From 7a5dbcb095f7271f65d63a9a6f01768a0b3760a6 Mon Sep 17 00:00:00 2001 From: Roman Laitarenko Date: Wed, 23 Aug 2023 11:10:27 +0300 Subject: [PATCH] [CP] Add privacy policy attribution dialog action to v10 (#1758) (#1760) --- CHANGELOG.md | 1 + .../en.lproj/OrnamentsLocalizable.strings | 3 +++ Sources/MapboxMaps/Style/Attribution.swift | 10 ++++++++++ .../Style/AttributionDialogManager.swift | 7 +++++++ .../InfoButton/InfoButtonOrnamentTests.swift | 6 ++++-- .../Style/AttributionDialogTests.swift | 16 +++++++++------- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b1c3f899c24..b7192950ca11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone. ## 10.16.0-beta.1 - Aug 9, 2023 * Update MapboxCoreMaps to 10.16.0-beta.1 and MapboxCommon to 23.8.0-beta.1. +* Add privacy policy attribution dialog action. ## 10.15.0-rc.1 - July 13, 2023 diff --git a/Sources/MapboxMaps/Ornaments/en.lproj/OrnamentsLocalizable.strings b/Sources/MapboxMaps/Ornaments/en.lproj/OrnamentsLocalizable.strings index 1ab8fa9c826f..a15e3775a28f 100644 --- a/Sources/MapboxMaps/Ornaments/en.lproj/OrnamentsLocalizable.strings +++ b/Sources/MapboxMaps/Ornaments/en.lproj/OrnamentsLocalizable.strings @@ -36,3 +36,6 @@ /* Telemetry prompt title */ "TELEMETRY_TITLE" = "Make Mapbox Maps Better"; + +/* Privacy policy action in attribution sheet */ +"ATTRIBUTION_PRIVACY_POLICY" = "Mapbox Privacy Policy"; diff --git a/Sources/MapboxMaps/Style/Attribution.swift b/Sources/MapboxMaps/Style/Attribution.swift index 13408f1ef74e..64aef299ec39 100644 --- a/Sources/MapboxMaps/Style/Attribution.swift +++ b/Sources/MapboxMaps/Style/Attribution.swift @@ -21,6 +21,7 @@ internal struct Attribution: Hashable { "https://www.mapbox.com/map-feedback/", "https://apps.mapbox.com/feedback/" ] + private static let privacyPolicyURL = URL(string: "https://www.mapbox.com/legal/privacy#product-privacy-policy") var title: String var kind: Kind @@ -46,6 +47,15 @@ internal struct Attribution: Hashable { } } + static func makePrivacyPolicyAttribution() -> Attribution { + let title = NSLocalizedString("ATTRIBUTION_PRIVACY_POLICY", + tableName: Ornaments.localizableTableName, + bundle: .mapboxMaps, + value: "Mapbox Privacy Policy", + comment: "Privacy policy action in attribution sheet") + return .init(title: title, url: Self.privacyPolicyURL) + } + internal init(title: String, url: URL?) { self.title = title diff --git a/Sources/MapboxMaps/Style/AttributionDialogManager.swift b/Sources/MapboxMaps/Style/AttributionDialogManager.swift index 430a6d7d7e50..66b8bb5b1ff6 100644 --- a/Sources/MapboxMaps/Style/AttributionDialogManager.swift +++ b/Sources/MapboxMaps/Style/AttributionDialogManager.swift @@ -163,6 +163,13 @@ extension AttributionDialogManager: InfoButtonOrnamentDelegate { alert.addAction(telemetryAction) + let privacyPolicyAttribution = Attribution.makePrivacyPolicyAttribution() + let privacyPolicyAction = UIAlertAction(title: privacyPolicyAttribution.title, style: .default) { _ in + self.delegate?.attributionDialogManager(self, didTriggerActionFor: privacyPolicyAttribution) + } + + alert.addAction(privacyPolicyAction) + let cancelTitle = NSLocalizedString("CANCEL", tableName: Ornaments.localizableTableName, bundle: bundle, diff --git a/Tests/MapboxMapsTests/Ornaments/InfoButton/InfoButtonOrnamentTests.swift b/Tests/MapboxMapsTests/Ornaments/InfoButton/InfoButtonOrnamentTests.swift index 8bebd51bc274..a5408f88e5da 100644 --- a/Tests/MapboxMapsTests/Ornaments/InfoButton/InfoButtonOrnamentTests.swift +++ b/Tests/MapboxMapsTests/Ornaments/InfoButton/InfoButtonOrnamentTests.swift @@ -23,12 +23,14 @@ class InfoButtonOrnamentTests: XCTestCase { let firstAlert = try XCTUnwrap(parentViewController.currentAlert, "The first alert controller could not be found.") XCTAssertNotNil(firstAlert) - XCTAssertEqual(firstAlert.actions.count, 2, "There should be two alerts present.") + XCTAssertEqual(firstAlert.actions.count, 3, "There should be three actions present.") let telemetryTitle = NSLocalizedString("Mapbox Telemetry", comment: "Action in attribution sheet") XCTAssertEqual(firstAlert.actions[0].title!, telemetryTitle) + XCTAssertEqual(firstAlert.actions[1].title, Attribution.makePrivacyPolicyAttribution().title) + let cancelTitle = NSLocalizedString("Cancel", comment: "Title of button for dismissing attribution action sheet") - XCTAssertEqual(firstAlert.actions[1].title, cancelTitle) + XCTAssertEqual(firstAlert.actions[2].title, cancelTitle) } func testTelemetryOptOut() throws { diff --git a/Tests/MapboxMapsTests/Style/AttributionDialogTests.swift b/Tests/MapboxMapsTests/Style/AttributionDialogTests.swift index 8f1584ce4229..103a29beaf0f 100644 --- a/Tests/MapboxMapsTests/Style/AttributionDialogTests.swift +++ b/Tests/MapboxMapsTests/Style/AttributionDialogTests.swift @@ -136,8 +136,8 @@ class AttributionDialogTests: XCTestCase { XCTAssertEqual(alert.title, alertTitle) XCTAssertNil(alert.message) - guard alert.actions.count == 2 else { - XCTFail("Telemetry alert should have 2 actions") + guard alert.actions.count == 3 else { + XCTFail("Telemetry alert should have 3 actions") return } @@ -147,12 +147,14 @@ class AttributionDialogTests: XCTestCase { comment: "") XCTAssertEqual(alert.actions[0].title, telemetryTitle) + XCTAssertEqual(alert.actions[1].title, Attribution.makePrivacyPolicyAttribution().title) + let cancelTitle = NSLocalizedString("CANCEL", tableName: Ornaments.localizableTableName, bundle: bundle, value: "Cancel", comment: "") - XCTAssertEqual(alert.actions[1].title, cancelTitle) + XCTAssertEqual(alert.actions[2].title, cancelTitle) } func testShowAttributionDialogSingleNonActionableAttribution() throws { @@ -179,8 +181,8 @@ class AttributionDialogTests: XCTestCase { XCTAssertEqual(alert.title, alertTitle) XCTAssertEqual(alert.message, attribution.title) - guard alert.actions.count == 2 else { - XCTFail("Telemetry alert should have 2 actions") + guard alert.actions.count == 3 else { + XCTFail("Telemetry alert should have 3 actions") return } } @@ -210,8 +212,8 @@ class AttributionDialogTests: XCTestCase { XCTAssertNil(alert.message) // Single, non-actionable attributions should be displayed as alert's actions along the telemetry and cancel actions - guard alert.actions.count == 4 else { - XCTFail("Telemetry alert should have 4 actions") + guard alert.actions.count == 5 else { + XCTFail("Telemetry alert should have 5 actions") return }