diff --git a/main/Base.lproj/Main.storyboard b/main/Base.lproj/Main.storyboard index 093dff1..644501c 100644 --- a/main/Base.lproj/Main.storyboard +++ b/main/Base.lproj/Main.storyboard @@ -727,7 +727,7 @@ Duration: 60:00 - + diff --git a/main/DB/DBWrapper.swift b/main/DB/DBWrapper.swift index 497f915..ae8b903 100644 --- a/main/DB/DBWrapper.swift +++ b/main/DB/DBWrapper.swift @@ -30,7 +30,7 @@ class DBWrapper { } 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) { diff --git a/main/DB/SQDB.swift b/main/DB/SQDB.swift index c25581d..2293668 100644 --- a/main/DB/SQDB.swift +++ b/main/DB/SQDB.swift @@ -266,7 +266,7 @@ extension SQLiteDatabase { // MARK: read 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) { (key: readText($0, 0) ?? "", value: FilterOptions(rawValue: sqlite3_column_int($0, 1))) diff --git a/main/Settings/TVCFilter.swift b/main/Settings/TVCFilter.swift index 2125f38..6e71602 100644 --- a/main/Settings/TVCFilter.swift +++ b/main/Settings/TVCFilter.swift @@ -6,9 +6,9 @@ class TVCFilter: UITableViewController, EditActionsRemove { override func viewDidLoad() { super.viewDidLoad() - if #available(iOS 10.0, *) { - tableView.refreshControl = UIRefreshControl(call: #selector(reloadDataSource), on: self) - } +// if #available(iOS 10.0, *) { +// tableView.refreshControl = UIRefreshControl(call: #selector(reloadDataSource), on: self) +// } NotifyFilterChanged.observe(call: #selector(reloadDataSource), on: self) reloadDataSource() } @@ -46,16 +46,47 @@ class TVCFilter: UITableViewController, EditActionsRemove { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "DomainFilterCell")! cell.textLabel?.text = dataSource[indexPath.row] + if cell.gestureRecognizers?.isEmpty ?? true { + cell.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(didLongTap))) + } return cell } // MARK: - Editing 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) - self.dataSource.remove(at: index.row) - self.tableView.deleteRows(at: [index], with: .automatic) + dataSource.remove(at: index.row) + tableView.deleteRows(at: [index], with: .automatic) 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 + } }