DNS filters: proper sort + no cell selection + copy cell value
This commit is contained in:
@@ -727,7 +727,7 @@ Duration: 60:00</string>
|
|||||||
<scene sceneID="218-uP-X7b">
|
<scene sceneID="218-uP-X7b">
|
||||||
<objects>
|
<objects>
|
||||||
<tableViewController id="q3B-Yi-1bx" customClass="TVCFilter" customModule="AppCheck" customModuleProvider="target" sceneMemberID="viewController">
|
<tableViewController id="q3B-Yi-1bx" customClass="TVCFilter" customModule="AppCheck" customModuleProvider="target" sceneMemberID="viewController">
|
||||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="GSg-ZZ-F8J">
|
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="GSg-ZZ-F8J">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
|
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class DBWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataF_list(_ filter: FilterOptions) -> [String] {
|
func dataF_list(_ filter: FilterOptions) -> [String] {
|
||||||
Q.sync() { dataF.compactMap { $1.contains(filter) ? $0 : nil } }
|
Q.sync() { dataF.compactMap { $1.contains(filter) ? $0 : nil } }.sorted()
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataF_counts() -> (blocked: Int, ignored: Int) {
|
func dataF_counts() -> (blocked: Int, ignored: Int) {
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ extension SQLiteDatabase {
|
|||||||
// MARK: read
|
// MARK: read
|
||||||
|
|
||||||
func loadFilters() -> [String : FilterOptions]? {
|
func loadFilters() -> [String : FilterOptions]? {
|
||||||
try? run(sql: "SELECT domain, opt FROM filter ORDER BY domain ASC;", bind: nil) {
|
try? run(sql: "SELECT domain, opt FROM filter;", bind: nil) {
|
||||||
allRowsKeyed($0) {
|
allRowsKeyed($0) {
|
||||||
(key: readText($0, 0) ?? "",
|
(key: readText($0, 0) ?? "",
|
||||||
value: FilterOptions(rawValue: sqlite3_column_int($0, 1)))
|
value: FilterOptions(rawValue: sqlite3_column_int($0, 1)))
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ class TVCFilter: UITableViewController, EditActionsRemove {
|
|||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
if #available(iOS 10.0, *) {
|
// if #available(iOS 10.0, *) {
|
||||||
tableView.refreshControl = UIRefreshControl(call: #selector(reloadDataSource), on: self)
|
// tableView.refreshControl = UIRefreshControl(call: #selector(reloadDataSource), on: self)
|
||||||
}
|
// }
|
||||||
NotifyFilterChanged.observe(call: #selector(reloadDataSource), on: self)
|
NotifyFilterChanged.observe(call: #selector(reloadDataSource), on: self)
|
||||||
reloadDataSource()
|
reloadDataSource()
|
||||||
}
|
}
|
||||||
@@ -46,16 +46,47 @@ class TVCFilter: UITableViewController, EditActionsRemove {
|
|||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: "DomainFilterCell")!
|
let cell = tableView.dequeueReusableCell(withIdentifier: "DomainFilterCell")!
|
||||||
cell.textLabel?.text = dataSource[indexPath.row]
|
cell.textLabel?.text = dataSource[indexPath.row]
|
||||||
|
if cell.gestureRecognizers?.isEmpty ?? true {
|
||||||
|
cell.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(didLongTap)))
|
||||||
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Editing
|
// MARK: - Editing
|
||||||
|
|
||||||
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
|
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
|
||||||
let domain = self.dataSource[index.row]
|
let domain = dataSource[index.row]
|
||||||
DBWrp.updateFilter(domain, remove: currentFilter)
|
DBWrp.updateFilter(domain, remove: currentFilter)
|
||||||
self.dataSource.remove(at: index.row)
|
dataSource.remove(at: index.row)
|
||||||
self.tableView.deleteRows(at: [index], with: .automatic)
|
tableView.deleteRows(at: [index], with: .automatic)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Long Press Gesture
|
||||||
|
|
||||||
|
private var cellTitleCopy: String?
|
||||||
|
|
||||||
|
@objc private func didLongTap(_ sender: UILongPressGestureRecognizer) {
|
||||||
|
guard let cell = sender.view as? UITableViewCell else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sender.state == .began {
|
||||||
|
cellTitleCopy = cell.textLabel?.text
|
||||||
|
self.becomeFirstResponder()
|
||||||
|
let menu = UIMenuController.shared
|
||||||
|
// menu.setTargetRect(CGRect(origin: sender.location(in: cell), size: CGSize.zero), in: cell)
|
||||||
|
menu.setTargetRect(cell.bounds, in: cell)
|
||||||
|
menu.setMenuVisible(true, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override var canBecomeFirstResponder: Bool { get { true } }
|
||||||
|
|
||||||
|
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
||||||
|
action == #selector(UIResponderStandardEditActions.copy)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func copy(_ sender: Any?) {
|
||||||
|
UIPasteboard.general.string = cellTitleCopy
|
||||||
|
cellTitleCopy = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user