diff --git a/Shared/ArticleStyles/ArticleThemesManager.swift b/Shared/ArticleStyles/ArticleThemesManager.swift index a8c7fe372..ff0365e9f 100644 --- a/Shared/ArticleStyles/ArticleThemesManager.swift +++ b/Shared/ArticleStyles/ArticleThemesManager.swift @@ -49,10 +49,6 @@ final class ArticleThemesManager: NSObject, NSFilePresenter { } } - var themes: [ArticleTheme] { - return themeNames.compactMap { articleThemeWithThemeName($0) } - } - init(folderPath: String) { self.folderPath = folderPath self.currentTheme = ArticleTheme.defaultTheme @@ -96,32 +92,6 @@ final class ArticleThemesManager: NSObject, NSFilePresenter { try FileManager.default.copyItem(atPath: filename, toPath: toFilename) } - func deleteTheme(themeName: String) { - if let filename = pathForThemeName(themeName, folder: folderPath) { - try? FileManager.default.removeItem(atPath: filename) - } - } - -} - -// MARK : Private - -private extension ArticleThemesManager { - - func updateThemeNames() { - let appThemeFilenames = Bundle.main.paths(forResourcesOfType: ArticleTheme.nnwThemeSuffix, inDirectory: nil) - let appThemeNames = Set(appThemeFilenames.map { ArticleTheme.themeNameForPath($0) }) - - let installedThemeNames = Set(allThemePaths(folderPath).map { ArticleTheme.themeNameForPath($0) }) - - let allThemeNames = appThemeNames.union(installedThemeNames) - - let sortedThemeNames = allThemeNames.sorted(by: { $0.compare($1, options: .caseInsensitive) == .orderedAscending }) - if sortedThemeNames != themeNames { - themeNames = sortedThemeNames - } - } - func articleThemeWithThemeName(_ themeName: String) -> ArticleTheme? { if themeName == AppDefaults.defaultThemeName { return ArticleTheme.defaultTheme @@ -148,6 +118,32 @@ private extension ArticleThemesManager { } + func deleteTheme(themeName: String) { + if let filename = pathForThemeName(themeName, folder: folderPath) { + try? FileManager.default.removeItem(atPath: filename) + } + } + +} + +// MARK : Private + +private extension ArticleThemesManager { + + func updateThemeNames() { + let appThemeFilenames = Bundle.main.paths(forResourcesOfType: ArticleTheme.nnwThemeSuffix, inDirectory: nil) + let appThemeNames = Set(appThemeFilenames.map { ArticleTheme.themeNameForPath($0) }) + + let installedThemeNames = Set(allThemePaths(folderPath).map { ArticleTheme.themeNameForPath($0) }) + + let allThemeNames = appThemeNames.union(installedThemeNames) + + let sortedThemeNames = allThemeNames.sorted(by: { $0.compare($1, options: .caseInsensitive) == .orderedAscending }) + if sortedThemeNames != themeNames { + themeNames = sortedThemeNames + } + } + func defaultArticleTheme() -> ArticleTheme { return articleThemeWithThemeName(AppDefaults.defaultThemeName)! } diff --git a/iOS/Settings/ArticleThemesTableViewController.swift b/iOS/Settings/ArticleThemesTableViewController.swift index 26e28944f..b7793d5c4 100644 --- a/iOS/Settings/ArticleThemesTableViewController.swift +++ b/iOS/Settings/ArticleThemesTableViewController.swift @@ -70,9 +70,10 @@ class ArticleThemesTableViewController: UITableViewController { } override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - guard indexPath.row != 0, - let cell = tableView.cellForRow(at: indexPath), - let themeName = cell.textLabel?.text else { return nil } + guard let cell = tableView.cellForRow(at: indexPath), + let themeName = cell.textLabel?.text, + let theme = ArticleThemesManager.shared.articleThemeWithThemeName(themeName), + !theme.isAppTheme else { return nil } let deleteTitle = NSLocalizedString("Delete", comment: "Delete") let deleteAction = UIContextualAction(style: .normal, title: deleteTitle) { [weak self] (action, view, completion) in