// // SettingsView.swift // Multiplatform iOS // // Created by Stuart Breckenridge on 30/6/20. // Copyright © 2020 Ranchero Software. All rights reserved. // import SwiftUI import Account struct SettingsView: View { @Environment(\.presentationMode) var presentationMode @StateObject private var viewModel = SettingsModel() @StateObject private var feedsSettingsModel = FeedsSettingsModel() @StateObject private var settings = AppDefaults.shared var body: some View { NavigationView { List { systemSettings accounts importExport timeline articles appearance help } .listStyle(InsetGroupedListStyle()) .navigationBarTitle("Settings", displayMode: .inline) .navigationBarItems(leading: HStack { Button("Done") { presentationMode.wrappedValue.dismiss() } } ) } .fileImporter( isPresented: $feedsSettingsModel.isImporting, allowedContentTypes: feedsSettingsModel.importingContentTypes, allowsMultipleSelection: true, onCompletion: { result in if let urls = try? result.get() { feedsSettingsModel.processImportedFiles(urls) } } ) .fileMover(isPresented: $feedsSettingsModel.isExporting, file: feedsSettingsModel.generateExportURL()) { _ in } .sheet(isPresented: $viewModel.presentSheet, content: { SafariView(url: viewModel.selectedWebsite.url!) }) } var systemSettings: some View { Section(header: Text("Notifications, Badge, Data, & More"), content: { Button(action: { UIApplication.shared.open(URL(string: "\(UIApplication.openSettingsURLString)")!) }, label: { Text("Open System Settings").foregroundColor(.primary) }) }) } var accounts: some View { Section(header: Text("Accounts"), content: { ForEach(0.. 1 { NavigationLink("Import Subscriptions", destination: importOptions) } else { Button(action:{ if feedsSettingsModel.checkForActiveAccount() { feedsSettingsModel.importOPML(account: viewModel.activeAccounts.first) } }) { Text("Import Subscriptions") .foregroundColor(.primary) } } if viewModel.accounts.count > 1 { NavigationLink("Export Subscriptions", destination: exportOptions) } else { Button(action:{ feedsSettingsModel.exportOPML(account: viewModel.accounts.first) }) { Text("Export Subscriptions") .foregroundColor(.primary) } } Toggle("Confirm When Deleting", isOn: $settings.sidebarConfirmDelete) .toggleStyle(SwitchToggleStyle(tint: .accentColor)) }) .alert(isPresented: $feedsSettingsModel.showError) { Alert( title: Text(feedsSettingsModel.feedsSettingsError!.title ?? "Oops"), message: Text(feedsSettingsModel.feedsSettingsError!.localizedDescription), dismissButton: Alert.Button.cancel({ feedsSettingsModel.feedsSettingsError = FeedsSettingsError.none })) } } var importOptions: some View { List { Section(header: Text("Choose an account to receive the imported feeds and folders"), content: { ForEach(0.. String { let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "" let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "" return "NetNewsWire \(version) (Build \(build))" } } struct SettingsView_Previews: PreviewProvider { static var previews: some View { SettingsView() } }