From 11457c687aab97688c4260232fe4f85e5940c184 Mon Sep 17 00:00:00 2001 From: Soner YUKSEL Date: Fri, 8 Dec 2023 16:29:01 -0500 Subject: [PATCH] Fix brave/brave-ios#8493: Privacy Hub hide action approval alert (brave/brave-ios#8508) --- .../NewTabPageViewController.swift | 25 +++++++++++++++++-- .../Brave/Frontend/ClientPreferences.swift | 5 ++++ Sources/BraveStrings/BraveStrings.swift | 12 ++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift b/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift index 7c86c3e77f65..c4c0817808f9 100644 --- a/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift +++ b/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift @@ -186,8 +186,7 @@ class NewTabPageViewController: UIViewController { self?.present(host, animated: true) }, hidePrivacyHubPressed: { [weak self] in - Preferences.NewTabPage.showNewTabPrivacyHub.value = false - self?.collectionView.reloadData() + self?.hidePrivacyHub() }), FavoritesSectionProvider(action: { [weak self] bookmark, action in self?.handleFavoriteAction(favorite: bookmark, action: action) @@ -788,6 +787,28 @@ class NewTabPageViewController: UIViewController { } feedDataSource.load(completion) } + + private func hidePrivacyHub() { + if Preferences.NewTabPage.hidePrivacyHubAlertShown.value { + Preferences.NewTabPage.showNewTabPrivacyHub.value = false + collectionView.reloadData() + } else { + let alert = UIAlertController( + title: Strings.PrivacyHub.hidePrivacyHubWidgetActionTitle, + message: Strings.PrivacyHub.hidePrivacyHubWidgetAlertDescription, + preferredStyle: .alert) + + alert.addAction(UIAlertAction(title: Strings.cancelButtonTitle, style: .cancel)) + alert.addAction(UIAlertAction(title: Strings.PrivacyHub.hidePrivacyHubWidgetActionButtonTitle, style: .default) { [weak self] _ in + Preferences.NewTabPage.showNewTabPrivacyHub.value = false + Preferences.NewTabPage.hidePrivacyHubAlertShown.value = true + self?.collectionView.reloadData() + }) + + UIImpactFeedbackGenerator(style: .medium).bzzt() + present(alert, animated: true, completion: nil) + } + } // MARK: - Actions diff --git a/Sources/Brave/Frontend/ClientPreferences.swift b/Sources/Brave/Frontend/ClientPreferences.swift index c772275e260d..6b82c1647a56 100644 --- a/Sources/Brave/Frontend/ClientPreferences.swift +++ b/Sources/Brave/Frontend/ClientPreferences.swift @@ -181,6 +181,11 @@ extension Preferences { public static let showNewTabPrivacyHub = Option(key: "newtabpage.show-newtab-privacyhub", default: true) + /// First time when privacy hub hide action is tieggered user will be shown alert + static let hidePrivacyHubAlertShown = Option( + key: "newtabpage.hide-privacyhub-alert", + default: false) + /// Tells the app whether we should show Favourites in new tab page view controller public static let showNewTabFavourites = Option(key: "newtabpage.show-newtab-favourites", default: true) diff --git a/Sources/BraveStrings/BraveStrings.swift b/Sources/BraveStrings/BraveStrings.swift index 99c9aafa228c..323a9a6c5fda 100644 --- a/Sources/BraveStrings/BraveStrings.swift +++ b/Sources/BraveStrings/BraveStrings.swift @@ -4705,14 +4705,24 @@ extension Strings { ) public static let hidePrivacyHubWidgetActionTitle = NSLocalizedString("privacyHub.hidePrivacyHubWidgetActionTitle", tableName: "BraveShared", bundle: .module, - value: "Hide Privacy Hub Widget", + value: "Hide Privacy Stats", comment: "The title of the button action which hides the privacy hub" ) + public static let hidePrivacyHubWidgetAlertDescription = NSLocalizedString("privacyHub.hidePrivacyHubWidgetAlertDescription", tableName: "BraveShared", bundle: .module, + value: "Tap Hide to remove the Privacy Stats widget. You can always re-enable in Settings, under New Tab Page", + comment: "The description in alert of the hide action which hides the privacy hub" + ) + public static let openPrivacyHubWidgetActionTitle = NSLocalizedString("privacyHub.openPrivacyHubWidgetActionTitle", tableName: "BraveShared", bundle: .module, value: "Open Privacy Hub", comment: "The title of the button action which open the privacy hub" ) + + public static let hidePrivacyHubWidgetActionButtonTitle = NSLocalizedString("privacyHub.hidePrivacyHubWidgetActionButtonTitle", tableName: "BraveShared", bundle: .module, + value: "Hide", + comment: "Hide Privacy Hub Alert Hide Button" + ) } }