Rename AccountSettings to AccountMetadata to show that more than settings are stored in it and that it is analogous to FeedMetadata
This commit is contained in:
parent
6e7477fd89
commit
35160aaf75
|
@ -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<Feed>()
|
||||
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
|
||||
|
|
|
@ -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 = "<group>"; };
|
||||
848935061F62485000CEBD24 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
848935101F62486800CEBD24 /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
|
||||
84AF4EA3222CFDD100F6A800 /* AccountSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSettings.swift; sourceTree = "<group>"; };
|
||||
84AF4EA3222CFDD100F6A800 /* AccountMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountMetadata.swift; sourceTree = "<group>"; };
|
||||
84B2D4CE2238C13D00498ADA /* FeedMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedMetadata.swift; sourceTree = "<group>"; };
|
||||
84B99C9E1FAE8D3200ECDEDB /* ContainerPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerPath.swift; sourceTree = "<group>"; };
|
||||
84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombinedRefreshProgress.swift; sourceTree = "<group>"; };
|
||||
|
@ -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;
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue