From d8c5d3719c8584b9ff471681c134391dc2b101db Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Wed, 15 Jul 2020 10:54:18 +0800 Subject: [PATCH] Refactors GeneralPrefs Model --- .../Preferences/MacPreferencesView.swift | 34 ++++++++++++++----- .../Add Account/AddAccountModel.swift | 4 +-- .../Add Account/AddAccountView.swift | 7 +--- .../General/GeneralPreferencesModel.swift} | 24 +++---------- .../General/GeneralPreferencesView.swift | 2 +- NetNewsWire.xcodeproj/project.pbxproj | 8 ++--- 6 files changed, 37 insertions(+), 42 deletions(-) rename Multiplatform/macOS/Preferences/{MacPreferencesModel.swift => Preference Panes/General/GeneralPreferencesModel.swift} (86%) diff --git a/Multiplatform/macOS/Preferences/MacPreferencesView.swift b/Multiplatform/macOS/Preferences/MacPreferencesView.swift index e24f8d6e9..1bc3cabcb 100644 --- a/Multiplatform/macOS/Preferences/MacPreferencesView.swift +++ b/Multiplatform/macOS/Preferences/MacPreferencesView.swift @@ -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) } diff --git a/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountModel.swift b/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountModel.swift index 304fbb5f1..6354600ba 100644 --- a/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountModel.swift +++ b/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountModel.swift @@ -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 diff --git a/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountView.swift b/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountView.swift index 0d9320e4b..b9267b6d0 100644 --- a/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountView.swift +++ b/Multiplatform/macOS/Preferences/Preference Panes/Accounts/Account Preferences/Add Account/AddAccountView.swift @@ -44,13 +44,8 @@ struct AddAccountView: View { case .newsBlur: userNameAndPasswordView } - - } - - - - + Spacer() HStack { if viewModel.accountIsAuthenticating { diff --git a/Multiplatform/macOS/Preferences/MacPreferencesModel.swift b/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesModel.swift similarity index 86% rename from Multiplatform/macOS/Preferences/MacPreferencesModel.swift rename to Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesModel.swift index 765ceffaf..886d58169 100644 --- a/Multiplatform/macOS/Preferences/MacPreferencesModel.swift +++ b/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesModel.swift @@ -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() { diff --git a/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift b/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift index f0bb30ded..edd4a3995 100644 --- a/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift +++ b/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift @@ -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 { diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 923e1ee06..f67730a6f 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -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 = ""; }; + 1717535524BADF33004498C6 /* GeneralPreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPreferencesModel.swift; sourceTree = ""; }; 172199C824AB228900A31D04 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; 172199EC24AB2E0100A31D04 /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = ""; }; 172199F024AB716900A31D04 /* SidebarToolbarModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarToolbarModifier.swift; sourceTree = ""; }; @@ -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 */,