Add (+) button to domain filter view
This commit is contained in:
@@ -178,7 +178,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kmY-ot-lJW">
|
||||
<rect key="frame" x="256" y="6" width="45" height="31"/>
|
||||
<rect key="frame" x="256" y="6" width="44" height="31"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
|
||||
<connections>
|
||||
<action selector="toggleVPNProxy:" destination="qdB-ZO-LHY" eventType="valueChanged" id="y95-2Z-Uep"/>
|
||||
@@ -202,7 +202,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="9Ko-sD-7x0">
|
||||
<rect key="frame" x="95" y="7" width="124" height="30"/>
|
||||
<rect key="frame" x="94" y="7" width="125" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<state key="normal" title="Export DB"/>
|
||||
<connections>
|
||||
@@ -339,7 +339,13 @@
|
||||
<outlet property="delegate" destination="q3B-Yi-1bx" id="02X-f0-d1a"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
<navigationItem key="navigationItem" title="Domains" id="FWA-IG-VIb"/>
|
||||
<navigationItem key="navigationItem" title="Domains" id="FWA-IG-VIb">
|
||||
<barButtonItem key="rightBarButtonItem" systemItem="add" id="RFW-bp-wwH">
|
||||
<connections>
|
||||
<action selector="addNewFilter" destination="q3B-Yi-1bx" id="JID-eH-y0p"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
</navigationItem>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="Xzo-dO-WpK" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
|
||||
@@ -2,19 +2,32 @@ import UIKit
|
||||
|
||||
// MARK: Basic Alerts
|
||||
|
||||
/// - Parameters:
|
||||
/// - buttonText: Default: "Dismiss"
|
||||
func Alert(title: String?, text: String?, buttonText: String = "Dismiss") -> UIAlertController {
|
||||
let alert = UIAlertController(title: title, message: text, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: buttonText, style: .cancel, handler: nil))
|
||||
return alert
|
||||
}
|
||||
|
||||
/// - Parameters:
|
||||
/// - buttonText: Default: "Dismiss"
|
||||
func ErrorAlert(_ error: Error, buttonText: String = "Dismiss") -> UIAlertController {
|
||||
return Alert(title: "Error", text: error.localizedDescription, buttonText: buttonText)
|
||||
}
|
||||
|
||||
func AskAlert(title: String?, text: String?, buttonText: String = "Continue", buttonStyle: UIAlertAction.Style = .default, action: @escaping () -> Void) -> UIAlertController {
|
||||
/// - Parameters:
|
||||
/// - buttonText: Default: "Dismiss"
|
||||
func ErrorAlert(_ errorDescription: String, buttonText: String = "Dismiss") -> UIAlertController {
|
||||
return Alert(title: "Error", text: errorDescription, buttonText: buttonText)
|
||||
}
|
||||
|
||||
/// - Parameters:
|
||||
/// - buttonText: Default: "Continue"
|
||||
/// - buttonStyle: Default: `.default`
|
||||
func AskAlert(title: String?, text: String?, buttonText: String = "Continue", buttonStyle: UIAlertAction.Style = .default, action: @escaping (UIAlertController) -> Void) -> UIAlertController {
|
||||
let alert = Alert(title: title, text: text, buttonText: "Cancel")
|
||||
alert.addAction(UIAlertAction(title: buttonText, style: buttonStyle) { _ in action() })
|
||||
alert.addAction(UIAlertAction(title: buttonText, style: buttonStyle) { _ in action(alert) })
|
||||
return alert
|
||||
}
|
||||
|
||||
|
||||
@@ -55,15 +55,11 @@ extension String {
|
||||
ending = rld + "." + ending
|
||||
}
|
||||
return (domain: ending, host: parts.joined(separator: "."))
|
||||
|
||||
// var allDots = enumerated().compactMap { $1 == "." ? $0 : nil }
|
||||
// let d1 = allDots.popLast() // we dont care about TLD
|
||||
// guard let d2 = allDots.popLast() else {
|
||||
// return (domain: self, host: nil) // no subdomains, just plain SLD
|
||||
// }
|
||||
// // TODO: check third level domains
|
||||
//// let d3 = allDots.popLast()
|
||||
// return (String(suffix(count - d2 - 1)), String(prefix(d2)))
|
||||
}
|
||||
/// Returns `true` if String matches list of known second level domains (e.g., `co.uk`).
|
||||
func isKnownSLD() -> Bool {
|
||||
let parts = components(separatedBy: ".")
|
||||
return parts.count == 2 && listOfSLDs[parts.last!]?[parts.first!] ?? false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,27 @@ class TVCFilter: UITableViewController, EditActionsRemove {
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
@IBAction private func addNewFilter() {
|
||||
let desc: String
|
||||
switch currentFilter {
|
||||
case .blocked: desc = "Enter the domain name you wish to block."
|
||||
case .ignored: desc = "Enter the domain name you wish to ignore."
|
||||
default: return
|
||||
}
|
||||
let alert = AskAlert(title: "Create new filter", text: desc, buttonText: "Add") {
|
||||
guard let dom = $0.textFields?.first?.text else {
|
||||
return
|
||||
}
|
||||
guard dom.contains("."), !dom.isKnownSLD() else {
|
||||
ErrorAlert("Entered domain is not valid. Filter can't match country TLD only.").presentIn(self)
|
||||
return
|
||||
}
|
||||
DBWrp.updateFilter(dom, add: self.currentFilter)
|
||||
}
|
||||
alert.addTextField { $0.placeholder = "cdn.domain.tld" }
|
||||
alert.presentIn(self)
|
||||
}
|
||||
|
||||
// MARK: - Table View Delegate
|
||||
|
||||
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { dataSource.count }
|
||||
|
||||
@@ -56,7 +56,7 @@ class TVCSettings: UITableViewController {
|
||||
AskAlert(title: "Clear results?", text: """
|
||||
You are about to delete all results that have been logged in the past. Your preference for blocked and ignored domains is preserved.
|
||||
Continue?
|
||||
""", buttonText: "Delete", buttonStyle: .destructive) {
|
||||
""", buttonText: "Delete", buttonStyle: .destructive) { _ in
|
||||
DBWrp.deleteHistory()
|
||||
}.presentIn(self)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user