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

Rewards: Add "Hide Rewards Icon" setting to new Display settings section #1567

Merged
merged 1 commit into from
Sep 19, 2019
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
5 changes: 4 additions & 1 deletion BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ extension Strings {
// MARK:- Settings.
extension Strings {
public static let ClearPrivateData = NSLocalizedString("ClearPrivateData", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Clear Private Data", comment: "Button in settings that clears private data for the selected items. Also used as section title in settings panel")
public static let DisplaySettingsSection = NSLocalizedString("DisplaySettingsSection", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Display", comment: "Section name for display preferences.")
public static let OtherSettingsSection = NSLocalizedString("OtherSettingsSection", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Other Settings", comment: "Section name for other settings.")
public static let HideRewardsIcon = NSLocalizedString("HideRewardsIcon", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Hide Brave Rewards Icon", comment: "Hides the rewards icon")
public static let HideRewardsIconSubtitle = NSLocalizedString("HideRewardsIconSubtitle", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Hides the Brave Rewards icon when Brave Rewards is not enabled", comment: "Hide the rewards icon explination.")
}

// MARK:- Error pages.
Expand Down Expand Up @@ -524,7 +527,7 @@ extension Strings {

// MARK: - Themes

public static let ThemesDisplayBrightness = NSLocalizedString("ThemesDisplayBrightness", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Display & Brightness", comment: "Setting to choose the user interface theme for normal browsing mode, contains choices like 'light' or 'dark' themes")
public static let ThemesDisplayBrightness = NSLocalizedString("ThemesDisplayBrightness", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Appearance", comment: "Setting to choose the user interface theme for normal browsing mode, contains choices like 'light' or 'dark' themes")
public static let ThemesDisplayBrightnessFooter = NSLocalizedString("ThemesDisplayBrightnessFooter", tableName: "BraveShared", bundle: Bundle.braveShared, value: "These settings are not applied in private browsing mode.", comment: "Text specifying that the above setting does not impact the user interface while they user is in private browsing mode.")
public static let ThemesAutomaticOption = NSLocalizedString("ThemesAutomaticOption", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Automatic", comment: "Selection to automatically color/style the user interface.")
public static let ThemesLightOption = NSLocalizedString("ThemesLightOption", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Light", comment: "Selection to color/style the user interface with a light theme.")
Expand Down
1 change: 1 addition & 0 deletions BraveShared/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extension Preferences {

public final class Rewards {
public static let myFirstAdShown = Option<Bool>(key: "rewards.ads.my-first-ad-shown", default: false)
public static let hideRewardsIcon = Option<Bool>(key: "rewards.hide-rewards-icon", default: false)
}
}

Expand Down
3 changes: 3 additions & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class BrowserViewController: UIViewController {
Preferences.General.alwaysRequestDesktopSite.observe(from: self)
Preferences.Shields.allShields.forEach { $0.observe(from: self) }
Preferences.Privacy.blockAllCookies.observe(from: self)
Preferences.Rewards.hideRewardsIcon.observe(from: self)
// Lists need to be compiled before attempting tab restoration
contentBlockListDeferred = ContentBlockerHelper.compileBundledLists()

Expand Down Expand Up @@ -3058,6 +3059,8 @@ extension BrowserViewController: PreferencesObserver {
} else {
tabManager.reloadSelectedTab()
}
case Preferences.Rewards.hideRewardsIcon.key:
updateRewardsButtonState()
default:
log.debug("Received a preference change for an unknown key: \(key) on \(type(of: self))")
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BraveRewards
import BraveRewardsUI
import Data
import Shared
import BraveShared

private let log = Logger.rewardsLogger

Expand Down Expand Up @@ -52,6 +53,7 @@ extension RewardsPanelController: PopoverContentComponent {
extension BrowserViewController {
func updateRewardsButtonState() {
if !isViewLoaded { return }
self.topToolbar.locationView.rewardsButton.isHidden = self.rewards?.ledger.isEnabled == false && Preferences.Rewards.hideRewardsIcon.value
self.topToolbar.locationView.rewardsButton.isVerified = self.publisher?.verified ?? false
self.topToolbar.locationView.rewardsButton.notificationCount = self.rewards?.ledger.notifications.count ?? 0
}
Expand Down
74 changes: 47 additions & 27 deletions Client/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class SettingsViewController: TableViewController {
private var sections: [Section] {
var list = [Section]()
list.append(generalSection)
list.append(displaySection)
#if !NO_SYNC
list.append(syncSection)
#endif
Expand Down Expand Up @@ -141,14 +142,46 @@ class SettingsViewController: TableViewController {
]
)

if #available(iOS 13.0, *), UIDevice.isIpad {
general.rows.append(BoolRow(title: Strings.AlwaysRequestDesktopSite,
option: Preferences.General.alwaysRequestDesktopSite))
}

return general
}()

private lazy var displaySection: Section = {
var display = Section(
header: .title(Strings.DisplaySettingsSection),
rows: []
)

let reloadCell = { (row: Row, displayString: String) in
if let indexPath = self.dataSource.indexPath(rowUUID: row.uuid, sectionUUID: general.uuid) {
if let indexPath = self.dataSource.indexPath(rowUUID: row.uuid, sectionUUID: display.uuid) {
self.dataSource.sections[indexPath.section].rows[indexPath.row].detailText = displayString
}
}

let themeSubtitle = Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value)?.displayString
var row = Row(text: Strings.ThemesDisplayBrightness, detailText: themeSubtitle, accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self)
row.selection = { [unowned self] in
let optionsViewController = OptionSelectionViewController<Theme.DefaultTheme>(
options: Theme.DefaultTheme.normalThemesOptions,
selectedOption: Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value),
optionChanged: { [unowned self] _, option in
Preferences.General.themeNormalMode.value = option.rawValue
reloadCell(row, option.displayString)
self.applyTheme(self.theme)
}
)
optionsViewController.headerText = Strings.ThemesDisplayBrightness
optionsViewController.footerText = Strings.ThemesDisplayBrightnessFooter
self.navigationController?.pushViewController(optionsViewController, animated: true)
}
display.rows.append(row)

if UIDevice.current.userInterfaceIdiom == .pad {
general.rows.append(
display.rows.append(
Row(text: Strings.Show_Tabs_Bar, accessory: .switchToggle(value: Preferences.General.tabBarVisibility.value == TabBarVisibility.always.rawValue, { Preferences.General.tabBarVisibility.value = $0 ? TabBarVisibility.always.rawValue : TabBarVisibility.never.rawValue }), cellClass: MultilineValue1Cell.self)
)
} else {
Expand All @@ -166,37 +199,23 @@ class SettingsViewController: TableViewController {
optionsViewController.headerText = Strings.Show_Tabs_Bar
self.navigationController?.pushViewController(optionsViewController, animated: true)
}
general.rows.append(row)
display.rows.append(row)
}

let themeSubtitle = Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value)?.displayString
var row = Row(text: Strings.ThemesDisplayBrightness, detailText: themeSubtitle, accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self)
row.selection = { [unowned self] in
let optionsViewController = OptionSelectionViewController<Theme.DefaultTheme>(
options: Theme.DefaultTheme.normalThemesOptions,
selectedOption: Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value),
optionChanged: { [unowned self] _, option in
Preferences.General.themeNormalMode.value = option.rawValue
reloadCell(row, option.displayString)
self.applyTheme(self.theme)
}
)
optionsViewController.headerText = Strings.ThemesDisplayBrightness
optionsViewController.footerText = Strings.ThemesDisplayBrightnessFooter
self.navigationController?.pushViewController(optionsViewController, animated: true)
}
general.rows.append(row)

general.rows.append(
display.rows.append(
BoolRow(title: Strings.Show_Bookmark_Button_In_Top_Toolbar, option: Preferences.General.showBookmarkToolbarShortcut)
)

if #available(iOS 13.0, *), UIDevice.isIpad {
general.rows.append(BoolRow(title: Strings.AlwaysRequestDesktopSite,
option: Preferences.General.alwaysRequestDesktopSite))
}
#if !NO_REWARDS
display.rows.append({
var row = BoolRow(title: Strings.HideRewardsIcon, option: Preferences.Rewards.hideRewardsIcon)
row.detailText = Strings.HideRewardsIconSubtitle
row.cellClass = MultilineSubtitleCell.self
return row
}())
#endif

return general
return display
}()

private lazy var syncSection: Section = {
Expand Down Expand Up @@ -499,6 +518,7 @@ fileprivate class MultilineSubtitleCell: SubtitleCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
textLabel?.numberOfLines = 0
detailTextLabel?.numberOfLines = 0
}

required init?(coder aDecoder: NSCoder) {
Expand Down