Skip to content
Permalink
Browse files

Convert Settings to use SwiftUI

  • Loading branch information...
vincode-io committed Jun 11, 2019
1 parent 3e0f70f commit 902304c723087925fece2d6019cb7552f9a4c12b

Large diffs are not rendered by default.

@@ -8,7 +8,7 @@
import Foundation

enum RefreshInterval: Int {
enum RefreshInterval: Int, CaseIterable {
case manually = 1
case every10Minutes = 2
case every30Minutes = 3
@@ -11,6 +11,7 @@ import Account
import Articles
import RSCore
import RSTree
import SwiftUI

class MasterFeedViewController: ProgressTableViewController, UndoableCommandRunner {

@@ -393,13 +394,8 @@ class MasterFeedViewController: ProgressTableViewController, UndoableCommandRunn
@IBAction func settings(_ sender: UIBarButtonItem) {

let settingsNavViewController = UIStoryboard.settings.instantiateInitialViewController() as! UINavigationController
settingsNavViewController.modalPresentationStyle = .formSheet

let settingsViewController = settingsNavViewController.topViewController as! SettingsViewController
settingsViewController.presentingParentController = self

self.present(settingsNavViewController, animated: true)
let settings = UIHostingController(rootView: SettingsView(viewModel: SettingsViewModel()))
self.present(settings, animated: true)

}

@@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
@@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
@@ -0,0 +1,40 @@
//
// SettingsAccountLabelView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI

struct SettingsAccountLabelView : View {
let accountImage: String
let accountLabel: String

var body: some View {
HStack {
Spacer()
HStack {
Image(accountImage)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(height: 32)
Text(verbatim: accountLabel).font(.title)

}
.layoutPriority(1)
Spacer()
}
.foregroundColor(.primary)
}
}

#if DEBUG
struct SettingsAccountLabelView_Previews : PreviewProvider {
static var previews: some View {
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: "On My Device")
.previewLayout(.fixed(width: 300, height: 44))
}
}
#endif
@@ -0,0 +1,30 @@
//
// SettingsAddAccountView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI

struct SettingsAddAccountView : View {
var body: some View {
List {
PresentationButton(SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: "On My Device"),
destination: SettingsLocalAccountView(name: ""))
PresentationButton(SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin"),
destination: SettingsFeedbinAccountView(email: "", password: ""))
}
.listStyle(.grouped)
.navigationBarTitle(Text("Add Account"), displayMode: .inline)
}
}

#if DEBUG
struct AddAccountView_Previews : PreviewProvider {
static var previews: some View {
SettingsAddAccountView()
}
}
#endif
@@ -0,0 +1,55 @@
//
// SettingsFeedbinAccountView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI

struct SettingsFeedbinAccountView : View {
@State var email: String
@State var password: String

var body: some View {
NavigationView {
List {
Section(header:
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin").padding()
) {
HStack {
Spacer()
TextField($email, placeholder: Text("Email"))
Spacer()
}
HStack {
Spacer()
SecureField($password, placeholder: Text("Password"))
Spacer()
}
}
Section {
HStack {
Spacer()
Button(action: {}) {
Text("Add Account")
}
Spacer()
}
}
}
.listStyle(.grouped)
.navigationBarTitle(Text(""), displayMode: .inline)
}
}

}

#if DEBUG
struct SettingsFeedbinAccountView_Previews : PreviewProvider {
static var previews: some View {
SettingsFeedbinAccountView(email: "", password: "")
}
}
#endif
@@ -0,0 +1,54 @@
//
// SettingsLocalAccountView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account

struct SettingsLocalAccountView : View {
@State var name: String

var body: some View {
NavigationView {
List {
Section(header:
SettingsAccountLabelView(accountImage: "accountLocal", accountLabel: "On My Device").padding()
) {
HStack {
Spacer()
TextField($name, placeholder: Text("Name (Optional)"))
Spacer()
}
}
Section {
HStack {
Spacer()
Button(action: { self.addAccount() }) {
Text("Add Account")
}
Spacer()
}
}
}
.listStyle(.grouped)
.navigationBarTitle(Text(""), displayMode: .inline)
}
}

func addAccount() {
let account = AccountManager.shared.createAccount(type: .onMyMac)
account.name = name
}
}

#if DEBUG
struct SettingsLocalAccountView_Previews : PreviewProvider {
static var previews: some View {
SettingsLocalAccountView(name: "")
}
}
#endif
@@ -0,0 +1,94 @@
//
// SettingsView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account

struct SettingsView : View {
@ObjectBinding var viewModel: SettingsViewModel

var body: some View {
NavigationView {
List {

Section(header: Text("ACCOUNTS")) {
ForEach(viewModel.accounts.identified(by: \.self)) { account in
Text(verbatim: account.nameForDisplay)
}
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)

}
}
}

#if DEBUG
struct SettingsView_Previews : PreviewProvider {
static var previews: some View {
SettingsView(viewModel: SettingsViewModel())
}
}
#endif
@@ -0,0 +1,68 @@
//
// SettingsViewModel.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 6/11/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Foundation
import SwiftUI
import Combine
import Account

class SettingsViewModel: BindableObject {

let didChange = PassthroughSubject<SettingsViewModel, Never>()

init() {
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .AccountsDidChange, object: nil)
}

var accounts: [Account] {
get {
return AccountManager.shared.accounts
}
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)
}

}
File renamed without changes.
File renamed without changes.

0 comments on commit 902304c

Please sign in to comment.
You can’t perform that action at this time.