NetNewsWire/iOS/Settings/SettingsView.swift

238 lines
6.5 KiB
Swift
Raw Normal View History

2019-06-11 23:59:16 +02:00
//
// SettingsView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
2019-06-13 21:30:56 +02:00
import Combine
2019-06-11 23:59:16 +02:00
import Account
struct SettingsView : View {
@ObservedObject var viewModel: ViewModel
@State var isWebsitePresented: Bool = false
@State var website: String? = nil
2019-06-16 01:19:20 +02:00
2019-06-11 23:59:16 +02:00
var body: some View {
NavigationView {
Form {
2019-06-11 23:59:16 +02:00
// Section(header: Text("ACCOUNTS")) {
// ForEach(viewModel.accounts.identified(by: \.self)) { account in
// NavigationLink(destination: SettingsDetailAccountView(viewModel: SettingsDetailAccountView.ViewModel(account)), isDetail: false) {
// Text(verbatim: account.nameForDisplay)
// }
// }
// NavigationLink(destination: SettingsAddAccountView(), isDetail: false) {
// Text("Add Account")
// }
// }
2019-06-11 23:59:16 +02:00
Section(header: Text("TIMELINE")) {
Toggle(isOn: $viewModel.sortOldestToNewest) {
Text("Sort Oldest to Newest")
}
Stepper(value: $viewModel.timelineNumberOfLines, in: 2...6) {
Text("Number of Text Lines: \(viewModel.timelineNumberOfLines)")
}
}
2019-09-07 21:33:15 +02:00
Section(header: Text("DATABASE")) {
Picker(selection: $viewModel.refreshInterval, label: Text("Refresh Interval")) {
ForEach(RefreshInterval.allCases) { interval in
Text(interval.description()).tag(interval)
}
}
// Button(action: {
// self.subscriptionsImportAccounts = self.createSubscriptionsImportAccounts
// }) {
// Text("Import Subscriptions...")
// }
// .presentation(subscriptionsImportAccounts)
// .presentation(subscriptionsImportDocumentPicker)
// Button(action: {
// self.subscriptionsExportAccounts = self.createSubscriptionsExportAccounts
// }) {
// Text("Export Subscriptions...")
// }
// .presentation(subscriptionsExportAccounts)
// .presentation(subscriptionsExportDocumentPicker)
2019-09-07 21:33:15 +02:00
}
.foregroundColor(.primary)
2019-06-16 01:19:20 +02:00
Section(header: Text("ABOUT"), footer: buildFooter) {
Text("About NetNewsWire")
Button(action: {
self.isWebsitePresented.toggle()
self.website = "https://ranchero.com/netnewswire/"
}) {
Text("Website")
}
Button(action: {
self.isWebsitePresented.toggle()
self.website = "https://github.com/brentsimmons/NetNewsWire"
}) {
Text("Github Repository")
}
Button(action: {
self.isWebsitePresented.toggle()
self.website = "https://github.com/brentsimmons/NetNewsWire/issues"
}) {
Text("Bug Tracker")
}
Button(action: {
self.isWebsitePresented.toggle()
self.website = "https://github.com/brentsimmons/NetNewsWire/tree/master/Technotes"
}) {
Text("Technotes")
}
Button(action: {
self.isWebsitePresented.toggle()
self.website = "https://github.com/brentsimmons/NetNewsWire/blob/master/Technotes/HowToSupportNetNewsWire.markdown"
}) {
Text("How To Support NetNewsWire")
}
Text("Add NetNewsWire News Feed")
}.sheet(isPresented: $isWebsitePresented) {
SafariView(url: URL(string: self.website!)!)
}
.foregroundColor(.primary)
2019-06-11 23:59:16 +02:00
}
.navigationBarTitle(Text("Settings"), displayMode: .inline)
}
}
2019-06-13 21:30:56 +02:00
// var createSubscriptionsImportAccounts: ActionSheet {
// var buttons = [ActionSheet.Button]()
//
// for account in viewModel.activeAccounts {
// if !account.isOPMLImportSupported {
// continue
// }
//
// let button = ActionSheet.Button.default(Text(verbatim: account.nameForDisplay)) {
// self.subscriptionsImportAccounts = nil
// self.subscriptionsImportDocumentPicker = Modal(SettingsSubscriptionsImportDocumentPickerView(account: account))
// }
//
// buttons.append(button)
// }
//
// buttons.append(.cancel { self.subscriptionsImportAccounts = nil })
// return ActionSheet(title: Text("Import Subscriptions..."), message: Text("Select the account to import your OPML file into."), buttons: buttons)
// }
//
// var createSubscriptionsExportAccounts: ActionSheet {
// var buttons = [ActionSheet.Button]()
//
// for account in viewModel.accounts {
// let button = ActionSheet.Button.default(Text(verbatim: account.nameForDisplay)) {
// self.subscriptionsExportAccounts = nil
// self.subscriptionsExportDocumentPicker = Modal(SettingsSubscriptionsExportDocumentPickerView(account: account))
// }
// buttons.append(button)
// }
//
// buttons.append(.cancel { self.subscriptionsExportAccounts = nil })
// return ActionSheet(title: Text("Export Subscriptions..."), message: Text("Select the account to export out of."), buttons: buttons)
// }
2019-06-16 01:19:20 +02:00
var buildFooter: some View {
return Text(verbatim: "\(Bundle.main.appName) v \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))")
.font(.footnote)
.foregroundColor(.secondary)
}
2019-06-17 14:20:39 +02:00
// MARK: ViewModel
class ViewModel: ObservableObject {
2019-06-13 21:30:56 +02:00
let objectWillChange = ObservableObjectPublisher()
2019-06-13 21:30:56 +02:00
init() {
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .AccountsDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
}
var accounts: [Account] {
get {
return AccountManager.shared.sortedAccounts
}
set {
}
}
var activeAccounts: [Account] {
get {
return AccountManager.shared.sortedActiveAccounts
}
set {
}
}
2019-06-13 21:30:56 +02:00
var sortOldestToNewest: Bool {
get {
return AppDefaults.timelineSortDirection == .orderedDescending
}
set {
objectWillChange.send()
2019-06-13 21:30:56 +02:00
if newValue == true {
AppDefaults.timelineSortDirection = .orderedDescending
} else {
AppDefaults.timelineSortDirection = .orderedAscending
}
}
}
var timelineNumberOfLines: Int {
get {
return AppDefaults.timelineNumberOfLines
}
set {
objectWillChange.send()
2019-06-13 21:30:56 +02:00
AppDefaults.timelineNumberOfLines = newValue
}
}
var refreshInterval: RefreshInterval {
get {
return AppDefaults.refreshInterval
}
set {
objectWillChange.send()
2019-06-13 21:30:56 +02:00
AppDefaults.refreshInterval = newValue
}
}
@objc func accountsDidChange(_ notification: Notification) {
objectWillChange.send()
2019-06-13 21:30:56 +02:00
}
@objc func displayNameDidChange(_ notification: Notification) {
objectWillChange.send()
2019-06-13 21:30:56 +02:00
}
}
2019-06-11 23:59:16 +02:00
}
#if DEBUG
struct SettingsView_Previews : PreviewProvider {
static var previews: some View {
2019-06-13 21:30:56 +02:00
SettingsView(viewModel: SettingsView.ViewModel())
2019-06-11 23:59:16 +02:00
}
}
#endif