// // SettingsView.swift // NetNewsWire-iOS // // Created by Stuart Breckenridge on 12/11/2022. // Copyright © 2022 Ranchero Software. All rights reserved. // import SwiftUI import Account import UniformTypeIdentifiers import UserNotifications struct SettingsView: View { @Environment(\.dismiss) var dismiss @StateObject private var appDefaults = AppDefaults.shared @StateObject private var viewModel = SettingsViewModel() @Binding var isConfigureAppearanceShown: Bool var body: some View { NavigationView { List { // Device Permissions Section(header: Text("DEVICE_PERMISSIONS_HEADER", tableName: "Settings"), footer: Text("DEVICE_PERMISSIONS_FOOTER", tableName: "Settings")) { SettingsViewRows.openSystemSettings } // Account/Extensions/OPML Management Section(header: Text("ACCOUNTS_EXTENSIONS_HEADER", tableName: "Settings"), footer: Text("ACCOUNTS_EXTENSIONS_FOOTER", tableName: "Settings")) { SettingsViewRows.addAccount SettingsViewRows.manageExtensions SettingsViewRows.importOPML(showImportActionSheet: $viewModel.showImportActionSheet) .confirmationDialog(Text("IMPORT_OPML_CONFIRMATION", tableName: "Settings"), isPresented: $viewModel.showImportActionSheet, titleVisibility: .visible) { ForEach(AccountManager.shared.sortedActiveAccounts, id: \.self) { account in Button(account.nameForDisplay) { viewModel.importAccount = account viewModel.showImportView = true } } } SettingsViewRows.exportOPML(showExportActionSheet: $viewModel.showExportActionSheet) .confirmationDialog(Text("EXPORT_OPML_CONFIRMATION", tableName: "Settings"), isPresented: $viewModel.showExportActionSheet, titleVisibility: .visible) { ForEach(AccountManager.shared.sortedAccounts, id: \.self) { account in Button(account.nameForDisplay) { do { let document = try OPMLDocument(account) viewModel.exportDocument = document viewModel.showExportView = true } catch { viewModel.importExportError = error viewModel.showImportExportError = true } } } } } // Appearance Section(header: Text("APPEARANCE_HEADER", tableName: "Settings"), footer: Text("APPEARANCE_FOOTER", tableName: "Settings")) { SettingsViewRows.configureAppearance($isConfigureAppearanceShown) if viewModel.notificationPermissions == .authorized { SettingsViewRows.configureNewArticleNotifications } } // Help Section { ForEach(0..