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

Fix #8493: Privacy Hub hide action approval alert #8508

Merged
merged 3 commits into from
Dec 8, 2023
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
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