mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 12:06:58 +01:00
Extract Theme Import logic so that it can be reused
This commit is contained in:
parent
b43d8b6b28
commit
42bcaf7e55
@ -253,6 +253,7 @@
|
|||||||
5137C2E626F3F52D009EFEDB /* Sepia.nnwtheme in Resources */ = {isa = PBXBuildFile; fileRef = 5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */; };
|
5137C2E626F3F52D009EFEDB /* Sepia.nnwtheme in Resources */ = {isa = PBXBuildFile; fileRef = 5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */; };
|
||||||
5137C2E726F3F52D009EFEDB /* Sepia.nnwtheme in Resources */ = {isa = PBXBuildFile; fileRef = 5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */; };
|
5137C2E726F3F52D009EFEDB /* Sepia.nnwtheme in Resources */ = {isa = PBXBuildFile; fileRef = 5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */; };
|
||||||
5137C2E826F3F52D009EFEDB /* Sepia.nnwtheme in Resources */ = {isa = PBXBuildFile; fileRef = 5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */; };
|
5137C2E826F3F52D009EFEDB /* Sepia.nnwtheme in Resources */ = {isa = PBXBuildFile; fileRef = 5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */; };
|
||||||
|
5137C2EA26F63AE6009EFEDB /* ArticleThemeImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5137C2E926F63AE6009EFEDB /* ArticleThemeImporter.swift */; };
|
||||||
51386A8E25673277005F3762 /* AccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51386A8D25673276005F3762 /* AccountCell.swift */; };
|
51386A8E25673277005F3762 /* AccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51386A8D25673276005F3762 /* AccountCell.swift */; };
|
||||||
51386A8F25673277005F3762 /* AccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51386A8D25673276005F3762 /* AccountCell.swift */; };
|
51386A8F25673277005F3762 /* AccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51386A8D25673276005F3762 /* AccountCell.swift */; };
|
||||||
5138E93A24D33E5600AFF0FE /* RSTree in Frameworks */ = {isa = PBXBuildFile; productRef = 5138E93924D33E5600AFF0FE /* RSTree */; };
|
5138E93A24D33E5600AFF0FE /* RSTree in Frameworks */ = {isa = PBXBuildFile; productRef = 5138E93924D33E5600AFF0FE /* RSTree */; };
|
||||||
@ -1656,6 +1657,7 @@
|
|||||||
51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddRedditFeedWindowController.swift; sourceTree = "<group>"; };
|
51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddRedditFeedWindowController.swift; sourceTree = "<group>"; };
|
||||||
51333D3A2468615D00EB5C91 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Mac/Base.lproj/AddRedditFeedSheet.xib; sourceTree = SOURCE_ROOT; };
|
51333D3A2468615D00EB5C91 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Mac/Base.lproj/AddRedditFeedSheet.xib; sourceTree = SOURCE_ROOT; };
|
||||||
5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Sepia.nnwtheme; sourceTree = "<group>"; };
|
5137C2E326F3F52D009EFEDB /* Sepia.nnwtheme */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Sepia.nnwtheme; sourceTree = "<group>"; };
|
||||||
|
5137C2E926F63AE6009EFEDB /* ArticleThemeImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleThemeImporter.swift; sourceTree = "<group>"; };
|
||||||
51386A8D25673276005F3762 /* AccountCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCell.swift; sourceTree = "<group>"; };
|
51386A8D25673276005F3762 /* AccountCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCell.swift; sourceTree = "<group>"; };
|
||||||
51392D1A24AC19A000BE0D35 /* SidebarExpandedContainers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarExpandedContainers.swift; sourceTree = "<group>"; };
|
51392D1A24AC19A000BE0D35 /* SidebarExpandedContainers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarExpandedContainers.swift; sourceTree = "<group>"; };
|
||||||
513C5CE6232571C2003D4054 /* NetNewsWire iOS Share Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "NetNewsWire iOS Share Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
|
513C5CE6232571C2003D4054 /* NetNewsWire iOS Share Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "NetNewsWire iOS Share Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@ -2801,6 +2803,7 @@
|
|||||||
519ED47924482AEB007F8E94 /* EnableExtensionPointViewController.swift */,
|
519ED47924482AEB007F8E94 /* EnableExtensionPointViewController.swift */,
|
||||||
519ED455244828C3007F8E94 /* AddExtensionPointViewController.swift */,
|
519ED455244828C3007F8E94 /* AddExtensionPointViewController.swift */,
|
||||||
510FFAB226EEA22C00F32265 /* ArticleThemesTableViewController.swift */,
|
510FFAB226EEA22C00F32265 /* ArticleThemesTableViewController.swift */,
|
||||||
|
5137C2E926F63AE6009EFEDB /* ArticleThemeImporter.swift */,
|
||||||
516244E2241E19F000B61C47 /* ColorPaletteTableViewController.swift */,
|
516244E2241E19F000B61C47 /* ColorPaletteTableViewController.swift */,
|
||||||
516A09382360A2AE00EAE89B /* SettingsComboTableViewCell.swift */,
|
516A09382360A2AE00EAE89B /* SettingsComboTableViewCell.swift */,
|
||||||
516A091D23609A3600EAE89B /* SettingsComboTableViewCell.xib */,
|
516A091D23609A3600EAE89B /* SettingsComboTableViewCell.xib */,
|
||||||
@ -5615,6 +5618,7 @@
|
|||||||
51C45268226508F600C03939 /* MasterFeedUnreadCountView.swift in Sources */,
|
51C45268226508F600C03939 /* MasterFeedUnreadCountView.swift in Sources */,
|
||||||
D3A39865246505DF00F9A366 /* FindInArticleActivity.swift in Sources */,
|
D3A39865246505DF00F9A366 /* FindInArticleActivity.swift in Sources */,
|
||||||
5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */,
|
5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */,
|
||||||
|
5137C2EA26F63AE6009EFEDB /* ArticleThemeImporter.swift in Sources */,
|
||||||
51C4529F22650A1900C03939 /* AuthorAvatarDownloader.swift in Sources */,
|
51C4529F22650A1900C03939 /* AuthorAvatarDownloader.swift in Sources */,
|
||||||
5108F6D22375EED2001ABC45 /* TimelineCustomizerViewController.swift in Sources */,
|
5108F6D22375EED2001ABC45 /* TimelineCustomizerViewController.swift in Sources */,
|
||||||
519E743D22C663F900A78E47 /* SceneDelegate.swift in Sources */,
|
519E743D22C663F900A78E47 /* SceneDelegate.swift in Sources */,
|
||||||
|
@ -1295,68 +1295,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func importTheme(filename: String) {
|
func importTheme(filename: String) {
|
||||||
let theme = ArticleTheme(path: filename)
|
ArticleThemeImporter.importTheme(controller: rootSplitViewController, filename: filename);
|
||||||
|
|
||||||
let localizedTitleText = NSLocalizedString("Install theme “%@” by %@?", comment: "Theme message text")
|
|
||||||
let title = NSString.localizedStringWithFormat(localizedTitleText as NSString, theme.name, theme.creatorName) as String
|
|
||||||
|
|
||||||
let localizedMessageText = NSLocalizedString("Author's Website:\n%@", comment: "Authors website")
|
|
||||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.creatorHomePage) as String
|
|
||||||
|
|
||||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
||||||
|
|
||||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
||||||
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
|
||||||
|
|
||||||
if let url = URL(string: theme.creatorHomePage) {
|
|
||||||
let visitSiteTitle = NSLocalizedString("Show Website", comment: "Show Website")
|
|
||||||
let visitSiteAction = UIAlertAction(title: visitSiteTitle, style: .default) { [weak self] action in
|
|
||||||
UIApplication.shared.open(url)
|
|
||||||
self?.importTheme(filename: filename)
|
|
||||||
}
|
|
||||||
alertController.addAction(visitSiteAction)
|
|
||||||
}
|
|
||||||
|
|
||||||
func importTheme() {
|
|
||||||
do {
|
|
||||||
try ArticleThemesManager.shared.importTheme(filename: filename)
|
|
||||||
confirmImportSuccess(themeName: theme.name)
|
|
||||||
} catch {
|
|
||||||
rootSplitViewController.presentError(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let installThemeTitle = NSLocalizedString("Install Theme", comment: "Install Theme")
|
|
||||||
let installThemeAction = UIAlertAction(title: installThemeTitle, style: .default) { [weak self] action in
|
|
||||||
|
|
||||||
if ArticleThemesManager.shared.themeExists(filename: filename) {
|
|
||||||
let title = NSLocalizedString("Duplicate Theme", comment: "Duplicate Theme")
|
|
||||||
let localizedMessageText = NSLocalizedString("The theme “%@” already exists. Overwrite it?", comment: "Overwrite theme")
|
|
||||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.name) as String
|
|
||||||
|
|
||||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
||||||
|
|
||||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
|
||||||
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
|
||||||
|
|
||||||
let overwriteAction = UIAlertAction(title: NSLocalizedString("Overwrite", comment: "Overwrite"), style: .default) { action in
|
|
||||||
importTheme()
|
|
||||||
}
|
|
||||||
alertController.addAction(overwriteAction)
|
|
||||||
alertController.preferredAction = overwriteAction
|
|
||||||
|
|
||||||
self?.rootSplitViewController.present(alertController, animated: true)
|
|
||||||
} else {
|
|
||||||
importTheme()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
alertController.addAction(installThemeAction)
|
|
||||||
alertController.preferredAction = installThemeAction
|
|
||||||
|
|
||||||
rootSplitViewController.present(alertController, animated: true)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2363,18 +2302,4 @@ private extension SceneCoordinator {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirmImportSuccess(themeName: String) {
|
|
||||||
let title = NSLocalizedString("Theme installed", comment: "Theme installed")
|
|
||||||
|
|
||||||
let localizedMessageText = NSLocalizedString("The theme “%@” has been installed.", comment: "Theme installed")
|
|
||||||
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, themeName) as String
|
|
||||||
|
|
||||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
||||||
|
|
||||||
let doneTitle = NSLocalizedString("Done", comment: "Done")
|
|
||||||
alertController.addAction(UIAlertAction(title: doneTitle, style: .default))
|
|
||||||
|
|
||||||
rootSplitViewController.present(alertController, animated: true)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
96
iOS/Settings/ArticleThemeImporter.swift
Normal file
96
iOS/Settings/ArticleThemeImporter.swift
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
//
|
||||||
|
// ArticleThemeImporter.swift
|
||||||
|
// NetNewsWire
|
||||||
|
//
|
||||||
|
// Created by Maurice Parker on 9/18/21.
|
||||||
|
// Copyright © 2021 Ranchero Software. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct ArticleThemeImporter {
|
||||||
|
|
||||||
|
static func importTheme(controller: UIViewController, filename: String) {
|
||||||
|
let theme = ArticleTheme(path: filename)
|
||||||
|
|
||||||
|
let localizedTitleText = NSLocalizedString("Install theme “%@” by %@?", comment: "Theme message text")
|
||||||
|
let title = NSString.localizedStringWithFormat(localizedTitleText as NSString, theme.name, theme.creatorName) as String
|
||||||
|
|
||||||
|
let localizedMessageText = NSLocalizedString("Author's Website:\n%@", comment: "Authors website")
|
||||||
|
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.creatorHomePage) as String
|
||||||
|
|
||||||
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||||
|
|
||||||
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
||||||
|
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
||||||
|
|
||||||
|
if let url = URL(string: theme.creatorHomePage) {
|
||||||
|
let visitSiteTitle = NSLocalizedString("Show Website", comment: "Show Website")
|
||||||
|
let visitSiteAction = UIAlertAction(title: visitSiteTitle, style: .default) { action in
|
||||||
|
UIApplication.shared.open(url)
|
||||||
|
Self.importTheme(controller: controller, filename: filename)
|
||||||
|
}
|
||||||
|
alertController.addAction(visitSiteAction)
|
||||||
|
}
|
||||||
|
|
||||||
|
func importTheme() {
|
||||||
|
do {
|
||||||
|
try ArticleThemesManager.shared.importTheme(filename: filename)
|
||||||
|
confirmImportSuccess(controller: controller, themeName: theme.name)
|
||||||
|
} catch {
|
||||||
|
controller.presentError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let installThemeTitle = NSLocalizedString("Install Theme", comment: "Install Theme")
|
||||||
|
let installThemeAction = UIAlertAction(title: installThemeTitle, style: .default) { action in
|
||||||
|
|
||||||
|
if ArticleThemesManager.shared.themeExists(filename: filename) {
|
||||||
|
let title = NSLocalizedString("Duplicate Theme", comment: "Duplicate Theme")
|
||||||
|
let localizedMessageText = NSLocalizedString("The theme “%@” already exists. Overwrite it?", comment: "Overwrite theme")
|
||||||
|
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.name) as String
|
||||||
|
|
||||||
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||||
|
|
||||||
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
|
||||||
|
alertController.addAction(UIAlertAction(title: cancelTitle, style: .cancel))
|
||||||
|
|
||||||
|
let overwriteAction = UIAlertAction(title: NSLocalizedString("Overwrite", comment: "Overwrite"), style: .default) { action in
|
||||||
|
importTheme()
|
||||||
|
}
|
||||||
|
alertController.addAction(overwriteAction)
|
||||||
|
alertController.preferredAction = overwriteAction
|
||||||
|
|
||||||
|
controller.present(alertController, animated: true)
|
||||||
|
} else {
|
||||||
|
importTheme()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
alertController.addAction(installThemeAction)
|
||||||
|
alertController.preferredAction = installThemeAction
|
||||||
|
|
||||||
|
controller.present(alertController, animated: true)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension ArticleThemeImporter {
|
||||||
|
|
||||||
|
static func confirmImportSuccess(controller: UIViewController, themeName: String) {
|
||||||
|
let title = NSLocalizedString("Theme installed", comment: "Theme installed")
|
||||||
|
|
||||||
|
let localizedMessageText = NSLocalizedString("The theme “%@” has been installed.", comment: "Theme installed")
|
||||||
|
let message = NSString.localizedStringWithFormat(localizedMessageText as NSString, themeName) as String
|
||||||
|
|
||||||
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||||
|
|
||||||
|
let doneTitle = NSLocalizedString("Done", comment: "Done")
|
||||||
|
alertController.addAction(UIAlertAction(title: doneTitle, style: .default))
|
||||||
|
|
||||||
|
controller.present(alertController, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user