NetNewsWire/iOS/Settings/SettingsView.swift

160 lines
3.9 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 {
2019-06-13 21:30:56 +02:00
@ObjectBinding var viewModel: ViewModel
2019-06-11 23:59:16 +02:00
var body: some View {
NavigationView {
List {
Section(header: Text("ACCOUNTS")) {
ForEach(viewModel.accounts.identified(by: \.self)) { account in
2019-06-13 21:30:56 +02:00
NavigationButton(destination: SettingsDetailAccountView(viewModel: SettingsDetailAccountView.ViewModel(account)), isDetail: false) {
Text(verbatim: account.nameForDisplay)
}
2019-06-11 23:59:16 +02:00
}
NavigationButton(destination: SettingsAddAccountView(), isDetail: false) {
Text("Add Account")
}
}
Section(header: Text("ABOUT")) {
Text("About NetNewsWire")
Button(action: {
UIApplication.shared.open(URL(string: "https://ranchero.com/netnewswire/")!, options: [:])
}) {
Text("Website")
}
Button(action: {
UIApplication.shared.open(URL(string: "https://github.com/brentsimmons/NetNewsWire")!, options: [:])
}) {
Text("Github Repository")
}
Button(action: {
UIApplication.shared.open(URL(string: "https://github.com/brentsimmons/NetNewsWire/issues")!, options: [:])
}) {
Text("Bug Tracker")
}
Button(action: {
UIApplication.shared.open(URL(string: "https://github.com/brentsimmons/NetNewsWire/tree/master/Technotes")!, options: [:])
}) {
Text("Technotes")
}
Text("Add NetNewsWire News Feed")
}
.foregroundColor(.primary)
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)")
}
}
Section(header: Text("DATABASE")) {
Picker(selection: $viewModel.refreshInterval, label: Text("Refresh Interval")) {
ForEach(RefreshInterval.allCases.identified(by: \.self)) { interval in
Text(interval.description()).tag(interval)
}
}
Text("Import Subscriptions...")
Text("Export Subscriptions...")
}
}
.listStyle(.grouped)
.navigationBarTitle(Text("Settings"), displayMode: .inline)
}
}
2019-06-13 21:30:56 +02:00
class ViewModel: BindableObject {
let didChange = PassthroughSubject<ViewModel, Never>()
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 sortOldestToNewest: Bool {
get {
return AppDefaults.timelineSortDirection == .orderedDescending
}
set {
if newValue == true {
AppDefaults.timelineSortDirection = .orderedDescending
} else {
AppDefaults.timelineSortDirection = .orderedAscending
}
didChange.send(self)
}
}
var timelineNumberOfLines: Int {
get {
return AppDefaults.timelineNumberOfLines
}
set {
AppDefaults.timelineNumberOfLines = newValue
didChange.send(self)
}
}
var refreshInterval: RefreshInterval {
get {
return AppDefaults.refreshInterval
}
set {
AppDefaults.refreshInterval = newValue
didChange.send(self)
}
}
@objc func accountsDidChange(_ notification: Notification) {
didChange.send(self)
}
@objc func displayNameDidChange(_ notification: Notification) {
didChange.send(self)
}
}
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