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

Commit

Permalink
Fix #4009: Disable History sync when user switches to PB only (#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored Aug 9, 2021
1 parent 9730006 commit e1d902f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
5 changes: 5 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,11 @@ extension Strings {
NSLocalizedString("history.historyEmptyStateTitle", tableName: "BraveShared", bundle: .braveShared,
value: "History will show up here.",
comment: "Title which is displayed when History screen is empty.")

public static let historyPrivateModeOnlyStateTitle =
NSLocalizedString("history.historyPrivateModeOnlyStateTitle", tableName: "BraveShared", bundle: .braveShared,
value: "History is not available in Private Browsing Only mode.",
comment: "Title which is displayed on History screen as a overlay when Private Browsing Only enabled")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol
tableView.accessibilityIdentifier = "History List"
title = Strings.historyScreenTitle

navigationItem.rightBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "playlist_delete_item").template, style: .done, target: self, action: #selector(performDeleteAll))
if !Preferences.Privacy.privateBrowsingOnly.value {
navigationItem.rightBarButtonItem =
UIBarButtonItem(image: #imageLiteral(resourceName: "playlist_delete_item").template, style: .done, target: self, action: #selector(performDeleteAll))
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

refreshHistory()
if Preferences.Privacy.privateBrowsingOnly.value {
showEmptyPanelState()
} else {
refreshHistory()
}
}

private func refreshHistory() {
Expand Down Expand Up @@ -95,7 +102,7 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol
}
}

fileprivate func createEmptyStateOverlayView() -> UIView {
private func createEmptyStateOverlayView() -> UIView {
let overlayView = UIView().then {
$0.backgroundColor = .secondaryBraveBackground
}
Expand All @@ -105,7 +112,9 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol
}

let welcomeLabel = UILabel().then {
$0.text = Strings.History.historyEmptyStateTitle
$0.text = Preferences.Privacy.privateBrowsingOnly.value
? Strings.History.historyPrivateModeOnlyStateTitle
: Strings.History.historyEmptyStateTitle
$0.textAlignment = .center
$0.font = DynamicFontHelper.defaultHelper.DeviceFontLight
$0.textColor = .braveLabel
Expand Down Expand Up @@ -135,20 +144,24 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol
return overlayView
}

fileprivate func updateEmptyPanelState() {
if historyFRC?.fetchedObjectsCount == 0 {
if emptyStateOverlayView.superview == nil {
view.addSubview(emptyStateOverlayView)
view.bringSubviewToFront(emptyStateOverlayView)
emptyStateOverlayView.snp.makeConstraints { make -> Void in
make.edges.equalTo(tableView)
}
}
private func updateEmptyPanelState() {
if historyFRC?.fetchedObjectsCount == 0 {
showEmptyPanelState()
} else {
emptyStateOverlayView.removeFromSuperview()
}
}

private func showEmptyPanelState() {
if emptyStateOverlayView.superview == nil {
view.addSubview(emptyStateOverlayView)
view.bringSubviewToFront(emptyStateOverlayView)
emptyStateOverlayView.snp.makeConstraints { make -> Void in
make.edges.equalTo(tableView)
}
}
}

@objc private func performDeleteAll() {
let style: UIAlertController.Style = UIDevice.current.userInterfaceIdiom == .pad ? .alert : .actionSheet
let alert = UIAlertController(
Expand Down

0 comments on commit e1d902f

Please sign in to comment.