2019-11-07 13:40:10 +01:00
|
|
|
//
|
2019-11-15 03:11:41 +01:00
|
|
|
// WebFeedInspectorViewController.swift
|
2019-11-07 13:40:10 +01:00
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 11/6/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Account
|
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
class WebFeedInspectorViewController: UITableViewController {
|
2019-11-07 13:40:10 +01:00
|
|
|
|
2019-11-14 00:02:14 +01:00
|
|
|
static let preferredContentSizeForFormSheetDisplay = CGSize(width: 460.0, height: 500.0)
|
2019-11-07 13:40:10 +01:00
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
var webFeed: WebFeed!
|
2019-11-07 13:40:10 +01:00
|
|
|
@IBOutlet weak var nameTextField: UITextField!
|
|
|
|
@IBOutlet weak var notifyAboutNewArticlesSwitch: UISwitch!
|
|
|
|
@IBOutlet weak var alwaysShowReaderViewSwitch: UISwitch!
|
|
|
|
@IBOutlet weak var homePageLabel: InteractiveLabel!
|
|
|
|
@IBOutlet weak var feedURLLabel: InteractiveLabel!
|
|
|
|
|
|
|
|
private var headerView: InspectorIconHeaderView?
|
|
|
|
private var iconImage: IconImage {
|
2019-11-15 03:11:41 +01:00
|
|
|
if let feedIcon = appDelegate.webFeedIconDownloader.icon(for: webFeed) {
|
2019-11-07 13:40:10 +01:00
|
|
|
return feedIcon
|
|
|
|
}
|
2020-01-07 22:17:00 +01:00
|
|
|
if let favicon = appDelegate.faviconDownloader.faviconAsIcon(for: webFeed) {
|
2019-11-07 13:40:10 +01:00
|
|
|
return favicon
|
|
|
|
}
|
2019-11-15 03:11:41 +01:00
|
|
|
return FaviconGenerator.favicon(webFeed)
|
2019-11-07 13:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
tableView.register(InspectorIconHeaderView.self, forHeaderFooterViewReuseIdentifier: "SectionHeader")
|
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
navigationItem.title = webFeed.nameForDisplay
|
|
|
|
nameTextField.text = webFeed.nameForDisplay
|
2019-11-07 13:40:10 +01:00
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
notifyAboutNewArticlesSwitch.setOn(webFeed.isNotifyAboutNewArticles ?? false, animated: false)
|
|
|
|
alwaysShowReaderViewSwitch.setOn(webFeed.isArticleExtractorAlwaysOn ?? false, animated: false)
|
2019-11-07 13:40:10 +01:00
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
homePageLabel.text = webFeed.homePageURL
|
|
|
|
feedURLLabel.text = webFeed.url
|
2019-11-07 13:40:10 +01:00
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil)
|
2019-11-07 13:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
2019-11-15 03:11:41 +01:00
|
|
|
if nameTextField.text != webFeed.nameForDisplay {
|
2019-11-07 13:40:10 +01:00
|
|
|
let nameText = nameTextField.text ?? ""
|
2019-11-15 03:11:41 +01:00
|
|
|
let newName = nameText.isEmpty ? (webFeed.name ?? NSLocalizedString("Untitled", comment: "Feed name")) : nameText
|
|
|
|
webFeed.rename(to: newName) { _ in }
|
2019-11-07 13:40:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Notifications
|
2019-11-15 03:11:41 +01:00
|
|
|
@objc func webFeedIconDidBecomeAvailable(_ notification: Notification) {
|
2019-11-07 13:40:10 +01:00
|
|
|
headerView?.iconView.iconImage = iconImage
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func notifyAboutNewArticlesChanged(_ sender: Any) {
|
2019-11-15 03:11:41 +01:00
|
|
|
webFeed.isNotifyAboutNewArticles = notifyAboutNewArticlesSwitch.isOn
|
2019-11-07 13:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func alwaysShowReaderViewChanged(_ sender: Any) {
|
2019-11-15 03:11:41 +01:00
|
|
|
webFeed.isArticleExtractorAlwaysOn = alwaysShowReaderViewSwitch.isOn
|
2019-11-07 13:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func done(_ sender: Any) {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Table View
|
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
extension WebFeedInspectorViewController {
|
2019-11-07 13:40:10 +01:00
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
2019-11-22 22:11:15 +01:00
|
|
|
return section == 0 ? ImageHeaderView.rowHeight : super.tableView(tableView, heightForHeaderInSection: section)
|
2019-11-07 13:40:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
|
if section == 0 {
|
|
|
|
headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as? InspectorIconHeaderView
|
|
|
|
headerView?.iconView.iconImage = iconImage
|
|
|
|
return headerView
|
|
|
|
} else {
|
|
|
|
return super.tableView(tableView, viewForHeaderInSection: section)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: UITextFieldDelegate
|
|
|
|
|
2019-11-15 03:11:41 +01:00
|
|
|
extension WebFeedInspectorViewController: UITextFieldDelegate {
|
2019-11-07 13:40:10 +01:00
|
|
|
|
|
|
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
|
|
|
textField.resignFirstResponder()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|