From 2978d4420b357471184016aa00f2a35847245f57 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 25 Sep 2017 13:31:36 -0700 Subject: [PATCH] Start work on adding feeds and folders. --- Evergreen/Data/DefaultFeedsImporter.swift | 10 +++---- .../Timeline/TimelineViewController.swift | 6 ++-- Frameworks/Account/Account.swift | 30 ++++++++++++++++++- Frameworks/Account/Container/Container.swift | 2 +- .../Account/Extensions/Feed+Account.swift | 9 ------ Frameworks/Data/Feed.swift | 2 +- 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/Evergreen/Data/DefaultFeedsImporter.swift b/Evergreen/Data/DefaultFeedsImporter.swift index 31c1570ce..8b075ff5f 100644 --- a/Evergreen/Data/DefaultFeedsImporter.swift +++ b/Evergreen/Data/DefaultFeedsImporter.swift @@ -10,14 +10,14 @@ import Foundation import Data import Account -private typealias DiskFeedDictionary = [String: String] +typealias DiskFeedDictionary = [String: String] struct DefaultFeedsImporter { static func importIfNeeded(_ firstRun: Bool, account: Account) { if shouldImportDefaultFeeds(firstRun) { - FeedsImporter.import(defaultFeeds(), account: account) + FeedsImporter.importFeeds(defaultFeeds(), account: account) } } @@ -44,10 +44,10 @@ struct DefaultFeedsImporter { struct FeedsImporter { - func import(_ feedDictionaries: [DiskFeedDictionary], account: Account) { + func importFeeds(_ feedDictionaries: [DiskFeedDictionary], account: Account) { - let feeds = feeds(with: feedDictionaries) - feeds.forEach { let _ = account.addItem($0) } + let feedsToImport = feeds(with: feedDictionaries) + feedsToImport.forEach(account.addItem) } private func feeds(with feedDictionaries: [DiskFeedDictionary]) -> Set { diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index 93ab63ab7..0940527ee 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -228,7 +228,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView guard let articles = note.appInfo?.articles else { return } - reloadCellsForArticles(articles) + reloadCellsForArticles(Array(articles)) } func fontSizeInDefaultsDidChange() { @@ -312,7 +312,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView return nil } - private func reloadCellsForArticles(_ articles: Set
) { + private func reloadCellsForArticles(_ articles: [Article]) { let indexes = indexesForArticles(articles) tableView.reloadData(forRowIndexes: indexes, columnIndexes: NSIndexSet(index: 0) as IndexSet) @@ -320,7 +320,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView // MARK: Articles - private func indexesForArticles(_ articles: Set
) -> IndexSet { + private func indexesForArticles(_ articles: [Article]) -> IndexSet { var indexes = IndexSet() diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 589784aad..45c08f534 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -79,7 +79,35 @@ public final class Account: DisplayNameProvider, Hashable { return nil //TODO } - + + public func canAddFeed(_ feed: Feed, to folder: Folder?) -> Bool { + + // If folder is nil, then it should go at the top level. + // The same feed in multiple folders is allowed. + // But the same feed can’t appear twice in the same folder + // (or at the top level). + + return true // TODO + } + + public func addFeed(_ feed: Feed, to folder: Folder?) -> Bool { + + // Return false if it couldn’t be added. + // If it already existed in that folder, return true. + + return true // TODO + } + + public func canAddFolder(_ folder: Folder, to folder: Folder?) -> Bool { + + return false // TODO + } + + public func addFolder(_ folder: Folder, to folder: Folder?) -> Bool { + + return false // TODO + } + public func importOPML(_ opmlDocument: RSOPMLDocument) { // TODO diff --git a/Frameworks/Account/Container/Container.swift b/Frameworks/Account/Container/Container.swift index ae7529423..28526518e 100644 --- a/Frameworks/Account/Container/Container.swift +++ b/Frameworks/Account/Container/Container.swift @@ -18,7 +18,7 @@ extension NSNotification.Name { } public protocol Container { - + //Recursive func hasAtLeastOneFeed() -> Bool func flattenedFeeds() -> Set diff --git a/Frameworks/Account/Extensions/Feed+Account.swift b/Frameworks/Account/Extensions/Feed+Account.swift index 2dd27b523..5de9e8c8b 100644 --- a/Frameworks/Account/Extensions/Feed+Account.swift +++ b/Frameworks/Account/Extensions/Feed+Account.swift @@ -21,13 +21,4 @@ public extension Feed { return accountWithID(accountID) } } - - struct DictionaryKey { - static let - } - - init?(accountID: String, feedDictionary: FeedDictionary) { - - - } } diff --git a/Frameworks/Data/Feed.swift b/Frameworks/Data/Feed.swift index 6ec97cfff..052ebdb14 100644 --- a/Frameworks/Data/Feed.swift +++ b/Frameworks/Data/Feed.swift @@ -10,7 +10,7 @@ import Foundation import RSCore import RSWeb -public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { +public final class Feed: DisplayNameProvider, UnreadCountProvider, Codable, Hashable { public let accountID: String public let url: String