Make FeedListFeed and FeedListFolder structs.
This commit is contained in:
parent
c08bbaa970
commit
8014b56846
|
@ -9,7 +9,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import RSCore
|
import RSCore
|
||||||
|
|
||||||
final class FeedListFeed: Hashable, DisplayNameProvider {
|
struct FeedListFeed: Hashable, DisplayNameProvider {
|
||||||
|
|
||||||
let name: String
|
let name: String
|
||||||
let url: String
|
let url: String
|
||||||
|
@ -37,7 +37,7 @@ final class FeedListFeed: Hashable, DisplayNameProvider {
|
||||||
static let homePageURL = "homePageURL"
|
static let homePageURL = "homePageURL"
|
||||||
}
|
}
|
||||||
|
|
||||||
convenience init(dictionary: [String: String]) {
|
init(dictionary: [String: String]) {
|
||||||
|
|
||||||
let name = (dictionary[Key.name] ?? dictionary[Key.editedName])!
|
let name = (dictionary[Key.name] ?? dictionary[Key.editedName])!
|
||||||
let url = dictionary[Key.url]!
|
let url = dictionary[Key.url]!
|
||||||
|
|
|
@ -10,7 +10,7 @@ import Foundation
|
||||||
import RSCore
|
import RSCore
|
||||||
import Data
|
import Data
|
||||||
|
|
||||||
final class FeedListFolder: Hashable, DisplayNameProvider {
|
struct FeedListFolder: Hashable, DisplayNameProvider {
|
||||||
|
|
||||||
let name: String
|
let name: String
|
||||||
let feeds: Set<FeedListFeed>
|
let feeds: Set<FeedListFeed>
|
||||||
|
@ -31,6 +31,6 @@ final class FeedListFolder: Hashable, DisplayNameProvider {
|
||||||
|
|
||||||
static func ==(lhs: FeedListFolder, rhs: FeedListFolder) -> Bool {
|
static func ==(lhs: FeedListFolder, rhs: FeedListFolder) -> Bool {
|
||||||
|
|
||||||
return lhs === rhs
|
return lhs.name == rhs.name && lhs.feeds == rhs.feeds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ private extension FeedListTreeControllerDelegate {
|
||||||
|
|
||||||
func childNodesForRootNode(_ rootNode: Node) -> [Node]? {
|
func childNodesForRootNode(_ rootNode: Node) -> [Node]? {
|
||||||
|
|
||||||
let children = Array(topLevelFeeds) as [AnyObject] + Array(folders) as [AnyObject]
|
let children = (Array(topLevelFeeds) as [AnyHashable]) + (Array(folders) as [AnyHashable])
|
||||||
return childNodesForContainerNode(rootNode, children)
|
return childNodesForContainerNode(rootNode, children)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,18 +58,18 @@ private extension FeedListTreeControllerDelegate {
|
||||||
return childNodesForContainerNode(folderNode, Array(folder.feeds))
|
return childNodesForContainerNode(folderNode, Array(folder.feeds))
|
||||||
}
|
}
|
||||||
|
|
||||||
func childNodesForContainerNode(_ containerNode: Node, _ children: [AnyObject]) -> [Node]? {
|
func childNodesForContainerNode(_ containerNode: Node, _ children: [AnyHashable]) -> [Node]? {
|
||||||
|
|
||||||
let nodes = unsortedNodes(parent: containerNode, children: children)
|
let nodes = unsortedNodes(parent: containerNode, children: children)
|
||||||
return Node.nodesSortedAlphabeticallyWithFoldersAtEnd(nodes)
|
return Node.nodesSortedAlphabeticallyWithFoldersAtEnd(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func unsortedNodes(parent: Node, children: [AnyObject]) -> [Node] {
|
func unsortedNodes(parent: Node, children: [AnyHashable]) -> [Node] {
|
||||||
|
|
||||||
return children.map{ createNode(child: $0, parent: parent) }
|
return children.map{ createNode(child: $0, parent: parent) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNode(child: AnyObject, parent: Node) -> Node {
|
func createNode(child: AnyHashable, parent: Node) -> Node {
|
||||||
|
|
||||||
if let feed = child as? FeedListFeed {
|
if let feed = child as? FeedListFeed {
|
||||||
return createNode(feed: feed, parent: parent)
|
return createNode(feed: feed, parent: parent)
|
||||||
|
|
Loading…
Reference in New Issue