From 4bd6b3ac964d3a651f9dc8049813312e8dd55691 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 4 Jul 2020 09:03:35 -0500 Subject: [PATCH] Refactor SettingsModel into its own swift file --- .../iOS/Settings/SettingsModel.swift | 49 +++++++++++++++++++ Multiplatform/iOS/Settings/SettingsView.swift | 43 +--------------- NetNewsWire.xcodeproj/project.pbxproj | 6 ++- 3 files changed, 55 insertions(+), 43 deletions(-) create mode 100644 Multiplatform/iOS/Settings/SettingsModel.swift diff --git a/Multiplatform/iOS/Settings/SettingsModel.swift b/Multiplatform/iOS/Settings/SettingsModel.swift new file mode 100644 index 000000000..ef37b7f16 --- /dev/null +++ b/Multiplatform/iOS/Settings/SettingsModel.swift @@ -0,0 +1,49 @@ +// +// SettingsModel.swift +// Multiplatform iOS +// +// Created by Maurice Parker on 7/4/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import Foundation + +class SettingsModel: ObservableObject { + + enum HelpSites { + case netNewsWireHelp, netNewsWire, supportNetNewsWire, github, bugTracker, technotes, netNewsWireSlack, none + + var url: URL? { + switch self { + case .netNewsWireHelp: + return URL(string: "https://ranchero.com/netnewswire/help/ios/5.0/en/")! + case .netNewsWire: + return URL(string: "https://ranchero.com/netnewswire/")! + case .supportNetNewsWire: + return URL(string: "https://github.com/brentsimmons/NetNewsWire/blob/master/Technotes/HowToSupportNetNewsWire.markdown")! + case .github: + return URL(string: "https://github.com/brentsimmons/NetNewsWire")! + case .bugTracker: + return URL(string: "https://github.com/brentsimmons/NetNewsWire/issues")! + case .technotes: + return URL(string: "https://github.com/brentsimmons/NetNewsWire/tree/master/Technotes")! + case .netNewsWireSlack: + return URL(string: "https://ranchero.com/netnewswire/slack")! + case .none: + return nil + } + } + } + + @Published var presentSheet: Bool = false + var selectedWebsite: HelpSites = .none { + didSet { + if selectedWebsite == .none { + presentSheet = false + } else { + presentSheet = true + } + } + } + +} diff --git a/Multiplatform/iOS/Settings/SettingsView.swift b/Multiplatform/iOS/Settings/SettingsView.swift index 95fbd6894..2862afa75 100644 --- a/Multiplatform/iOS/Settings/SettingsView.swift +++ b/Multiplatform/iOS/Settings/SettingsView.swift @@ -10,47 +10,6 @@ import SwiftUI import Account import UniformTypeIdentifiers - -class SettingsViewModel: ObservableObject { - - enum HelpSites { - case netNewsWireHelp, netNewsWire, supportNetNewsWire, github, bugTracker, technotes, netNewsWireSlack, none - - var url: URL? { - switch self { - case .netNewsWireHelp: - return URL(string: "https://ranchero.com/netnewswire/help/ios/5.0/en/")! - case .netNewsWire: - return URL(string: "https://ranchero.com/netnewswire/")! - case .supportNetNewsWire: - return URL(string: "https://github.com/brentsimmons/NetNewsWire/blob/master/Technotes/HowToSupportNetNewsWire.markdown")! - case .github: - return URL(string: "https://github.com/brentsimmons/NetNewsWire")! - case .bugTracker: - return URL(string: "https://github.com/brentsimmons/NetNewsWire/issues")! - case .technotes: - return URL(string: "https://github.com/brentsimmons/NetNewsWire/tree/master/Technotes")! - case .netNewsWireSlack: - return URL(string: "https://ranchero.com/netnewswire/slack")! - case .none: - return nil - } - } - } - - @Published var presentSheet: Bool = false - var selectedWebsite: HelpSites = .none { - didSet { - if selectedWebsite == .none { - presentSheet = false - } else { - presentSheet = true - } - } - } - -} - struct SettingsView: View { let sortedAccounts = AccountManager.shared.sortedAccounts @@ -58,7 +17,7 @@ struct SettingsView: View { @Environment(\.exportFiles) var exportAction @Environment(\.importFiles) var importAction - @StateObject private var viewModel = SettingsViewModel() + @StateObject private var viewModel = SettingsModel() @StateObject private var feedsSettingsModel = FeedsSettingsModel() @StateObject private var settings = AppDefaults.shared diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 1e7515704..f85dea27d 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -222,6 +222,7 @@ 517A757C24451C1500B553B9 /* OAuthSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 517A755324451BD500B553B9 /* OAuthSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 5181C5AD24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5181C5AC24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift */; }; 5181C5AE24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5181C5AC24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift */; }; + 5181C66224B0C326002E0F70 /* SettingsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5181C66124B0C326002E0F70 /* SettingsModel.swift */; }; 5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */; }; 5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */; }; 5183CCE5226F4DFA0010922C /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */; }; @@ -1850,6 +1851,7 @@ 517A745A2443665000B553B9 /* UIPageViewController-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIPageViewController-Extensions.swift"; sourceTree = ""; }; 517A754424451BD500B553B9 /* OAuthSwift.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OAuthSwift.xcodeproj; path = submodules/OAuthSwift/OAuthSwift.xcodeproj; sourceTree = ""; }; 5181C5AC24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferredColorSchemeModifier.swift; sourceTree = ""; }; + 5181C66124B0C326002E0F70 /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = ""; }; 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicLabel.swift; sourceTree = ""; }; 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicImageView.swift; sourceTree = ""; }; 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshInterval.swift; sourceTree = ""; }; @@ -2386,8 +2388,9 @@ 172199EB24AB228E00A31D04 /* Settings */ = { isa = PBXGroup; children = ( - 172199C824AB228900A31D04 /* SettingsView.swift */, 65C2E40024B05D8A000AFDF6 /* FeedsSettingsModel.swift */, + 5181C66124B0C326002E0F70 /* SettingsModel.swift */, + 172199C824AB228900A31D04 /* SettingsView.swift */, 17B223B924AC24A8001E4592 /* Submenus */, ); path = Settings; @@ -4849,6 +4852,7 @@ 51E4991D24A8092100B667CB /* NSAttributedString+NetNewsWire.swift in Sources */, 51E499FD24A9137600B667CB /* SidebarModel.swift in Sources */, 51A576BE24AE637400078888 /* ArticleView.swift in Sources */, + 5181C66224B0C326002E0F70 /* SettingsModel.swift in Sources */, 51E4995324A8734D00B667CB /* RedditFeedProvider-Extensions.swift in Sources */, 172199C924AB228900A31D04 /* SettingsView.swift in Sources */, 17D232A824AFF10A0005F075 /* AddWebFeedModel.swift in Sources */,