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
|
|
|
|
|
2019-09-07 23:43:44 +02:00
|
|
|
|
2019-06-11 23:59:16 +02:00
|
|
|
struct SettingsView : View {
|
2019-09-07 21:00:31 +02:00
|
|
|
|
|
|
|
@ObservedObject var viewModel: ViewModel
|
2019-09-07 23:43:44 +02:00
|
|
|
|
|
|
|
@Environment(\.viewController) private var viewController: UIViewController?
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-09-07 23:43:44 +02:00
|
|
|
@State private var isWebsitePresented: Bool = false
|
|
|
|
@State private var website: String? = nil
|
2019-09-07 22:30:54 +02:00
|
|
|
|
2019-09-07 23:43:44 +02:00
|
|
|
@State private var isOPMLImportPresented: Bool = false
|
|
|
|
@State private var isOPMLImportDocPickerPresented: Bool = false
|
|
|
|
@State private var isOPMLExportPresented: Bool = false
|
|
|
|
@State private var isOPMLExportDocPickerPresented: Bool = false
|
|
|
|
@State private var opmlAccount: Account? = nil
|
2019-06-16 01:19:20 +02:00
|
|
|
|
2019-06-11 23:59:16 +02:00
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
2019-06-18 23:54:51 +02:00
|
|
|
Form {
|
2019-06-11 23:59:16 +02:00
|
|
|
|
2019-09-07 21:00:31 +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)
|
|
|
|
}
|
|
|
|
}
|
2019-09-07 22:30:54 +02:00
|
|
|
|
|
|
|
VStack {
|
|
|
|
Button("Import Subscriptions...") {
|
|
|
|
self.isOPMLImportPresented = true
|
|
|
|
}
|
|
|
|
}.actionSheet(isPresented: $isOPMLImportPresented) {
|
|
|
|
createSubscriptionsImportAccounts
|
|
|
|
}.sheet(isPresented: $isOPMLImportDocPickerPresented) {
|
|
|
|
SettingsSubscriptionsImportDocumentPickerView(account: self.opmlAccount!)
|
|
|
|
}
|
|
|
|
|
|
|
|
VStack {
|
|
|
|
Button("Export Subscriptions...") {
|
|
|
|
self.isOPMLExportPresented = true
|
|
|
|
}
|
|
|
|
}.actionSheet(isPresented: $isOPMLExportPresented) {
|
|
|
|
createSubscriptionsExportAccounts
|
|
|
|
}.sheet(isPresented: $isOPMLExportDocPickerPresented) {
|
|
|
|
SettingsSubscriptionsExportDocumentPickerView(account: self.opmlAccount!)
|
|
|
|
}
|
2019-09-07 21:33:15 +02:00
|
|
|
}
|
|
|
|
.foregroundColor(.primary)
|
2019-06-16 01:19:20 +02:00
|
|
|
|
2019-06-19 00:38:20 +02:00
|
|
|
Section(header: Text("ABOUT"), footer: buildFooter) {
|
|
|
|
Text("About NetNewsWire")
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-09-07 21:10:20 +02:00
|
|
|
Button(action: {
|
|
|
|
self.isWebsitePresented.toggle()
|
|
|
|
self.website = "https://ranchero.com/netnewswire/"
|
|
|
|
}) {
|
2019-06-19 00:38:20 +02:00
|
|
|
Text("Website")
|
|
|
|
}
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-09-07 21:10:20 +02:00
|
|
|
Button(action: {
|
|
|
|
self.isWebsitePresented.toggle()
|
|
|
|
self.website = "https://github.com/brentsimmons/NetNewsWire"
|
|
|
|
}) {
|
|
|
|
Text("Github Repository")
|
2019-06-19 00:38:20 +02:00
|
|
|
}
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-09-07 21:10:20 +02:00
|
|
|
Button(action: {
|
|
|
|
self.isWebsitePresented.toggle()
|
|
|
|
self.website = "https://github.com/brentsimmons/NetNewsWire/issues"
|
|
|
|
}) {
|
|
|
|
Text("Bug Tracker")
|
2019-06-19 00:38:20 +02:00
|
|
|
}
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-09-07 21:10:20 +02:00
|
|
|
Button(action: {
|
|
|
|
self.isWebsitePresented.toggle()
|
|
|
|
self.website = "https://github.com/brentsimmons/NetNewsWire/tree/master/Technotes"
|
|
|
|
}) {
|
|
|
|
Text("Technotes")
|
2019-06-19 00:38:20 +02:00
|
|
|
}
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-09-07 21:10:20 +02:00
|
|
|
Button(action: {
|
|
|
|
self.isWebsitePresented.toggle()
|
|
|
|
self.website = "https://github.com/brentsimmons/NetNewsWire/blob/master/Technotes/HowToSupportNetNewsWire.markdown"
|
|
|
|
}) {
|
|
|
|
Text("How To Support NetNewsWire")
|
2019-06-19 00:38:20 +02:00
|
|
|
}
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-06-19 00:38:20 +02:00
|
|
|
Text("Add NetNewsWire News Feed")
|
2019-09-07 21:00:31 +02:00
|
|
|
|
2019-09-07 21:10:20 +02:00
|
|
|
}.sheet(isPresented: $isWebsitePresented) {
|
|
|
|
SafariView(url: URL(string: self.website!)!)
|
2019-09-07 21:00:31 +02:00
|
|
|
}
|
|
|
|
.foregroundColor(.primary)
|
2019-06-19 00:38:20 +02:00
|
|
|
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
.navigationBarTitle(Text("Settings"), displayMode: .inline)
|
2019-09-07 23:43:44 +02:00
|
|
|
.navigationBarItems(leading: Button(action: { self.viewController?.dismiss(animated: true) }) { Text("Done") } )
|
2019-06-11 23:59:16 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-13 21:30:56 +02:00
|
|
|
|
2019-09-07 22:30:54 +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.opmlAccount = account
|
|
|
|
self.isOPMLImportDocPickerPresented = true
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons.append(button)
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons.append(.cancel())
|
|
|
|
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.opmlAccount = account
|
|
|
|
self.isOPMLExportDocPickerPresented = true
|
|
|
|
}
|
|
|
|
buttons.append(button)
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons.append(.cancel())
|
|
|
|
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
|
|
|
|
2019-06-19 00:38: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
|
|
|
|
|
2019-09-07 21:00:31 +02:00
|
|
|
class ViewModel: ObservableObject {
|
2019-06-13 21:30:56 +02:00
|
|
|
|
2019-09-07 21:00:31 +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 {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 22:50:17 +02:00
|
|
|
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 {
|
2019-09-07 21:00:31 +02:00
|
|
|
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 {
|
2019-09-07 21:00:31 +02:00
|
|
|
objectWillChange.send()
|
2019-06-13 21:30:56 +02:00
|
|
|
AppDefaults.timelineNumberOfLines = newValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var refreshInterval: RefreshInterval {
|
|
|
|
get {
|
|
|
|
return AppDefaults.refreshInterval
|
|
|
|
}
|
|
|
|
set {
|
2019-09-07 21:00:31 +02:00
|
|
|
objectWillChange.send()
|
2019-06-13 21:30:56 +02:00
|
|
|
AppDefaults.refreshInterval = newValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func accountsDidChange(_ notification: Notification) {
|
2019-09-07 21:00:31 +02:00
|
|
|
objectWillChange.send()
|
2019-06-13 21:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc func displayNameDidChange(_ notification: Notification) {
|
2019-09-07 21:00:31 +02:00
|
|
|
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
|