// // ArticleThemeManagerView.swift // NetNewsWire-iOS // // Created by Stuart Breckenridge on 20/12/2022. // Copyright © 2022 Ranchero Software. All rights reserved. // import SwiftUI struct ArticleThemeManagerView: View { @StateObject private var themeManager = ArticleThemesManager.shared @State private var showDeleteConfirmation: (String, Bool) = ("", false) @State private var showImportThemeView: Bool = false @State private var showImportConfirmationAlert: (ArticleTheme?, Bool) = (nil, false) @State private var showImportErrorAlert: (Error?, Bool) = (nil, false) @State private var showImportSuccessAlert: Bool = false @State private var installedFirstPartyThemes: [ArticleTheme] = [] @State private var installedThirdPartyThemes: [ArticleTheme] = [] var body: some View { Form { Section(header: Text("Ranchero Software Themes", comment: "Section header for installed themes"), footer: Text("These themes cannot be deleted.", comment: "Section footer for installed themes.")) { articleThemeRow(try! themeManager.articleThemeWithThemeName("Default")) ForEach(0.. some View { Button { themeManager.currentThemeName = theme.name } label: { HStack { VStack(alignment: .leading) { Text(theme.name) .foregroundColor(.primary) Text("Created by \(theme.creatorName)", comment: "Article theme creator byline.") .font(.caption) .foregroundColor(.secondary) } Spacer() if themeManager.currentThemeName == theme.name { Image(systemName: "checkmark") .foregroundColor(Color(uiColor: AppAssets.primaryAccentColor)) } } } .swipeActions(edge: .trailing, allowsFullSwipe: false) { if theme.isAppTheme || theme.name == themeManager.currentThemeName { } else { Button { showDeleteConfirmation = (theme.name, true) } label: { Text("Delete", comment: "Button title") Image(systemName: "trash") } .tint(.red) } } } private func updateThemesArrays() { installedFirstPartyThemes = themeManager.themeNames.map({ try? themeManager.articleThemeWithThemeName($0) }).compactMap({ $0 }).filter({ $0.isAppTheme }).sorted(by: { $0.name < $1.name }) installedThirdPartyThemes = themeManager.themeNames.map({ try? themeManager.articleThemeWithThemeName($0) }).compactMap({ $0 }).filter({ !$0.isAppTheme }).sorted(by: { $0.name < $1.name }) } } struct ArticleThemeImporterView_Previews: PreviewProvider { static var previews: some View { ArticleThemeManagerView() } }