Start work on adding feeds and folders.

This commit is contained in:
Brent Simmons 2017-09-25 13:31:36 -07:00
parent 21080a97fc
commit 2978d4420b
6 changed files with 39 additions and 20 deletions

View File

@ -10,14 +10,14 @@ import Foundation
import Data import Data
import Account import Account
private typealias DiskFeedDictionary = [String: String] typealias DiskFeedDictionary = [String: String]
struct DefaultFeedsImporter { struct DefaultFeedsImporter {
static func importIfNeeded(_ firstRun: Bool, account: Account) { static func importIfNeeded(_ firstRun: Bool, account: Account) {
if shouldImportDefaultFeeds(firstRun) { if shouldImportDefaultFeeds(firstRun) {
FeedsImporter.import(defaultFeeds(), account: account) FeedsImporter.importFeeds(defaultFeeds(), account: account)
} }
} }
@ -44,10 +44,10 @@ struct DefaultFeedsImporter {
struct FeedsImporter { struct FeedsImporter {
func import(_ feedDictionaries: [DiskFeedDictionary], account: Account) { func importFeeds(_ feedDictionaries: [DiskFeedDictionary], account: Account) {
let feeds = feeds(with: feedDictionaries) let feedsToImport = feeds(with: feedDictionaries)
feeds.forEach { let _ = account.addItem($0) } feedsToImport.forEach(account.addItem)
} }
private func feeds(with feedDictionaries: [DiskFeedDictionary]) -> Set<Feed> { private func feeds(with feedDictionaries: [DiskFeedDictionary]) -> Set<Feed> {

View File

@ -228,7 +228,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
guard let articles = note.appInfo?.articles else { guard let articles = note.appInfo?.articles else {
return return
} }
reloadCellsForArticles(articles) reloadCellsForArticles(Array(articles))
} }
func fontSizeInDefaultsDidChange() { func fontSizeInDefaultsDidChange() {
@ -312,7 +312,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
return nil return nil
} }
private func reloadCellsForArticles(_ articles: Set<Article>) { private func reloadCellsForArticles(_ articles: [Article]) {
let indexes = indexesForArticles(articles) let indexes = indexesForArticles(articles)
tableView.reloadData(forRowIndexes: indexes, columnIndexes: NSIndexSet(index: 0) as IndexSet) tableView.reloadData(forRowIndexes: indexes, columnIndexes: NSIndexSet(index: 0) as IndexSet)
@ -320,7 +320,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
// MARK: Articles // MARK: Articles
private func indexesForArticles(_ articles: Set<Article>) -> IndexSet { private func indexesForArticles(_ articles: [Article]) -> IndexSet {
var indexes = IndexSet() var indexes = IndexSet()

View File

@ -79,7 +79,35 @@ public final class Account: DisplayNameProvider, Hashable {
return nil //TODO 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 cant 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 couldnt 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) { public func importOPML(_ opmlDocument: RSOPMLDocument) {
// TODO // TODO

View File

@ -18,7 +18,7 @@ extension NSNotification.Name {
} }
public protocol Container { public protocol Container {
//Recursive //Recursive
func hasAtLeastOneFeed() -> Bool func hasAtLeastOneFeed() -> Bool
func flattenedFeeds() -> Set<Feed> func flattenedFeeds() -> Set<Feed>

View File

@ -21,13 +21,4 @@ public extension Feed {
return accountWithID(accountID) return accountWithID(accountID)
} }
} }
struct DictionaryKey {
static let
}
init?(accountID: String, feedDictionary: FeedDictionary) {
}
} }

View File

@ -10,7 +10,7 @@ import Foundation
import RSCore import RSCore
import RSWeb import RSWeb
public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { public final class Feed: DisplayNameProvider, UnreadCountProvider, Codable, Hashable {
public let accountID: String public let accountID: String
public let url: String public let url: String