diff --git a/Delta/Base.lproj/Settings.storyboard b/Delta/Base.lproj/Settings.storyboard index d6f92c9..9e77a32 100644 --- a/Delta/Base.lproj/Settings.storyboard +++ b/Delta/Base.lproj/Settings.storyboard @@ -20,7 +20,7 @@ - + @@ -349,7 +349,7 @@ - + @@ -359,7 +359,7 @@ - + @@ -375,11 +375,11 @@ - + - + @@ -398,11 +398,11 @@ - + - + @@ -451,7 +451,7 @@ - + @@ -461,7 +461,7 @@ - + @@ -478,11 +478,11 @@ - + - + @@ -498,7 +498,7 @@ - + @@ -508,7 +508,7 @@ - + @@ -521,7 +521,7 @@ - + @@ -531,7 +531,7 @@ - + @@ -544,7 +544,7 @@ - + @@ -554,7 +554,7 @@ - + @@ -567,11 +567,11 @@ - + - + @@ -928,13 +928,23 @@ - - - - - - + + + + + + + + + + + + + + + + diff --git a/Delta/Settings/Controller Skins/ControllerSkinsViewController.swift b/Delta/Settings/Controller Skins/ControllerSkinsViewController.swift index cc3619c..1b96e0f 100644 --- a/Delta/Settings/Controller Skins/ControllerSkinsViewController.swift +++ b/Delta/Settings/Controller Skins/ControllerSkinsViewController.swift @@ -38,6 +38,8 @@ class ControllerSkinsViewController: UITableViewController private let dataSource: RSTFetchedResultsTableViewPrefetchingDataSource + @IBOutlet private var importControllerSkinButton: UIBarButtonItem! + required init?(coder aDecoder: NSCoder) { self.dataSource = RSTFetchedResultsTableViewPrefetchingDataSource(fetchedResultsController: NSFetchedResultsController()) @@ -57,9 +59,11 @@ extension ControllerSkinsViewController self.tableView.dataSource = self.dataSource self.tableView.prefetchDataSource = self.dataSource + self.importControllerSkinButton.accessibilityLabel = NSLocalizedString("Import Controller Skin", comment: "") + if !self.isResetButtonVisible { - self.navigationItem.rightBarButtonItem = nil + self.navigationItem.rightBarButtonItems = [self.importControllerSkinButton] } } @@ -139,6 +143,13 @@ private extension ControllerSkinsViewController })) self.present(alertController, animated: true, completion: nil) } + + @IBAction private func importControllerSkin() + { + let importController = ImportController(documentTypes: ["com.rileytestut.delta.skin"]) + importController.delegate = self + self.present(importController, animated: true, completion: nil) + } } extension ControllerSkinsViewController @@ -196,3 +207,41 @@ extension ControllerSkinsViewController return height } } + +extension ControllerSkinsViewController: ImportControllerDelegate +{ + func importController(_ importController: ImportController, didImportItemsAt urls: Set, errors: [Error]) + { + for error in errors + { + print(error) + } + + if let error = errors.first + { + DispatchQueue.main.async { + self.transitionCoordinator?.animate(alongsideTransition: nil) { _ in + // Wait until ImportController is dismissed before presenting alert. + let alertController = UIAlertController(title: NSLocalizedString("Failed to Import Controller Skin", comment: ""), error: error) + self.present(alertController, animated: true, completion: nil) + } + } + + return + } + + let controllerSkinURLs = urls.filter { $0.pathExtension.lowercased() == "deltaskin" } + DatabaseManager.shared.importControllerSkins(at: Set(controllerSkinURLs)) { (controllerSkins, errors) in + if errors.count > 0 + { + let alertController = UIAlertController.alertController(for: .controllerSkins, with: errors) + self.present(alertController, animated: true, completion: nil) + } + + if controllerSkins.count > 0 + { + print("Imported Controller Skins:", controllerSkins.map { $0.name }) + } + } + } +}