mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add settings scene.
This commit is contained in:
@@ -7,28 +7,146 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Account
|
||||
|
||||
class SettingsViewController: UITableViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@IBOutlet weak var refreshIntervalLabel: UILabel!
|
||||
@IBOutlet weak var timelineSortOrderSwitch: UISwitch!
|
||||
|
||||
weak var presentingParentController: UIViewController?
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
if AppDefaults.timelineSortDirection == .orderedAscending {
|
||||
timelineSortOrderSwitch.isOn = true
|
||||
} else {
|
||||
timelineSortOrderSwitch.isOn = false
|
||||
}
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
refreshIntervalLabel.text = AppDefaults.refreshInterval.description()
|
||||
}
|
||||
|
||||
/*
|
||||
// MARK: - Navigation
|
||||
|
||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
// Get the new view controller using segue.destination.
|
||||
// Pass the selected object to the new view controller.
|
||||
}
|
||||
*/
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
|
||||
switch indexPath.section {
|
||||
case 0:
|
||||
print("Accounts isn't ready yet")
|
||||
case 1:
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
let timeline = UIStoryboard.settings.instantiateController(ofType: AboutViewController.self)
|
||||
self.navigationController?.pushViewController(timeline, animated: true)
|
||||
case 1:
|
||||
UIApplication.shared.open(URL(string: "https://ranchero.com/netnewswire/")!, options: [:])
|
||||
case 2:
|
||||
UIApplication.shared.open(URL(string: "https://github.com/brentsimmons/NetNewsWire")!, options: [:])
|
||||
case 3:
|
||||
UIApplication.shared.open(URL(string: "https://github.com/brentsimmons/NetNewsWire/issues")!, options: [:])
|
||||
default:
|
||||
UIApplication.shared.open(URL(string: "https://github.com/brentsimmons/NetNewsWire/tree/master/Technotes")!, options: [:])
|
||||
}
|
||||
case 2:
|
||||
UIApplication.shared.open(URL(string: "https://appcamp4girls.com/contribute/")!, options: [:])
|
||||
default:
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
let timeline = UIStoryboard.settings.instantiateController(ofType: RefreshIntervalViewController.self)
|
||||
self.navigationController?.pushViewController(timeline, animated: true)
|
||||
case 1:
|
||||
addFeed()
|
||||
case 2:
|
||||
importOPML()
|
||||
case 3:
|
||||
exportOPML()
|
||||
default:
|
||||
print("export")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@IBAction func done(_ sender: Any) {
|
||||
dismiss(animated: true)
|
||||
}
|
||||
|
||||
@IBAction func switchTimelineOrder(_ sender: Any) {
|
||||
if timelineSortOrderSwitch.isOn {
|
||||
AppDefaults.timelineSortDirection = .orderedAscending
|
||||
} else {
|
||||
AppDefaults.timelineSortDirection = .orderedDescending
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: OPML Document Picker
|
||||
|
||||
extension SettingsViewController: UIDocumentPickerDelegate {
|
||||
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
|
||||
for url in urls {
|
||||
do {
|
||||
try OPMLImporter.parseAndImport(fileURL: url, account: AccountManager.shared.localAccount)
|
||||
} catch {
|
||||
presentError(title: "OPML Import Error", message: error.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private extension SettingsViewController {
|
||||
|
||||
func addFeed() {
|
||||
|
||||
let appNewsURLString = "https://nnw.ranchero.com/feed.json"
|
||||
if AccountManager.shared.anyAccountHasFeedWithURL(appNewsURLString) {
|
||||
presentError(title: "Subscribe", message: "You are already subscribed to the NetNewsWire news feed.")
|
||||
return
|
||||
}
|
||||
|
||||
self.dismiss(animated: true)
|
||||
|
||||
let addNavViewController = UIStoryboard.add.instantiateInitialViewController() as! UINavigationController
|
||||
let addViewController = addNavViewController.topViewController as! AddContainerViewController
|
||||
addNavViewController.modalPresentationStyle = .formSheet
|
||||
addViewController.initialFeed = appNewsURLString
|
||||
addViewController.initialFeedName = "NetNewsWire News"
|
||||
|
||||
presentingParentController?.present(addNavViewController, animated: true)
|
||||
|
||||
}
|
||||
|
||||
func importOPML() {
|
||||
|
||||
let docPicker = UIDocumentPickerViewController(documentTypes: ["public.xml", "org.opml.opml"], in: .import)
|
||||
docPicker.delegate = self
|
||||
docPicker.modalPresentationStyle = .formSheet
|
||||
self.present(docPicker, animated: true)
|
||||
|
||||
}
|
||||
|
||||
func exportOPML() {
|
||||
|
||||
let filename = "MySubscriptions.opml"
|
||||
let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent(filename)
|
||||
let opmlString = OPMLExporter.OPMLString(with: AccountManager.shared.localAccount, title: filename)
|
||||
do {
|
||||
try opmlString.write(to: tempFile, atomically: true, encoding: String.Encoding.utf8)
|
||||
} catch {
|
||||
self.presentError(title: "OPML Export Error", message: error.localizedDescription)
|
||||
}
|
||||
|
||||
let docPicker = UIDocumentPickerViewController(url: tempFile, in: .exportToService)
|
||||
docPicker.modalPresentationStyle = .formSheet
|
||||
self.present(docPicker, animated: true)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user