2019-10-21 18:51:33 +02:00
|
|
|
//
|
|
|
|
// SettingsViewController.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/24/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Account
|
2019-10-22 00:52:29 +02:00
|
|
|
import SafariServices
|
2019-10-21 18:51:33 +02:00
|
|
|
|
|
|
|
class SettingsViewController: UITableViewController {
|
|
|
|
|
2019-10-22 01:02:44 +02:00
|
|
|
private let appNewsURLString = "https://nnw.ranchero.com/feed.json"
|
2019-10-22 17:32:35 +02:00
|
|
|
private weak var opmlAccount: Account?
|
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
static let preferredContentSizeForFormSheetDisplay = CGSize(width: 460.0, height: 400.0)
|
|
|
|
|
|
|
|
@IBOutlet weak var refreshIntervalLabel: UILabel!
|
|
|
|
@IBOutlet weak var timelineSortOrderSwitch: UISwitch!
|
2019-10-21 23:42:58 +02:00
|
|
|
@IBOutlet weak var groupByFeedSwitch: UISwitch!
|
2019-10-22 00:19:22 +02:00
|
|
|
@IBOutlet weak var numberOfTextLinesLabel: UILabel!
|
|
|
|
@IBOutlet weak var numberOfTextLinesSteppper: UIStepper!
|
2019-10-21 18:51:33 +02:00
|
|
|
|
|
|
|
weak var presentingParentController: UIViewController?
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
// This hack mostly works around a bug in static tables with dynamic type. See: https://spin.atomicobject.com/2018/10/15/dynamic-type-static-uitableview/
|
|
|
|
NotificationCenter.default.removeObserver(tableView!, name: UIContentSizeCategory.didChangeNotification, object: nil)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
2019-10-23 02:20:35 +02:00
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange), name: .UserDidAddAccount, object: nil)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange), name: .UserDidDeleteAccount, object: nil)
|
2019-10-24 02:58:18 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange), name: .DisplayNameDidChange, object: nil)
|
2019-10-23 02:20:35 +02:00
|
|
|
|
2019-10-23 17:35:53 +02:00
|
|
|
tableView.register(UINib(nibName: "SettingsAccountTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsAccountTableViewCell")
|
2019-10-21 18:51:33 +02:00
|
|
|
tableView.register(UINib(nibName: "SettingsTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsTableViewCell")
|
2019-10-23 17:35:53 +02:00
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
|
|
|
if AppDefaults.timelineSortDirection == .orderedAscending {
|
|
|
|
timelineSortOrderSwitch.isOn = true
|
|
|
|
} else {
|
|
|
|
timelineSortOrderSwitch.isOn = false
|
|
|
|
}
|
|
|
|
|
2019-10-21 23:42:58 +02:00
|
|
|
if AppDefaults.timelineGroupByFeed {
|
|
|
|
groupByFeedSwitch.isOn = true
|
|
|
|
} else {
|
|
|
|
groupByFeedSwitch.isOn = false
|
|
|
|
}
|
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
refreshIntervalLabel.text = AppDefaults.refreshInterval.description()
|
|
|
|
|
2019-10-22 00:19:22 +02:00
|
|
|
let numberOfTextLines = AppDefaults.timelineNumberOfLines
|
|
|
|
numberOfTextLinesSteppper.value = Double(numberOfTextLines)
|
|
|
|
updateNumberOfTextLinesLabel(value: numberOfTextLines)
|
2019-10-21 18:51:33 +02:00
|
|
|
|
|
|
|
let buildLabel = NonIntrinsicLabel(frame: CGRect(x: 20.0, y: 0.0, width: 0.0, height: 0.0))
|
|
|
|
buildLabel.font = UIFont.systemFont(ofSize: 11.0)
|
|
|
|
buildLabel.textColor = UIColor.gray
|
|
|
|
buildLabel.text = "\(Bundle.main.appName) v \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))"
|
|
|
|
buildLabel.sizeToFit()
|
|
|
|
buildLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
tableView.tableFooterView = buildLabel
|
|
|
|
|
2019-10-23 02:20:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
self.tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: UITableView
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
switch section {
|
|
|
|
case 1:
|
2019-10-22 15:43:39 +02:00
|
|
|
return AccountManager.shared.accounts.count + 1
|
|
|
|
case 4:
|
2019-10-21 18:51:33 +02:00
|
|
|
let defaultNumberOfRows = super.tableView(tableView, numberOfRowsInSection: section)
|
2019-10-22 15:43:39 +02:00
|
|
|
if AccountManager.shared.activeAccounts.isEmpty || AccountManager.shared.anyAccountHasFeedWithURL(appNewsURLString) {
|
2019-10-22 01:02:44 +02:00
|
|
|
return defaultNumberOfRows - 1
|
|
|
|
}
|
|
|
|
return defaultNumberOfRows
|
2019-10-21 18:51:33 +02:00
|
|
|
default:
|
|
|
|
return super.tableView(tableView, numberOfRowsInSection: section)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
let cell: UITableViewCell
|
|
|
|
switch indexPath.section {
|
2019-10-22 15:43:39 +02:00
|
|
|
case 1:
|
2019-10-23 17:35:53 +02:00
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
let sortedAccounts = AccountManager.shared.sortedAccounts
|
|
|
|
if indexPath.row == sortedAccounts.count {
|
2019-10-23 17:35:53 +02:00
|
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "SettingsTableViewCell", for: indexPath)
|
|
|
|
cell.textLabel?.adjustsFontForContentSizeCategory = true
|
2019-10-21 18:51:33 +02:00
|
|
|
cell.textLabel?.text = NSLocalizedString("Add Account", comment: "Accounts")
|
|
|
|
} else {
|
2019-10-23 17:35:53 +02:00
|
|
|
let acctCell = tableView.dequeueReusableCell(withIdentifier: "SettingsAccountTableViewCell", for: indexPath) as! SettingsAccountTableViewCell
|
2019-10-23 18:47:21 +02:00
|
|
|
acctCell.applyThemeProperties()
|
2019-10-23 17:35:53 +02:00
|
|
|
let account = sortedAccounts[indexPath.row]
|
|
|
|
acctCell.accountImage?.image = AppAssets.image(for: account.type)
|
|
|
|
acctCell.accountNameLabel?.text = account.nameForDisplay
|
|
|
|
cell = acctCell
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
cell = super.tableView(tableView, cellForRowAt: indexPath)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
switch indexPath.section {
|
|
|
|
case 0:
|
2019-10-22 15:43:39 +02:00
|
|
|
UIApplication.shared.open(URL(string: "\(UIApplication.openSettingsURLString)")!)
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-22 15:43:39 +02:00
|
|
|
case 1:
|
2019-10-21 18:51:33 +02:00
|
|
|
let sortedAccounts = AccountManager.shared.sortedAccounts
|
|
|
|
if indexPath.row == sortedAccounts.count {
|
|
|
|
let controller = UIStoryboard.settings.instantiateController(ofType: AddAccountViewController.self)
|
|
|
|
self.navigationController?.pushViewController(controller, animated: true)
|
|
|
|
} else {
|
2019-10-24 02:58:18 +02:00
|
|
|
let controller = UIStoryboard.inspector.instantiateController(ofType: AccountInspectorViewController.self)
|
2019-10-21 18:51:33 +02:00
|
|
|
controller.account = sortedAccounts[indexPath.row]
|
|
|
|
self.navigationController?.pushViewController(controller, animated: true)
|
|
|
|
}
|
2019-10-22 15:43:39 +02:00
|
|
|
case 3:
|
2019-10-21 23:27:54 +02:00
|
|
|
switch indexPath.row {
|
|
|
|
case 0:
|
|
|
|
let timeline = UIStoryboard.settings.instantiateController(ofType: RefreshIntervalViewController.self)
|
|
|
|
self.navigationController?.pushViewController(timeline, animated: true)
|
|
|
|
case 1:
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-22 17:32:35 +02:00
|
|
|
if let sourceView = tableView.cellForRow(at: indexPath) {
|
|
|
|
let sourceRect = tableView.rectForRow(at: indexPath)
|
|
|
|
importOPML(sourceView: sourceView, sourceRect: sourceRect)
|
|
|
|
}
|
2019-10-21 23:27:54 +02:00
|
|
|
case 2:
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-22 17:32:35 +02:00
|
|
|
if let sourceView = tableView.cellForRow(at: indexPath) {
|
|
|
|
let sourceRect = tableView.rectForRow(at: indexPath)
|
|
|
|
exportOPML(sourceView: sourceView, sourceRect: sourceRect)
|
|
|
|
}
|
2019-10-21 23:27:54 +02:00
|
|
|
default:
|
2019-10-21 23:42:58 +02:00
|
|
|
break
|
2019-10-21 23:27:54 +02:00
|
|
|
}
|
2019-10-22 15:43:39 +02:00
|
|
|
case 4:
|
2019-10-21 18:51:33 +02:00
|
|
|
switch indexPath.row {
|
|
|
|
case 0:
|
|
|
|
let timeline = UIStoryboard.settings.instantiateController(ofType: AboutViewController.self)
|
|
|
|
self.navigationController?.pushViewController(timeline, animated: true)
|
|
|
|
case 1:
|
2019-10-22 00:52:29 +02:00
|
|
|
openURL("https://ranchero.com/netnewswire/")
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-21 18:51:33 +02:00
|
|
|
case 2:
|
2019-10-22 00:52:29 +02:00
|
|
|
openURL("https://github.com/brentsimmons/NetNewsWire/blob/master/Technotes/HowToSupportNetNewsWire.markdown")
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-21 18:51:33 +02:00
|
|
|
case 3:
|
2019-10-22 00:52:29 +02:00
|
|
|
openURL("https://github.com/brentsimmons/NetNewsWire")
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-21 18:51:33 +02:00
|
|
|
case 4:
|
2019-10-22 00:52:29 +02:00
|
|
|
openURL("https://github.com/brentsimmons/NetNewsWire/issues")
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-21 18:51:33 +02:00
|
|
|
case 5:
|
2019-10-22 00:52:29 +02:00
|
|
|
openURL("https://github.com/brentsimmons/NetNewsWire/tree/master/Technotes")
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-22 00:52:29 +02:00
|
|
|
case 6:
|
2019-10-21 18:51:33 +02:00
|
|
|
addFeed()
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-21 18:51:33 +02:00
|
|
|
default:
|
2019-10-22 00:52:29 +02:00
|
|
|
break
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
default:
|
2019-10-23 02:20:35 +02:00
|
|
|
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
|
|
|
|
return .none
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
2019-10-22 15:43:39 +02:00
|
|
|
if indexPath.section == 1 {
|
|
|
|
return super.tableView(tableView, heightForRowAt: IndexPath(row: 0, section: 1))
|
2019-10-21 18:51:33 +02:00
|
|
|
} else {
|
|
|
|
return super.tableView(tableView, heightForRowAt: indexPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath) -> Int {
|
2019-10-22 15:43:39 +02:00
|
|
|
if indexPath.section == 1 {
|
|
|
|
return super.tableView(tableView, indentationLevelForRowAt: IndexPath(row: 0, section: 1))
|
2019-10-21 18:51:33 +02:00
|
|
|
} else {
|
|
|
|
return super.tableView(tableView, indentationLevelForRowAt: indexPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
|
|
|
@IBAction func done(_ sender: Any) {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func switchTimelineOrder(_ sender: Any) {
|
|
|
|
if timelineSortOrderSwitch.isOn {
|
|
|
|
AppDefaults.timelineSortDirection = .orderedAscending
|
|
|
|
} else {
|
|
|
|
AppDefaults.timelineSortDirection = .orderedDescending
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-21 23:42:58 +02:00
|
|
|
@IBAction func switchGroupByFeed(_ sender: Any) {
|
|
|
|
if groupByFeedSwitch.isOn {
|
|
|
|
AppDefaults.timelineGroupByFeed = true
|
|
|
|
} else {
|
|
|
|
AppDefaults.timelineGroupByFeed = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 00:19:22 +02:00
|
|
|
@IBAction func stepNumberOfTextLines(_ sender: UIStepper) {
|
|
|
|
let numberOfLines = Int(sender.value)
|
|
|
|
AppDefaults.timelineNumberOfLines = numberOfLines
|
|
|
|
updateNumberOfTextLinesLabel(value: numberOfLines)
|
|
|
|
}
|
|
|
|
|
2019-10-23 02:20:35 +02:00
|
|
|
// MARK: Notifications
|
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
@objc func contentSizeCategoryDidChange() {
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
|
|
|
|
2019-10-23 02:20:35 +02:00
|
|
|
@objc func accountsDidChange() {
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
|
|
|
|
2019-10-24 02:58:18 +02:00
|
|
|
@objc func displayNameDidChange() {
|
|
|
|
tableView.reloadData()
|
|
|
|
}
|
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: OPML Document Picker
|
|
|
|
|
|
|
|
extension SettingsViewController: UIDocumentPickerDelegate {
|
|
|
|
|
|
|
|
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
|
|
|
for url in urls {
|
2019-10-22 17:32:35 +02:00
|
|
|
opmlAccount?.importOPML(url) { result in}
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Private
|
|
|
|
|
|
|
|
private extension SettingsViewController {
|
|
|
|
|
2019-10-22 00:19:22 +02:00
|
|
|
func updateNumberOfTextLinesLabel(value: Int) {
|
|
|
|
let localizedText = NSLocalizedString("Number of Text Lines: %d", comment: "Number of Text Lines")
|
|
|
|
numberOfTextLinesLabel.text = NSString.localizedStringWithFormat(localizedText as NSString, value) as String
|
|
|
|
}
|
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
func addFeed() {
|
|
|
|
self.dismiss(animated: true)
|
|
|
|
|
|
|
|
let addNavViewController = UIStoryboard.add.instantiateInitialViewController() as! UINavigationController
|
|
|
|
let addViewController = addNavViewController.topViewController as! AddContainerViewController
|
|
|
|
addNavViewController.modalPresentationStyle = .formSheet
|
|
|
|
addNavViewController.preferredContentSize = AddContainerViewController.preferredContentSizeForFormSheetDisplay
|
2019-10-22 01:02:44 +02:00
|
|
|
addViewController.initialControllerType = .feed
|
2019-10-21 18:51:33 +02:00
|
|
|
addViewController.initialFeed = appNewsURLString
|
|
|
|
addViewController.initialFeedName = "NetNewsWire News"
|
|
|
|
|
|
|
|
presentingParentController?.present(addNavViewController, animated: true)
|
|
|
|
}
|
|
|
|
|
2019-10-22 17:32:35 +02:00
|
|
|
func importOPML(sourceView: UIView, sourceRect: CGRect) {
|
|
|
|
switch AccountManager.shared.activeAccounts.count {
|
|
|
|
case 0:
|
|
|
|
presentError(title: "Error", message: NSLocalizedString("You must have at least one active account.", comment: "Missing active account"))
|
|
|
|
case 1:
|
|
|
|
opmlAccount = AccountManager.shared.activeAccounts.first
|
|
|
|
importOPMLDocumentPicker()
|
|
|
|
default:
|
|
|
|
importOPMLAccountPicker(sourceView: sourceView, sourceRect: sourceRect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func importOPMLAccountPicker(sourceView: UIView, sourceRect: CGRect) {
|
|
|
|
let title = NSLocalizedString("Select an Import Account", comment: "Select an Import Account")
|
|
|
|
let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
|
2019-10-21 18:51:33 +02:00
|
|
|
|
2019-10-22 17:32:35 +02:00
|
|
|
if let popoverController = alert.popoverPresentationController {
|
|
|
|
popoverController.sourceView = view
|
|
|
|
popoverController.sourceRect = sourceRect
|
|
|
|
}
|
|
|
|
|
2019-10-23 00:18:37 +02:00
|
|
|
for account in AccountManager.shared.sortedActiveAccounts {
|
2019-10-22 17:32:35 +02:00
|
|
|
let action = UIAlertAction(title: account.nameForDisplay, style: .default) { [weak self] action in
|
|
|
|
self?.opmlAccount = account
|
|
|
|
self?.importOPMLDocumentPicker()
|
|
|
|
}
|
|
|
|
alert.addAction(action)
|
|
|
|
}
|
|
|
|
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
|
|
|
|
|
|
|
self.present(alert, animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func importOPMLDocumentPicker() {
|
2019-10-21 18:51:33 +02:00
|
|
|
let docPicker = UIDocumentPickerViewController(documentTypes: ["public.xml", "org.opml.opml"], in: .import)
|
|
|
|
docPicker.delegate = self
|
|
|
|
docPicker.modalPresentationStyle = .formSheet
|
|
|
|
self.present(docPicker, animated: true)
|
2019-10-22 17:32:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func exportOPML(sourceView: UIView, sourceRect: CGRect) {
|
|
|
|
if AccountManager.shared.accounts.count == 1 {
|
|
|
|
exportOPMLDocumentPicker()
|
|
|
|
} else {
|
|
|
|
exportOPMLAccountPicker(sourceView: sourceView, sourceRect: sourceRect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func exportOPMLAccountPicker(sourceView: UIView, sourceRect: CGRect) {
|
|
|
|
let title = NSLocalizedString("Select an Export Account", comment: "Select an Export Account")
|
|
|
|
let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
|
2019-10-21 18:51:33 +02:00
|
|
|
|
2019-10-22 17:32:35 +02:00
|
|
|
if let popoverController = alert.popoverPresentationController {
|
|
|
|
popoverController.sourceView = view
|
|
|
|
popoverController.sourceRect = sourceRect
|
|
|
|
}
|
|
|
|
|
2019-10-23 00:18:37 +02:00
|
|
|
for account in AccountManager.shared.sortedAccounts {
|
2019-10-22 17:32:35 +02:00
|
|
|
let action = UIAlertAction(title: account.nameForDisplay, style: .default) { [weak self] action in
|
|
|
|
self?.opmlAccount = account
|
|
|
|
self?.exportOPMLDocumentPicker()
|
|
|
|
}
|
|
|
|
alert.addAction(action)
|
|
|
|
}
|
|
|
|
|
|
|
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
|
|
alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
|
|
|
|
|
|
|
self.present(alert, animated: true)
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|
|
|
|
|
2019-10-22 17:32:35 +02:00
|
|
|
func exportOPMLDocumentPicker() {
|
|
|
|
guard let account = opmlAccount else { return }
|
2019-10-21 18:51:33 +02:00
|
|
|
|
2019-10-22 17:32:35 +02:00
|
|
|
let accountName = account.nameForDisplay.replacingOccurrences(of: " ", with: "").trimmingCharacters(in: .whitespaces)
|
|
|
|
let filename = "Subscriptions-\(accountName).opml"
|
2019-10-21 18:51:33 +02:00
|
|
|
let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent(filename)
|
2019-10-22 17:32:35 +02:00
|
|
|
let opmlString = OPMLExporter.OPMLString(with: account, title: filename)
|
2019-10-21 18:51:33 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-10-22 00:52:29 +02:00
|
|
|
func openURL(_ urlString: String) {
|
|
|
|
let vc = SFSafariViewController(url: URL(string: urlString)!)
|
|
|
|
vc.modalPresentationStyle = .pageSheet
|
|
|
|
present(vc, animated: true)
|
|
|
|
}
|
|
|
|
|
2019-10-21 18:51:33 +02:00
|
|
|
}
|