diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index f37e76a13..f4e479bfc 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -79,6 +79,7 @@ 84B0700B1ED3822600F0B54B /* RSTextDrawing.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84B070071ED3821900F0B54B /* RSTextDrawing.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84BB4B771F11753300858766 /* Data.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84BB4B681F1174D400858766 /* Data.framework */; }; 84BB4B781F11753300858766 /* Data.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84BB4B681F1174D400858766 /* Data.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 84E46C7D1F75EF7B005ECFB3 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */; }; 84FB9A2F1EDCD6C4003D53B9 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; }; 84FB9A301EDCD6C4003D53B9 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ @@ -436,6 +437,7 @@ 84B06FF41ED3818000F0B54B /* RSTree.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSTree.xcodeproj; path = Frameworks/RSTree/RSTree.xcodeproj; sourceTree = ""; }; 84B070011ED3821800F0B54B /* RSTextDrawing.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSTextDrawing.xcodeproj; path = Frameworks/RSTextDrawing/RSTextDrawing.xcodeproj; sourceTree = ""; }; 84BB4B611F1174D400858766 /* Data.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Data.xcodeproj; path = Frameworks/Data/Data.xcodeproj; sourceTree = ""; }; + 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDefaults.swift; path = Evergreen/AppDefaults.swift; sourceTree = ""; }; 84FB9A2D1EDCD6B8003D53B9 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Frameworks/Vendor/Sparkle.framework; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ @@ -668,6 +670,7 @@ 849C64671ED37A5D003D8FC0 /* Assets.xcassets */, 849C64691ED37A5D003D8FC0 /* Main.storyboard */, 842E45CD1ED8C308000A8B52 /* AppConstants.swift */, + 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */, 849C64631ED37A5D003D8FC0 /* AppDelegate.swift */, 842E45DC1ED8C54B000A8B52 /* Browser.swift */, 842E45E11ED8C681000A8B52 /* MainWindow */, @@ -1166,6 +1169,7 @@ 849A97661ED9EB96007D329B /* SidebarViewController.swift in Sources */, 842E45E31ED8C681000A8B52 /* KeyboardDelegateProtocol.swift in Sources */, 849A976E1ED9EBC8007D329B /* TimelineViewController.swift in Sources */, + 84E46C7D1F75EF7B005ECFB3 /* AppDefaults.swift in Sources */, 849A978D1ED9EE4D007D329B /* FeedListWindowController.swift in Sources */, 849A97771ED9EC04007D329B /* TimelineCellData.swift in Sources */, 849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */, diff --git a/Evergreen/AppConstants.swift b/Evergreen/AppConstants.swift index cd15a0f40..df99e5582 100644 --- a/Evergreen/AppConstants.swift +++ b/Evergreen/AppConstants.swift @@ -29,15 +29,5 @@ struct AppUserInfoKey { static let appNavigation = "key" } -struct AppDefaultsKey { - - static let firstRunDate = "firstRunDate" - - static let sidebarFontSize = "sidebarFontSize" - static let timelineFontSize = "timelineFontSize" - static let detailFontSize = "detailFontSize" - - static let openInBrowserInBackground = "openInBrowserInBackground" -} diff --git a/Evergreen/AppDefaults.swift b/Evergreen/AppDefaults.swift new file mode 100644 index 000000000..b90326967 --- /dev/null +++ b/Evergreen/AppDefaults.swift @@ -0,0 +1,74 @@ +// +// AppDefaults.swift +// Evergreen +// +// Created by Brent Simmons on 9/22/17. +// Copyright © 2017 Ranchero Software. All rights reserved. +// + +import Foundation + +final class AppDefaults { + + static let shared = AppDefaults() + + private struct Key { + + static let firstRunDate = "firstRunDate" + + static let sidebarFontSize = "sidebarFontSize" + static let timelineFontSize = "timelineFontSize" + static let detailFontSize = "detailFontSize" + + static let openInBrowserInBackground = "openInBrowserInBackground" + } + + var firstRunDate: Date? { + get { + return date(for: Key.firstRunDate) + } + set { + setDate(for: key.firstRunDate, date) + } + } + var openInBrowserInBackground: Bool { + get { + return bool(for: Key.openInBrowserInBackground) + } + set { + setBool(for: Key.openInBrowserInBackground, newValue) + } + } + + init() { + + registerDefaults() + } + + func registerDefaults() { + + + + } +} + +private extension AppDefaults { + + func bool(for key: String) -> Bool { + return UserDefaults.standard.bool(forKey: key) + } + + func setBool(for key: String, _ flag: Bool) { + UserDefaults.standard.set(flag, forKey: key) + } + + func date(for key: String) -> Date? { + return UserDefaults.standard.object(forKey: key) as? Date + } + + func setDate(for key: String, _ date: Date) { + UserDefaults.standard.set(date, forKey: key) + } +} + + diff --git a/Evergreen/Data/ArticleUtilities.swift b/Evergreen/Data/ArticleUtilities.swift index 24a16ec6c..2d817f343 100644 --- a/Evergreen/Data/ArticleUtilities.swift +++ b/Evergreen/Data/ArticleUtilities.swift @@ -49,16 +49,6 @@ extension Article { } } - var status: ArticleStatus? { - get { - guard let status = account?.articleStatus(for: self) else { - assertionFailure("Expected ArticleStatus for article.status.") - return nil - } - return status - } - } - var preferredLink: String? { get { return url ?? externalURL @@ -73,16 +63,7 @@ extension Article { var logicalDatePublished: Date { get { - return datePublished ?? dateModified ?? status?.dateArrived ?? Date.distantPast - } - } - - var read: Bool { - get { - if let status = status { - return status.read - } - return false + return datePublished ?? dateModified ?? status.dateArrived } } } diff --git a/Evergreen/Preferences/Defaults.swift b/Evergreen/Preferences/Defaults.swift index 5b773b556..1bb6999df 100644 --- a/Evergreen/Preferences/Defaults.swift +++ b/Evergreen/Preferences/Defaults.swift @@ -33,7 +33,7 @@ private let largestFontSizeRawValue = FontSize.veryLarge.rawValue func registerDefaults() { - let defaults = [AppDefaultsKey.sidebarFontSize: FontSize.medium.rawValue, AppDefaultsKey.timelineFontSize: FontSize.medium.rawValue, AppDefaultsKey.detailFontSize, FontSize.medium.rawValue] + let defaults = [AppDefaultsKey.sidebarFontSize: FontSize.medium.rawValue, AppDefaultsKey.timelineFontSize: FontSize.medium.rawValue, AppDefaultsKey.detailFontSize: FontSize.medium.rawValue] UserDefaults.standard.register(defaults: defaults) }