Established settings menu with built in OPML Import/Export.

This commit is contained in:
Maurice Parker 2019-04-17 07:00:32 -05:00
parent 8c4a2dca0b
commit ce0e548e79
5 changed files with 74 additions and 67 deletions

View File

@ -205,14 +205,11 @@
</barButtonItem> </barButtonItem>
</toolbarItems> </toolbarItems>
<navigationItem key="navigationItem" title="Feeds" id="Zdf-7t-Un8"> <navigationItem key="navigationItem" title="Feeds" id="Zdf-7t-Un8">
<leftBarButtonItems> <barButtonItem key="leftBarButtonItem" image="settingsImage" id="2lM-3y-hKs">
<barButtonItem image="settingsImage" id="7xz-3z-0PJ"/>
<barButtonItem title="Tools" image="toolsImage" id="2lM-3y-hKs">
<connections> <connections>
<action selector="showOPMLImportExport:" destination="7bK-jq-Zjz" id="qIa-yP-E6a"/> <action selector="showTools:" destination="7bK-jq-Zjz" id="3el-OE-Sfi"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
</leftBarButtonItems>
</navigationItem> </navigationItem>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/> <simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
</tableViewController> </tableViewController>
@ -287,7 +284,6 @@
<image name="circleOpenImage" width="22" height="22"/> <image name="circleOpenImage" width="22" height="22"/>
<image name="settingsImage" width="24" height="24"/> <image name="settingsImage" width="24" height="24"/>
<image name="starOpenImage" width="24" height="24"/> <image name="starOpenImage" width="24" height="24"/>
<image name="toolsImage" width="24" height="22"/>
</resources> </resources>
<inferredMetricsTieBreakers> <inferredMetricsTieBreakers>
<segue reference="RT3-gH-cyN"/> <segue reference="RT3-gH-cyN"/>

View File

@ -13,47 +13,6 @@ import RSTree
class MasterPrimaryViewController: MasterViewController { class MasterPrimaryViewController: MasterViewController {
// MARK: Actions
@IBAction func showOPMLImportExport(_ sender: UIBarButtonItem) {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let importOPML = UIAlertAction(title: "Import OPML", style: .default) { [unowned self] alertAction in
let docPicker = UIDocumentPickerViewController(documentTypes: ["public.xml", "org.opml.opml"], in: .import)
docPicker.delegate = self
docPicker.modalPresentationStyle = .formSheet
self.present(docPicker, animated: true)
}
optionMenu.addAction(importOPML)
let exportOPML = UIAlertAction(title: "Export OPML", style: .default) { [unowned self] alertAction in
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)
}
optionMenu.addAction(exportOPML)
optionMenu.addAction(UIAlertAction(title: "Cancel", style: .cancel))
if let popoverController = optionMenu.popoverPresentationController {
popoverController.barButtonItem = sender
}
self.present(optionMenu, animated: true)
}
// MARK: - Table View // MARK: - Table View
override func numberOfSections(in tableView: UITableView) -> Int { override func numberOfSections(in tableView: UITableView) -> Int {
@ -103,19 +62,3 @@ class MasterPrimaryViewController: MasterViewController {
} }
} }
extension MasterPrimaryViewController: 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)
}
}
}
}

View File

@ -193,6 +193,56 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
// MARK: Actions // MARK: Actions
@IBAction func showTools(_ sender: UIBarButtonItem) {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
// Settings Button
let settingsTitle = NSLocalizedString("Settings", comment: "Settings")
let setting = UIAlertAction(title: settingsTitle, style: .default) { alertAction in
}
optionMenu.addAction(setting)
// Import Button
let importOPMLTitle = NSLocalizedString("Import OPML", comment: "Import OPML")
let importOPML = UIAlertAction(title: importOPMLTitle, style: .default) { [unowned self] alertAction in
let docPicker = UIDocumentPickerViewController(documentTypes: ["public.xml", "org.opml.opml"], in: .import)
docPicker.delegate = self
docPicker.modalPresentationStyle = .formSheet
self.present(docPicker, animated: true)
}
optionMenu.addAction(importOPML)
// Export Button
let exportOPMLTitle = NSLocalizedString("Export OPML", comment: "Export OPML")
let exportOPML = UIAlertAction(title: exportOPMLTitle, style: .default) { [unowned self] alertAction in
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)
}
optionMenu.addAction(exportOPML)
optionMenu.addAction(UIAlertAction(title: "Cancel", style: .cancel))
if let popoverController = optionMenu.popoverPresentationController {
popoverController.barButtonItem = sender
}
self.present(optionMenu, animated: true)
}
@IBAction func markAllAsRead(_ sender: Any) { @IBAction func markAllAsRead(_ sender: Any) {
let title = NSLocalizedString("Mark All Read", comment: "Mark All Read") let title = NSLocalizedString("Mark All Read", comment: "Mark All Read")
@ -323,6 +373,24 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
} }
// MARK: OPML Document Picker
extension MasterViewController: 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 // MARK: Private
private extension MasterViewController { private extension MasterViewController {

View File

@ -2,7 +2,7 @@
"images" : [ "images" : [
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "settings.pdf" "filename" : "settings3.pdf"
} }
], ],
"info" : { "info" : {