Refactors GeneralPrefs Model

This commit is contained in:
Stuart Breckenridge 2020-07-15 10:54:18 +08:00
parent c630bf3b9f
commit d8c5d3719c
No known key found for this signature in database
GPG Key ID: 79BD673276AE83CE
6 changed files with 37 additions and 42 deletions

View File

@ -7,17 +7,33 @@
import SwiftUI
enum PreferencePane: Int, CaseIterable {
case general = 0
case accounts = 1
case advanced = 2
var description: String {
switch self {
case .general:
return "General"
case .accounts:
return "Accounts"
case .advanced:
return "Advanced"
}
}
}
struct MacPreferencesView: View {
@EnvironmentObject var defaults: AppDefaults
@StateObject private var viewModel = MacPreferencesModel()
@State private var preferencePane: PreferencePane = .general
var body: some View {
VStack {
switch viewModel.currentPreferencePane {
switch preferencePane {
case .general:
GeneralPreferencesView(preferences: viewModel)
GeneralPreferencesView()
.environmentObject(defaults)
case .accounts:
AccountsPreferencesView()
@ -31,36 +47,36 @@ struct MacPreferencesView: View {
ToolbarItem {
HStack {
Button(action: {
viewModel.currentPreferencePane = .general
preferencePane = .general
}, label: {
VStack {
Image(systemName: "gearshape")
.font(.title2)
Text("General")
}.foregroundColor(
viewModel.currentPreferencePane == .general ? Color("AccentColor") : Color.gray
preferencePane == .general ? Color("AccentColor") : Color.gray
)
}).frame(width: 70)
Button(action: {
viewModel.currentPreferencePane = .accounts
preferencePane = .accounts
}, label: {
VStack {
Image(systemName: "at")
.font(.title2)
Text("Accounts")
}.foregroundColor(
viewModel.currentPreferencePane == .accounts ? Color("AccentColor") : Color.gray
preferencePane == .accounts ? Color("AccentColor") : Color.gray
)
}).frame(width: 70)
Button(action: {
viewModel.currentPreferencePane = .advanced
preferencePane = .advanced
}, label: {
VStack {
Image(systemName: "scale.3d")
.font(.title2)
Text("Advanced")
}.foregroundColor(
viewModel.currentPreferencePane == .advanced ? Color("AccentColor") : Color.gray
preferencePane == .advanced ? Color("AccentColor") : Color.gray
)
}).frame(width: 70)
}

View File

@ -15,9 +15,9 @@ import RSCore
class AddAccountModel: ObservableObject {
#if DEBUG
var addableAccountTypes: [AccountType] = [.onMyMac, .feedbin, .feedly, .feedWrangler, .freshRSS, .cloudKit, .newsBlur]
let addableAccountTypes: [AccountType] = [.onMyMac, .feedbin, .feedly, .feedWrangler, .freshRSS, .cloudKit, .newsBlur]
#else
var addableAccountTypes: [AccountType] = [.onMyMac, .feedbin, .feedly]
let addableAccountTypes: [AccountType] = [.onMyMac, .feedbin, .feedly]
#endif
// Add Accounts

View File

@ -44,13 +44,8 @@ struct AddAccountView: View {
case .newsBlur:
userNameAndPasswordView
}
}
Spacer()
HStack {
if viewModel.accountIsAuthenticating {

View File

@ -1,5 +1,5 @@
//
// MacPreferencesModel.swift
// GeneralPreferencesModel.swift
// Multiplatform macOS
//
// Created by Stuart Breckenridge on 12/7/20.
@ -8,26 +8,10 @@
import Foundation
enum PreferencePane: Int, CaseIterable {
case general = 0
case accounts = 1
case advanced = 2
var description: String {
switch self {
case .general:
return "General"
case .accounts:
return "Accounts"
case .advanced:
return "Advanced"
}
}
}
class MacPreferencesModel: ObservableObject {
class GeneralPreferencesModel: ObservableObject {
@Published var currentPreferencePane: PreferencePane = PreferencePane.general
@Published var rssReaders = [RSSReader]()
@Published var readerSelection: Int = 0 {
willSet {
@ -47,7 +31,7 @@ class MacPreferencesModel: ObservableObject {
// MARK:- RSS Readers
private extension MacPreferencesModel {
private extension GeneralPreferencesModel {
func prepareRSSReaders() {

View File

@ -11,7 +11,7 @@ struct GeneralPreferencesView: View {
@EnvironmentObject private var defaults: AppDefaults
@Environment(\.colorScheme) private var colorScheme
@ObservedObject var preferences: MacPreferencesModel
@StateObject private var preferences = GeneralPreferencesModel()
private let colorPalettes = UserInterfaceColorPalette.allCases
var body: some View {

View File

@ -7,7 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1717535624BADF33004498C6 /* MacPreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1717535524BADF33004498C6 /* MacPreferencesModel.swift */; };
1717535624BADF33004498C6 /* GeneralPreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1717535524BADF33004498C6 /* GeneralPreferencesModel.swift */; };
172199C924AB228900A31D04 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199C824AB228900A31D04 /* SettingsView.swift */; };
172199ED24AB2E0100A31D04 /* SafariView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199EC24AB2E0100A31D04 /* SafariView.swift */; };
172199F124AB716900A31D04 /* SidebarToolbarModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199F024AB716900A31D04 /* SidebarToolbarModifier.swift */; };
@ -1788,7 +1788,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1717535524BADF33004498C6 /* MacPreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacPreferencesModel.swift; sourceTree = "<group>"; };
1717535524BADF33004498C6 /* GeneralPreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPreferencesModel.swift; sourceTree = "<group>"; };
172199C824AB228900A31D04 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
172199EC24AB2E0100A31D04 /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = "<group>"; };
172199F024AB716900A31D04 /* SidebarToolbarModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarToolbarModifier.swift; sourceTree = "<group>"; };
@ -2523,7 +2523,6 @@
1729528F24AA1A4F00D65E66 /* Preferences */ = {
isa = PBXGroup;
children = (
1717535524BADF33004498C6 /* MacPreferencesModel.swift */,
1729529624AA1CD000D65E66 /* MacPreferencesView.swift */,
1729529924AA1CE100D65E66 /* Preference Panes */,
);
@ -2543,6 +2542,7 @@
1769E2FD24BC589E000E1E8E /* General */ = {
isa = PBXGroup;
children = (
1717535524BADF33004498C6 /* GeneralPreferencesModel.swift */,
1729529224AA1CAA00D65E66 /* GeneralPreferencesView.swift */,
);
path = General;
@ -5216,7 +5216,7 @@
51E4996C24A8762D00B667CB /* ExtractedArticle.swift in Sources */,
51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */,
51919FF824AB8B7700541E64 /* TimelineView.swift in Sources */,
1717535624BADF33004498C6 /* MacPreferencesModel.swift in Sources */,
1717535624BADF33004498C6 /* GeneralPreferencesModel.swift in Sources */,
51E4992B24A8676300B667CB /* ArticleArray.swift in Sources */,
51B54AB324B5AC830014348B /* ArticleButtonState.swift in Sources */,
17D5F17224B0BC6700375168 /* SidebarToolbarModel.swift in Sources */,