Files
appchk-app/main/Requests/TVCDomains.swift

86 lines
2.6 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import UIKit
class TVCDomains: UITableViewController, UISearchBarDelegate, FilterPipelineDelegate {
lazy var source = GroupedDomainDataSource(withDelegate: self, parent: nil)
@IBOutlet private var filterButton: UIBarButtonItem!
@IBOutlet private var filterButtonDetail: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
NotifyDateFilterChanged.observe(call: #selector(didChangeDateFilter), on: self)
didChangeDateFilter()
}
private var didLoadAlready = false
override func viewDidAppear(_ animated: Bool) {
if !didLoadAlready {
didLoadAlready = true
source.reloadFromSource()
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let index = tableView.indexPathForSelectedRow?.row {
(segue.destination as? TVCHosts)?.parentDomain = source[index].domain
}
}
// MARK: - Search
@IBAction private func searchButtonTapped(_ sender: UIBarButtonItem) {
source.toggleSearch()
}
// MARK: - Filter
@IBAction private func filterButtonTapped(_ sender: UIBarButtonItem) {
let vc = self.storyboard!.instantiateViewController(withIdentifier: "domainFilter")
vc.modalPresentationStyle = .custom
if #available(iOS 13.0, *) {
vc.isModalInPresentation = true
}
present(vc, animated: true)
}
@objc private func didChangeDateFilter() {
switch Pref.DateFilter.Kind {
case .ABRange: // read start/end time
self.filterButtonDetail.title = "AB"
self.filterButton.image = UIImage(named: "filter-filled")
case .LastXMin: // most recent
let lastXMin = Pref.DateFilter.LastXMin
if lastXMin == 0 { fallthrough }
self.filterButtonDetail.title = TimeFormat(.abbreviated).from(minutes: lastXMin)
self.filterButton.image = UIImage(named: "filter-filled")
default:
self.filterButtonDetail.title = ""
self.filterButton.image = UIImage(named: "filter-clear")
}
}
// MARK: - Table View Data Source
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { source.numberOfRows }
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DomainCell")!
let entry = source[indexPath.row]
cell.textLabel?.text = entry.domain
cell.detailTextLabel?.text = entry.detailCellText
cell.imageView?.image = entry.options?.tableRowImage()
return cell
}
func rowNeedsUpdate(_ row: Int) {
let entry = source[row]
let cell = tableView.cellForRow(at: IndexPath(row: row))
cell?.detailTextLabel?.text = entry.detailCellText
cell?.imageView?.image = entry.options?.tableRowImage()
}
}