From b8660c9a35dba8285a6bd84ea3dc18263f518f58 Mon Sep 17 00:00:00 2001 From: relikd Date: Sat, 5 Sep 2020 20:08:37 +0200 Subject: [PATCH] Jump from Recordings to Requests tab --- main/GUI/Base.lproj/Recordings.storyboard | 2 +- main/Recordings/TVCRecordingDetails.swift | 59 +++++++++++++++++++++++ main/Requests/VCDateFilter.swift | 9 ++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/main/GUI/Base.lproj/Recordings.storyboard b/main/GUI/Base.lproj/Recordings.storyboard index 01277dd..9142a49 100644 --- a/main/GUI/Base.lproj/Recordings.storyboard +++ b/main/GUI/Base.lproj/Recordings.storyboard @@ -191,7 +191,7 @@ - + diff --git a/main/Recordings/TVCRecordingDetails.swift b/main/Recordings/TVCRecordingDetails.swift index c863331..7a53f64 100644 --- a/main/Recordings/TVCRecordingDetails.swift +++ b/main/Recordings/TVCRecordingDetails.swift @@ -118,4 +118,63 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove { shareButton.isEnabled = !noResults return true } + + + // MARK: - Tap to Copy + + private var rowToCopy: Int = Int.max + + override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { + if rowToCopy == indexPath.row { + UIMenuController.shared.setMenuVisible(false, animated: true) + rowToCopy = Int.max + return nil + } + rowToCopy = indexPath.row + self.becomeFirstResponder() + let cell = tableView.cellForRow(at: indexPath)! + UIMenuController.shared.setTargetRect(cell.bounds, in: cell) + UIMenuController.shared.menuItems = [ + .init(title: "All requests", action: #selector(openInLogs)), +// .init(title: "CoOccurrence", action: #selector(openCoOccurrence)) + ] + UIMenuController.shared.setMenuVisible(true, animated: true) + return nil + } + + override var canBecomeFirstResponder: Bool { true } + + override func copy(_ sender: Any?) { + UIPasteboard.general.string = getDomain() + rowToCopy = Int.max + } + + @objc private func openInLogs() { + guard let selectedDomain = getDomain(), + let tabBar = tabBarController as? TBCMain, + let tab = tabBar.openTab(0) as? TVCDomains else { + return + } + VCDateFilter.disableFilter() + tab.pushOpen(domain: selectedDomain) + } + + private func getDomain() -> String? { + if showRaw { + guard rowToCopy < dataSourceRaw.count else { return nil } + return dataSourceRaw[rowToCopy].domain + } else { + guard rowToCopy < dataSourceSum.count else { return nil } + return dataSourceSum[rowToCopy].domain + } + } + +// @objc private func openCoOccurrence() { +// guard let vc: VCCoOccurrence = storyboard?.load("IBCoOccurrence") else { +// return +// } +// vc.domainName = getDomain() +// vc.isFQDN = true +// present(vc, animated: true) +// } } diff --git a/main/Requests/VCDateFilter.swift b/main/Requests/VCDateFilter.swift index 95401be..c21c640 100644 --- a/main/Requests/VCDateFilter.swift +++ b/main/Requests/VCDateFilter.swift @@ -116,4 +116,13 @@ class VCDateFilter: UIViewController, UIGestureRecognizerDelegate { NotifyDateFilterChanged.post() } } + + static func disableFilter() { + if Prefs.DateFilter.Kind <-? .Off { + Prefs.DateFilter.LastXMin = 0 + Prefs.DateFilter.RangeA = nil + Prefs.DateFilter.RangeB = nil + NotifyDateFilterChanged.post() + } + } }