Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #8493: Privacy Hub hide action approval alert (#8508)
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored and Brandon-T committed Dec 14, 2023
1 parent cfc284e commit 4b26939
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions Sources/Brave/Frontend/ClientPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ extension Preferences {
public static let showNewTabPrivacyHub =
Option<Bool>(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<Bool>(
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<Bool>(key: "newtabpage.show-newtab-favourites", default: true)
Expand Down
12 changes: 11 additions & 1 deletion Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
}

Expand Down

0 comments on commit 4b26939

Please sign in to comment.