Skip to content

Commit

Permalink
Convert Settings to use SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Jun 11, 2019
1 parent 3e0f70f commit 902304c
Show file tree
Hide file tree
Showing 21 changed files with 449 additions and 282 deletions.
254 changes: 42 additions & 212 deletions NetNewsWire.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Shared/Timer/RefreshInterval.swift
Expand Up @@ -8,7 +8,7 @@

import Foundation

enum RefreshInterval: Int {
enum RefreshInterval: Int, CaseIterable {
case manually = 1
case every10Minutes = 2
case every30Minutes = 3
Expand Down
10 changes: 3 additions & 7 deletions iOS/MasterFeed/MasterFeedViewController.swift
Expand Up @@ -11,6 +11,7 @@ import Account
import Articles
import RSCore
import RSTree
import SwiftUI

class MasterFeedViewController: ProgressTableViewController, UndoableCommandRunner {

Expand Down Expand Up @@ -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)

}

Expand Down
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
Expand Up @@ -10,6 +10,7 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
40 changes: 40 additions & 0 deletions iOS/Settings/SettingsAccountLabelView.swift
@@ -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
30 changes: 30 additions & 0 deletions iOS/Settings/SettingsAddAccountView.swift
@@ -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
55 changes: 55 additions & 0 deletions iOS/Settings/SettingsFeedbinAccountView.swift
@@ -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
54 changes: 54 additions & 0 deletions iOS/Settings/SettingsLocalAccountView.swift
@@ -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
94 changes: 94 additions & 0 deletions iOS/Settings/SettingsView.swift
@@ -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
68 changes: 68 additions & 0 deletions iOS/Settings/SettingsViewModel.swift
@@ -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.