From 35160aaf75b3424e7f2cd6adaa0d8e4a789f4c90 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 5 May 2019 07:49:59 -0500 Subject: [PATCH] Rename AccountSettings to AccountMetadata to show that more than settings are stored in it and that it is analogous to FeedMetadata --- Frameworks/Account/Account.swift | 84 +++++++++---------- .../Account/Account.xcodeproj/project.pbxproj | 8 +- Frameworks/Account/AccountDelegate.swift | 2 +- ...ntSettings.swift => AccountMetadata.swift} | 10 +-- .../Account/Feedbin/FeedbinAPICaller.swift | 2 + .../Feedbin/FeedbinAccountDelegate.swift | 7 +- .../LocalAccount/LocalAccountDelegate.swift | 2 +- 7 files changed, 60 insertions(+), 55 deletions(-) rename Frameworks/Account/{AccountSettings.swift => AccountMetadata.swift} (72%) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index d951d22d0..dbb908e60 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -57,12 +57,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, public var name: String? { get { - return settings.name + return metadata.name } set { let currentNameForDisplay = nameForDisplay - if newValue != settings.name { - settings.name = newValue + if newValue != metadata.name { + metadata.name = newValue if currentNameForDisplay != nameForDisplay { postDisplayNameDidChangeNotification() } @@ -73,11 +73,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, public var isActive: Bool { get { - return settings.isActive + return metadata.isActive } set { - if newValue != settings.isActive { - settings.isActive = newValue + if newValue != metadata.isActive { + metadata.isActive = newValue NotificationCenter.default.post(name: .AccountStateDidChange, object: self, userInfo: nil) } } @@ -96,11 +96,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, var username: String? { get { - return settings.username + return metadata.username } set { - if newValue != settings.username { - settings.username = newValue + if newValue != metadata.username { + metadata.username = newValue } } } @@ -119,11 +119,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, private var _flattenedFeeds = Set() private var flattenedFeedsNeedUpdate = true - private let settingsPath: String - private var settings = AccountSettings() - private var settingsDirty = false { + private let metadataPath: String + private var metadata = AccountMetadata() + private var metadataDirty = false { didSet { - queueSaveSettingsIfNeeded() + queueSaveAccountMetadatafNeeded() } } @@ -132,7 +132,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, private var feedMetadata = FeedMetadataDictionary() private var feedMetadataDirty = false { didSet { - queueSaveMetadataIfNeeded() + queueSaveFeedMetadataIfNeeded() } } @@ -195,7 +195,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, self.database = ArticlesDatabase(databaseFilePath: databaseFilePath, accountID: accountID) self.feedMetadataPath = (dataFolder as NSString).appendingPathComponent("FeedMetadata.plist") - self.settingsPath = (dataFolder as NSString).appendingPathComponent("Settings.plist") + self.metadataPath = (dataFolder as NSString).appendingPathComponent("Settings.plist") switch type { case .onMyMac: @@ -388,8 +388,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, // For syncing, this may need to be an async method with a callback, // since it will likely need to call the server. - let feedMetadata = metadata(feedID: url) - let feed = Feed(account: self, url: url, feedID: url, metadata: feedMetadata) + let metadata = feedMetadata(feedID: url) + let feed = Feed(account: self, url: url, feedID: url, metadata: metadata) if let name = name, feed.name == nil { feed.name = name } @@ -671,15 +671,15 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } - @objc func saveMetadataIfNeeded() { + @objc func saveFeedMetadataIfNeeded() { if feedMetadataDirty { saveFeedMetadata() } } - @objc func saveSettingsIfNeeded() { - if settingsDirty { - saveSettings() + @objc func saveAccountMetadataIfNeeded() { + if metadataDirty { + saveAccountMetadata() } } @@ -697,11 +697,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } -// MARK: - AccountSettingsDelegate +// MARK: - AccountMetadataDelegate -extension Account: AccountSettingsDelegate { - func valueDidChange(_ accountSettings: AccountSettings, key: AccountSettings.CodingKeys) { - settingsDirty = true +extension Account: AccountMetadataDelegate { + func valueDidChange(_ accountMetadata: AccountMetadata, key: AccountMetadata.CodingKeys) { + metadataDirty = true } } @@ -727,20 +727,20 @@ private extension Account { } func pullObjectsFromDisk() { - importSettings() + importAccountMetadata() importFeedMetadata() importOPMLFile(path: opmlFilePath) } - func importSettings() { - let url = URL(fileURLWithPath: settingsPath) + func importAccountMetadata() { + let url = URL(fileURLWithPath: metadataPath) guard let data = try? Data(contentsOf: url) else { - settings.delegate = self + metadata.delegate = self return } let decoder = PropertyListDecoder() - settings = (try? decoder.decode(AccountSettings.self, from: data)) ?? AccountSettings() - settings.delegate = self + metadata = (try? decoder.decode(AccountMetadata.self, from: data)) ?? AccountMetadata() + metadata.delegate = self } func importFeedMetadata() { @@ -808,8 +808,8 @@ private extension Account { } } - func queueSaveMetadataIfNeeded() { - Account.saveQueue.add(self, #selector(saveMetadataIfNeeded)) + func queueSaveFeedMetadataIfNeeded() { + Account.saveQueue.add(self, #selector(saveFeedMetadataIfNeeded)) } private func metadataForOnlySubscribedToFeeds() -> FeedMetadataDictionary { @@ -835,18 +835,18 @@ private extension Account { } } - func queueSaveSettingsIfNeeded() { - Account.saveQueue.add(self, #selector(saveSettingsIfNeeded)) + func queueSaveAccountMetadatafNeeded() { + Account.saveQueue.add(self, #selector(saveAccountMetadataIfNeeded)) } - func saveSettings() { - settingsDirty = false + func saveAccountMetadata() { + metadataDirty = false let encoder = PropertyListEncoder() encoder.outputFormat = .binary - let url = URL(fileURLWithPath: settingsPath) + let url = URL(fileURLWithPath: metadataPath) do { - let data = try encoder.encode(settings) + let data = try encoder.encode(metadata) try data.write(to: url) } catch { @@ -859,7 +859,7 @@ private extension Account { private extension Account { - func metadata(feedID: String) -> FeedMetadata { + func feedMetadata(feedID: String) -> FeedMetadata { if let d = feedMetadata[feedID] { assert(d.delegate === self) return d @@ -894,8 +894,8 @@ private extension Account { func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed { let feedID = opmlFeedSpecifier.feedURL - let feedMetadata = metadata(feedID: feedID) - let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: feedID, metadata: feedMetadata) + let metadata = feedMetadata(feedID: feedID) + let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: feedID, metadata: metadata) if let feedTitle = opmlFeedSpecifier.title { if feed.name == nil { feed.name = feedTitle diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index f0abdc5a3..a405748e6 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -38,7 +38,7 @@ 84D09623217418DC00D77525 /* FeedbinTagging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D09622217418DC00D77525 /* FeedbinTagging.swift */; }; 84D0962521741B8500D77525 /* FeedbinSavedSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D0962421741B8500D77525 /* FeedbinSavedSearch.swift */; }; 84EAC4822148CC6300F154AB /* RSDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84EAC4812148CC6300F154AB /* RSDatabase.framework */; }; - 84F1F06E2243524700DA0616 /* AccountSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AF4EA3222CFDD100F6A800 /* AccountSettings.swift */; }; + 84F1F06E2243524700DA0616 /* AccountMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AF4EA3222CFDD100F6A800 /* AccountMetadata.swift */; }; 84F73CF1202788D90000BCEF /* ArticleFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */; }; /* End PBXBuildFile section */ @@ -113,7 +113,7 @@ 848935041F62485000CEBD24 /* AccountTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTests.swift; sourceTree = ""; }; 848935061F62485000CEBD24 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 848935101F62486800CEBD24 /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = ""; }; - 84AF4EA3222CFDD100F6A800 /* AccountSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSettings.swift; sourceTree = ""; }; + 84AF4EA3222CFDD100F6A800 /* AccountMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountMetadata.swift; sourceTree = ""; }; 84B2D4CE2238C13D00498ADA /* FeedMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedMetadata.swift; sourceTree = ""; }; 84B99C9E1FAE8D3200ECDEDB /* ContainerPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerPath.swift; sourceTree = ""; }; 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombinedRefreshProgress.swift; sourceTree = ""; }; @@ -217,7 +217,7 @@ 848935101F62486800CEBD24 /* Account.swift */, 841974241F6DDCE4006346C4 /* AccountDelegate.swift */, 846E77531F6F00E300A165E2 /* AccountManager.swift */, - 84AF4EA3222CFDD100F6A800 /* AccountSettings.swift */, + 84AF4EA3222CFDD100F6A800 /* AccountMetadata.swift */, 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */, 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */, 8419740D1F6DD25F006346C4 /* Container.swift */, @@ -449,7 +449,7 @@ 841974011F6DD1EC006346C4 /* Folder.swift in Sources */, 846E774F1F6EF9C000A165E2 /* LocalAccountDelegate.swift in Sources */, 844B297F210CE37E004020B3 /* UnreadCountProvider.swift in Sources */, - 84F1F06E2243524700DA0616 /* AccountSettings.swift in Sources */, + 84F1F06E2243524700DA0616 /* AccountMetadata.swift in Sources */, 84245C851FDDD8CB0074AFBB /* FeedbinFeed.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Frameworks/Account/AccountDelegate.swift b/Frameworks/Account/AccountDelegate.swift index b9cce3990..7afbf8ec3 100644 --- a/Frameworks/Account/AccountDelegate.swift +++ b/Frameworks/Account/AccountDelegate.swift @@ -15,7 +15,7 @@ protocol AccountDelegate { var supportsSubFolders: Bool { get } var server: String? { get } var credentials: Credentials? { get set } - var settings: AccountSettings? { get set } + var accountMetadata: AccountMetadata? { get set } var refreshProgress: DownloadProgress { get } diff --git a/Frameworks/Account/AccountSettings.swift b/Frameworks/Account/AccountMetadata.swift similarity index 72% rename from Frameworks/Account/AccountSettings.swift rename to Frameworks/Account/AccountMetadata.swift index 8b6e112e9..5209674c8 100644 --- a/Frameworks/Account/AccountSettings.swift +++ b/Frameworks/Account/AccountMetadata.swift @@ -1,5 +1,5 @@ // -// AccountSettings.swift +// AccountMetadata.swift // Account // // Created by Brent Simmons on 3/3/19. @@ -8,11 +8,11 @@ import Foundation -protocol AccountSettingsDelegate: class { - func valueDidChange(_ accountSettings: AccountSettings, key: AccountSettings.CodingKeys) +protocol AccountMetadataDelegate: class { + func valueDidChange(_ accountMetadata: AccountMetadata, key: AccountMetadata.CodingKeys) } -final class AccountSettings: Codable { +final class AccountMetadata: Codable { enum CodingKeys: String, CodingKey { case name @@ -44,7 +44,7 @@ final class AccountSettings: Codable { } } - weak var delegate: AccountSettingsDelegate? + weak var delegate: AccountMetadataDelegate? func valueDidChange(_ key: CodingKeys) { delegate?.valueDidChange(self, key: key) diff --git a/Frameworks/Account/Feedbin/FeedbinAPICaller.swift b/Frameworks/Account/Feedbin/FeedbinAPICaller.swift index e8ed64ecc..eb46c01c1 100644 --- a/Frameworks/Account/Feedbin/FeedbinAPICaller.swift +++ b/Frameworks/Account/Feedbin/FeedbinAPICaller.swift @@ -13,7 +13,9 @@ final class FeedbinAPICaller: NSObject { private let feedbinBaseURL = URL(string: "https://api.feedbin.com/v2/")! private var transport: Transport! + var credentials: Credentials? + var accountMetadata: AccountMetadata? init(transport: Transport) { super.init() diff --git a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift index 9cb2c1370..664b0145a 100644 --- a/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Frameworks/Account/Feedbin/FeedbinAccountDelegate.swift @@ -21,9 +21,12 @@ final class FeedbinAccountDelegate: AccountDelegate { } } - var settings: AccountSettings? + var accountMetadata: AccountMetadata? { + didSet { + caller.accountMetadata = accountMetadata + } + } - init(transport: Transport) { caller = FeedbinAPICaller(transport: transport) } diff --git a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift index ae006bb7b..3d3599060 100644 --- a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift @@ -14,7 +14,7 @@ final class LocalAccountDelegate: AccountDelegate { let supportsSubFolders = false let server: String? = nil var credentials: Credentials? - var settings: AccountSettings? + var accountMetadata: AccountMetadata? private let refresher = LocalAccountRefresher()