diff --git a/Core/UserDefaultsPropertyWrapper.swift b/Core/UserDefaultsPropertyWrapper.swift index 57f4b5a871..b386b3da5b 100644 --- a/Core/UserDefaultsPropertyWrapper.swift +++ b/Core/UserDefaultsPropertyWrapper.swift @@ -57,6 +57,7 @@ public struct UserDefaultsWrapper { case legacyCovidInfo = "com.duckduckgo.ios.home.covidInfo" case lastConfigurationRefreshDate = "com.duckduckgo.ios.lastConfigurationRefreshDate" + case lastConfigurationUpdateDate = "com.duckduckgo.ios.lastConfigurationUpdateDate" case lastRemoteMessagingRefreshDate = "com.duckduckgo.ios.lastRemoteMessagingRefreshDate" case doNotSell = "com.duckduckgo.ios.sendDoNotSell" diff --git a/DuckDuckGo/Base.lproj/OmniBar.xib b/DuckDuckGo/Base.lproj/OmniBar.xib index b72d90e54d..95dfd30ef1 100644 --- a/DuckDuckGo/Base.lproj/OmniBar.xib +++ b/DuckDuckGo/Base.lproj/OmniBar.xib @@ -441,7 +441,7 @@ - + diff --git a/DuckDuckGo/BlankSnapshotViewController.swift b/DuckDuckGo/BlankSnapshotViewController.swift index 8de797a421..5537036a85 100644 --- a/DuckDuckGo/BlankSnapshotViewController.swift +++ b/DuckDuckGo/BlankSnapshotViewController.swift @@ -127,6 +127,7 @@ class BlankSnapshotViewController: UIViewController { } extension BlankSnapshotViewController: OmniBarDelegate { + func onVoiceSearchPressed() { // No-op } @@ -143,10 +144,6 @@ extension BlankSnapshotViewController: OmniBarDelegate { userInteractionDetected() } - func onSettingsLongPressed() { - userInteractionDetected() - } - func onTextFieldDidBeginEditing(_ omniBar: OmniBar) -> Bool { DispatchQueue.main.async { self.viewCoordinator.omniBar.resignFirstResponder() diff --git a/DuckDuckGo/ConfigurationURLDebugViewController.swift b/DuckDuckGo/ConfigurationURLDebugViewController.swift index 6f2e6eaacc..a1f4fcea2e 100644 --- a/DuckDuckGo/ConfigurationURLDebugViewController.swift +++ b/DuckDuckGo/ConfigurationURLDebugViewController.swift @@ -21,6 +21,7 @@ import UIKit import WebKit import Core import Configuration +import DesignResourcesKit final class ConfigurationURLDebugViewController: UITableViewController { @@ -42,11 +43,21 @@ final class ConfigurationURLDebugViewController: UITableViewController { } + private let dateFormatter: DateFormatter = { + let formatter = DateFormatter() + formatter.dateStyle = .medium + formatter.timeStyle = .long + return formatter + }() + private var customURLProvider = CustomConfigurationURLProvider() @UserDefaultsWrapper(key: .lastConfigurationRefreshDate, defaultValue: .distantPast) private var lastConfigurationRefreshDate: Date + @UserDefaultsWrapper(key: .lastConfigurationUpdateDate, defaultValue: nil) + private var lastConfigurationUpdateDate: Date? + @UserDefaultsWrapper(key: .privacyConfigCustomURL, defaultValue: nil) private var privacyConfigCustomURL: String? { didSet { @@ -65,7 +76,7 @@ final class ConfigurationURLDebugViewController: UITableViewController { private func url(for row: CustomURLsRows) -> String { switch row { - case .privacyConfigURL: return customURLProvider.url(for: .privacyConfiguration).absoluteString + case .privacyConfigURL: return customURL(for: row) ?? customURLProvider.url(for: .privacyConfiguration).absoluteString } } @@ -81,17 +92,20 @@ final class ConfigurationURLDebugViewController: UITableViewController { case .assetsUpdated(let protectionsUpdated): if protectionsUpdated { ContentBlocking.shared.contentBlockingManager.scheduleCompilation() + DispatchQueue.main.async { + self.lastConfigurationUpdateDate = Date() + } } DispatchQueue.main.async { tableView?.reloadData() } + case .noData: break } } } - override func viewDidLoad() { super.viewDidLoad() } @@ -115,8 +129,9 @@ final class ConfigurationURLDebugViewController: UITableViewController { } cell.title.text = row.title cell.subtitle.text = url(for: row) - cell.switchView.isOn = customURL(for: row) != nil - cell.switchView.addAction(makeSwitchViewAction(for: row), for: .valueChanged) + cell.subtitle.textColor = customURL(for: row) != nil ? UIColor(designSystemColor: .accent) : .black + cell.ternary.text = lastConfigurationUpdateDate != nil ? dateFormatter.string(from: lastConfigurationUpdateDate!) : "-" + cell.refresh.addAction(makeAction(for: row), for: .allEvents) return cell } @@ -125,15 +140,11 @@ final class ConfigurationURLDebugViewController: UITableViewController { presentCustomURLAlert(for: row) } - private func makeSwitchViewAction(for row: CustomURLsRows) -> UIAction { - UIAction { [weak self] act in - guard let switchView = act.sender as? UISwitch else { fatalError("Wrong view") } - if switchView.isOn { - self?.presentCustomURLAlert(for: row) - } else { - self?.setCustomURL(nil, for: row) - self?.tableView.reloadData() - } + private func makeAction(for row: CustomURLsRows) -> UIAction { + UIAction { [weak self] _ in + self?.lastConfigurationRefreshDate = Date.distantPast + self?.fetchAssets() + self?.tableView.reloadData() } } @@ -147,6 +158,13 @@ final class ConfigurationURLDebugViewController: UITableViewController { } alert.addAction(cancelAction) + if customURL(for: row) != nil { + let resetToDefaultAction = UIAlertAction(title: "Reset to default URL", style: .default) { _ in + self.privacyConfigCustomURL = nil + } + alert.addAction(resetToDefaultAction) + } + let submitAction = UIAlertAction(title: "Override", style: .default) { _ in self.setCustomURL(alert.textFields?.first?.text, for: row) self.tableView.reloadData() @@ -194,6 +212,7 @@ final class ConfigurationURLTableViewCell: UITableViewCell { @IBOutlet weak var title: UILabel! @IBOutlet weak var subtitle: UILabel! - @IBOutlet weak var switchView: UISwitch! - + @IBOutlet weak var refresh: UIButton! + @IBOutlet weak var ternary: UILabel! + } diff --git a/DuckDuckGo/Debug.storyboard b/DuckDuckGo/Debug.storyboard index 86e23f022b..c102ebb2e6 100644 --- a/DuckDuckGo/Debug.storyboard +++ b/DuckDuckGo/Debug.storyboard @@ -4,6 +4,7 @@ + @@ -737,37 +738,45 @@ - + - + - - + + - + + - - - + @@ -779,8 +788,9 @@ - - + + + @@ -799,6 +809,10 @@ + + + + diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index 1244a57657..90ff4af2e7 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -1376,7 +1376,15 @@ extension MainViewController: OmniBarDelegate { guard let link = currentTab?.link else { return } currentTab?.onShareAction(forLink: link, fromView: viewCoordinator.omniBar.shareButton, orginatedFromMenu: false) } - + + func onShareLongPressed() { + if featureFlagger.isFeatureOn(.debugMenu) || isDebugBuild { + segueToDebugSettings() + } else { + onSharePressed() + } + } + func onVoiceSearchPressed() { SpeechRecognizer.requestMicAccess { permission in if permission { diff --git a/DuckDuckGo/OmniBar.swift b/DuckDuckGo/OmniBar.swift index e995c69f0a..b40b0854ca 100644 --- a/DuckDuckGo/OmniBar.swift +++ b/DuckDuckGo/OmniBar.swift @@ -92,7 +92,8 @@ class OmniBar: UIView { super.awakeFromNib() configureMenuButton() configureTextField() - configureSettingsButton() + configureSettingsLongPressButton() + configureShareLongPressButton() registerNotifications() configureSeparator() @@ -104,18 +105,30 @@ class OmniBar: UIView { privacyInfoContainer.isHidden = true } - private func configureSettingsButton() { - let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:))) + private func configureSettingsLongPressButton() { + let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleSettingsLongPress(_:))) longPressGesture.minimumPressDuration = 0.7 settingsButton.addGestureRecognizer(longPressGesture) } - @objc private func handleLongPress(_ gesture: UILongPressGestureRecognizer) { + private func configureShareLongPressButton() { + let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleShareLongPress(_:))) + longPressGesture.minimumPressDuration = 0.7 + shareButton.addGestureRecognizer(longPressGesture) + } + + @objc private func handleSettingsLongPress(_ gesture: UILongPressGestureRecognizer) { if gesture.state == .began { omniDelegate?.onSettingsLongPressed() } } + @objc private func handleShareLongPress(_ gesture: UILongPressGestureRecognizer) { + if gesture.state == .began { + omniDelegate?.onShareLongPressed() + } + } + private func registerNotifications() { NotificationCenter.default.addObserver(self, selector: #selector(textDidChange), diff --git a/DuckDuckGo/OmniBarDelegate.swift b/DuckDuckGo/OmniBarDelegate.swift index 1e5c7e452c..de8a977cef 100644 --- a/DuckDuckGo/OmniBarDelegate.swift +++ b/DuckDuckGo/OmniBarDelegate.swift @@ -32,7 +32,7 @@ protocol OmniBarDelegate: AnyObject { func onPrivacyIconPressed() func onMenuPressed() - + func onBookmarksPressed() func onSettingsPressed() @@ -50,7 +50,9 @@ protocol OmniBarDelegate: AnyObject { func onForwardPressed() func onSharePressed() - + + func onShareLongPressed() + func onTextFieldWillBeginEditing(_ omniBar: OmniBar) // Returns whether field should select the text or not @@ -83,7 +85,11 @@ extension OmniBarDelegate { func onMenuPressed() { } - + + func onShareLongPressed() { + + } + func onBookmarksPressed() { } @@ -91,7 +97,11 @@ extension OmniBarDelegate { func onSettingsPressed() { } - + + func onSettingsLongPressed() { + + } + func onCancelPressed() { }