Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Dec 18, 2023
1 parent 59bc453 commit a197996
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 41 deletions.
1 change: 1 addition & 0 deletions Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public struct UserDefaultsWrapper<T> {
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"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Base.lproj/OmniBar.xib
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@
</objects>
<designables>
<designable name="fqM-N4-jNd">
<size key="intrinsicContentSize" width="5" height="21"/>
<size key="intrinsicContentSize" width="10" height="22"/>
</designable>
</designables>
<resources>
Expand Down
5 changes: 1 addition & 4 deletions DuckDuckGo/BlankSnapshotViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class BlankSnapshotViewController: UIViewController {
}

extension BlankSnapshotViewController: OmniBarDelegate {

func onVoiceSearchPressed() {
// No-op
}
Expand All @@ -143,10 +144,6 @@ extension BlankSnapshotViewController: OmniBarDelegate {
userInteractionDetected()
}

func onSettingsLongPressed() {
userInteractionDetected()
}

func onTextFieldDidBeginEditing(_ omniBar: OmniBar) -> Bool {
DispatchQueue.main.async {
self.viewCoordinator.omniBar.resignFirstResponder()
Expand Down
49 changes: 34 additions & 15 deletions DuckDuckGo/ConfigurationURLDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import UIKit
import WebKit
import Core
import Configuration
import DesignResourcesKit

final class ConfigurationURLDebugViewController: UITableViewController {

Expand All @@ -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 {
Expand All @@ -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
}
}

Expand All @@ -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()
}
Expand All @@ -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
}

Expand All @@ -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()
}
}

Expand All @@ -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()
Expand Down Expand Up @@ -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!

}
38 changes: 26 additions & 12 deletions DuckDuckGo/Debug.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -737,37 +738,45 @@
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="ConfigurationURLTableViewCell" id="jmL-W2-PZT" customClass="ConfigurationURLTableViewCell" customModule="DuckDuckGo" customModuleProvider="target">
<rect key="frame" x="0.0" y="50" width="414" height="63.5"/>
<rect key="frame" x="0.0" y="50" width="414" height="70.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="jmL-W2-PZT" id="8nr-nN-SdE">
<rect key="frame" x="0.0" y="0.0" width="414" height="63.5"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="70.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="gWn-YG-iFq">
<rect key="frame" x="20" y="11" width="374" height="41.5"/>
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="gWn-YG-iFq">
<rect key="frame" x="20" y="11" width="374" height="48.5"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="Uzf-Zx-YVo">
<rect key="frame" x="0.0" y="0.5" width="317" height="41"/>
<rect key="frame" x="0.0" y="0.0" width="44" height="48.5"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="ybz-8K-XIL">
<rect key="frame" x="0.0" y="0.0" width="317" height="20.5"/>
<rect key="frame" x="0.0" y="0.0" width="44" height="16"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Subtitle" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="wBo-BZ-9Gq">
<rect key="frame" x="0.0" y="20.5" width="317" height="20.5"/>
<rect key="frame" x="0.0" y="16" width="44" height="16"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" name="accent"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AZq-qk-Hl7">
<rect key="frame" x="0.0" y="32.5" width="44" height="16"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="H4R-Em-ad2">
<rect key="frame" x="325" y="5.5" width="51" height="31"/>
</switch>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nzb-TB-wuL">
<rect key="frame" x="350" y="0.0" width="24" height="48.5"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="Reload-24"/>
</button>
</subviews>
</stackView>
</subviews>
Expand All @@ -779,8 +788,9 @@
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="subtitle" destination="wBo-BZ-9Gq" id="G1W-Cq-xFu"/>
<outlet property="switchView" destination="H4R-Em-ad2" id="i2C-lV-vBj"/>
<outlet property="refresh" destination="nzb-TB-wuL" id="gOH-u0-irx"/>
<outlet property="subtitle" destination="wBo-BZ-9Gq" id="W8K-Jp-1as"/>
<outlet property="ternary" destination="AZq-qk-Hl7" id="nrL-5O-Snx"/>
<outlet property="title" destination="ybz-8K-XIL" id="bE8-1t-ASx"/>
</connections>
</tableViewCell>
Expand All @@ -799,6 +809,10 @@
</scenes>
<resources>
<image name="Logo" width="128" height="128"/>
<image name="Reload-24" width="24" height="24"/>
<namedColor name="accent">
<color red="0.22352941176470589" green="0.41176470588235292" blue="0.93725490196078431" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="labelColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
Expand Down
10 changes: 9 additions & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 17 additions & 4 deletions DuckDuckGo/OmniBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class OmniBar: UIView {
super.awakeFromNib()
configureMenuButton()
configureTextField()
configureSettingsButton()
configureSettingsLongPressButton()
configureShareLongPressButton()
registerNotifications()

configureSeparator()
Expand All @@ -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),
Expand Down
18 changes: 14 additions & 4 deletions DuckDuckGo/OmniBarDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protocol OmniBarDelegate: AnyObject {
func onPrivacyIconPressed()

func onMenuPressed()

func onBookmarksPressed()

func onSettingsPressed()
Expand All @@ -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
Expand Down Expand Up @@ -83,15 +85,23 @@ extension OmniBarDelegate {
func onMenuPressed() {

}


func onShareLongPressed() {

}

func onBookmarksPressed() {

}

func onSettingsPressed() {

}


func onSettingsLongPressed() {

}

func onCancelPressed() {

}
Expand Down

0 comments on commit a197996

Please sign in to comment.