Refactor SettingsModel into its own swift file

This commit is contained in:
Maurice Parker 2020-07-04 09:03:35 -05:00
parent c7e5296ab1
commit 4bd6b3ac96
3 changed files with 55 additions and 43 deletions

View File

@ -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
}
}
}
}

View File

@ -10,47 +10,6 @@ import SwiftUI
import Account import Account
import UniformTypeIdentifiers 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 { struct SettingsView: View {
let sortedAccounts = AccountManager.shared.sortedAccounts let sortedAccounts = AccountManager.shared.sortedAccounts
@ -58,7 +17,7 @@ struct SettingsView: View {
@Environment(\.exportFiles) var exportAction @Environment(\.exportFiles) var exportAction
@Environment(\.importFiles) var importAction @Environment(\.importFiles) var importAction
@StateObject private var viewModel = SettingsViewModel() @StateObject private var viewModel = SettingsModel()
@StateObject private var feedsSettingsModel = FeedsSettingsModel() @StateObject private var feedsSettingsModel = FeedsSettingsModel()
@StateObject private var settings = AppDefaults.shared @StateObject private var settings = AppDefaults.shared

View File

@ -222,6 +222,7 @@
517A757C24451C1500B553B9 /* OAuthSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 517A755324451BD500B553B9 /* OAuthSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 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 */; }; 5181C5AD24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5181C5AC24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift */; };
5181C5AE24AF89B1002E0F70 /* 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 */; }; 5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */; };
5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */; }; 5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */; };
5183CCE5226F4DFA0010922C /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.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 = "<group>"; }; 517A745A2443665000B553B9 /* UIPageViewController-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIPageViewController-Extensions.swift"; sourceTree = "<group>"; };
517A754424451BD500B553B9 /* OAuthSwift.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OAuthSwift.xcodeproj; path = submodules/OAuthSwift/OAuthSwift.xcodeproj; sourceTree = "<group>"; }; 517A754424451BD500B553B9 /* OAuthSwift.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OAuthSwift.xcodeproj; path = submodules/OAuthSwift/OAuthSwift.xcodeproj; sourceTree = "<group>"; };
5181C5AC24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferredColorSchemeModifier.swift; sourceTree = "<group>"; }; 5181C5AC24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferredColorSchemeModifier.swift; sourceTree = "<group>"; };
5181C66124B0C326002E0F70 /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = "<group>"; };
5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicLabel.swift; sourceTree = "<group>"; }; 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicLabel.swift; sourceTree = "<group>"; };
5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicImageView.swift; sourceTree = "<group>"; }; 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicImageView.swift; sourceTree = "<group>"; };
5183CCE4226F4DFA0010922C /* RefreshInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshInterval.swift; sourceTree = "<group>"; }; 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshInterval.swift; sourceTree = "<group>"; };
@ -2386,8 +2388,9 @@
172199EB24AB228E00A31D04 /* Settings */ = { 172199EB24AB228E00A31D04 /* Settings */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
172199C824AB228900A31D04 /* SettingsView.swift */,
65C2E40024B05D8A000AFDF6 /* FeedsSettingsModel.swift */, 65C2E40024B05D8A000AFDF6 /* FeedsSettingsModel.swift */,
5181C66124B0C326002E0F70 /* SettingsModel.swift */,
172199C824AB228900A31D04 /* SettingsView.swift */,
17B223B924AC24A8001E4592 /* Submenus */, 17B223B924AC24A8001E4592 /* Submenus */,
); );
path = Settings; path = Settings;
@ -4849,6 +4852,7 @@
51E4991D24A8092100B667CB /* NSAttributedString+NetNewsWire.swift in Sources */, 51E4991D24A8092100B667CB /* NSAttributedString+NetNewsWire.swift in Sources */,
51E499FD24A9137600B667CB /* SidebarModel.swift in Sources */, 51E499FD24A9137600B667CB /* SidebarModel.swift in Sources */,
51A576BE24AE637400078888 /* ArticleView.swift in Sources */, 51A576BE24AE637400078888 /* ArticleView.swift in Sources */,
5181C66224B0C326002E0F70 /* SettingsModel.swift in Sources */,
51E4995324A8734D00B667CB /* RedditFeedProvider-Extensions.swift in Sources */, 51E4995324A8734D00B667CB /* RedditFeedProvider-Extensions.swift in Sources */,
172199C924AB228900A31D04 /* SettingsView.swift in Sources */, 172199C924AB228900A31D04 /* SettingsView.swift in Sources */,
17D232A824AFF10A0005F075 /* AddWebFeedModel.swift in Sources */, 17D232A824AFF10A0005F075 /* AddWebFeedModel.swift in Sources */,