Move Account/Local folder to Account/LocalAccount, to make it easier to spot (since LocalAccount is its name). Also: wire up refreshing. Make organization changes to LocalAccountRefresher.

This commit is contained in:
Brent Simmons 2017-10-07 12:40:14 -07:00
parent f7c5919674
commit ab82febb9a
4 changed files with 30 additions and 27 deletions

View File

@ -192,13 +192,13 @@
path = Container; path = Container;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
8419742B1F6DDE84006346C4 /* Local */ = { 8419742B1F6DDE84006346C4 /* LocalAccount */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
8419742C1F6DDE84006346C4 /* LocalAccountDelegate.swift */, 8419742C1F6DDE84006346C4 /* LocalAccountDelegate.swift */,
8419742D1F6DDE96006346C4 /* LocalAccountRefresher.swift */, 8419742D1F6DDE96006346C4 /* LocalAccountRefresher.swift */,
); );
path = Local; path = LocalAccount;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
8469F80F1F6DC3C10084783E /* Frameworks */ = { 8469F80F1F6DC3C10084783E /* Frameworks */ = {
@ -230,7 +230,7 @@
841974001F6DD1EC006346C4 /* Folder.swift */, 841974001F6DD1EC006346C4 /* Folder.swift */,
846E77551F6F03B200A165E2 /* Extensions */, 846E77551F6F03B200A165E2 /* Extensions */,
841974141F6DD4FF006346C4 /* Container */, 841974141F6DD4FF006346C4 /* Container */,
8419742B1F6DDE84006346C4 /* Local */, 8419742B1F6DDE84006346C4 /* LocalAccount */,
8469F80F1F6DC3C10084783E /* Frameworks */, 8469F80F1F6DC3C10084783E /* Frameworks */,
848934FA1F62484F00CEBD24 /* Info.plist */, 848934FA1F62484F00CEBD24 /* Info.plist */,
848935031F62484F00CEBD24 /* AccountTests */, 848935031F62484F00CEBD24 /* AccountTests */,

View File

@ -84,9 +84,7 @@ public final class AccountManager: UnreadCountProvider {
public func refreshAll() { public func refreshAll() {
accounts.forEach { (account) in accounts.forEach { $0.refreshAll() }
account.refreshAll()
}
} }
public func anyAccountHasAtLeastOneFeed() -> Bool { public func anyAccountHasAtLeastOneFeed() -> Bool {

View File

@ -15,6 +15,6 @@ struct LocalAccountDelegate: AccountDelegate {
func refreshAll(for account: Account) { func refreshAll(for account: Account) {
// TODO refresher.refreshFeeds(account.flattenedFeeds())
} }
} }

View File

@ -12,7 +12,7 @@ import RSParser
import RSWeb import RSWeb
import Data import Data
final class LocalAccountRefresher: DownloadSessionDelegate { final class LocalAccountRefresher {
private lazy var downloadSession: DownloadSession = { private lazy var downloadSession: DownloadSession = {
return DownloadSession(delegate: self) return DownloadSession(delegate: self)
@ -24,14 +24,17 @@ final class LocalAccountRefresher: DownloadSessionDelegate {
} }
} }
public func refreshFeeds(_ feeds: NSSet) { public func refreshFeeds(_ feeds: Set<Feed>) {
downloadSession.downloadObjects(feeds)
}
// MARK: DownloadSessionDelegate downloadSession.downloadObjects(feeds as NSSet)
}
public func downloadSession(_ downloadSession: DownloadSession, requestForRepresentedObject representedObject: AnyObject) -> URLRequest? { }
// MARK: - DownloadSessionDelegate
extension LocalAccountRefresher: DownloadSessionDelegate {
func downloadSession(_ downloadSession: DownloadSession, requestForRepresentedObject representedObject: AnyObject) -> URLRequest? {
guard let feed = representedObject as? Feed else { guard let feed = representedObject as? Feed else {
return nil return nil
@ -49,7 +52,7 @@ final class LocalAccountRefresher: DownloadSessionDelegate {
return request as URLRequest return request as URLRequest
} }
public func downloadSession(_ downloadSession: DownloadSession, downloadDidCompleteForRepresentedObject representedObject: AnyObject, response: URLResponse?, data: Data, error: NSError?) { func downloadSession(_ downloadSession: DownloadSession, downloadDidCompleteForRepresentedObject representedObject: AnyObject, response: URLResponse?, data: Data, error: NSError?) {
guard let feed = representedObject as? Feed, !data.isEmpty else { guard let feed = representedObject as? Feed, !data.isEmpty else {
return return
@ -83,7 +86,7 @@ final class LocalAccountRefresher: DownloadSessionDelegate {
} }
} }
public func downloadSession(_ downloadSession: DownloadSession, shouldContinueAfterReceivingData data: Data, representedObject: AnyObject) -> Bool { func downloadSession(_ downloadSession: DownloadSession, shouldContinueAfterReceivingData data: Data, representedObject: AnyObject) -> Bool {
guard let feed = representedObject as? Feed else { guard let feed = representedObject as? Feed else {
return false return false
@ -106,23 +109,25 @@ final class LocalAccountRefresher: DownloadSessionDelegate {
func downloadSession(_ downloadSession: DownloadSession, didReceiveUnexpectedResponse response: URLResponse, representedObject: AnyObject) { func downloadSession(_ downloadSession: DownloadSession, didReceiveUnexpectedResponse response: URLResponse, representedObject: AnyObject) {
// guard let feed = representedObject as? LocalFeed else { guard let feed = representedObject as? Feed else {
// return return
// } }
//
// print("Unexpected response \(response) for \(feed.url).") print("Unexpected response \(response) for \(feed.url).")
} }
func downloadSession(_ downloadSession: DownloadSession, didReceiveNotModifiedResponse: URLResponse, representedObject: AnyObject) { func downloadSession(_ downloadSession: DownloadSession, didReceiveNotModifiedResponse: URLResponse, representedObject: AnyObject) {
// guard let feed = representedObject as? LocalFeed else { guard let feed = representedObject as? Feed else {
// return return
// } }
//
// print("Not modified response for \(feed.url).") print("Not modified response for \(feed.url).")
} }
} }
// MARK: - Utility
private extension Data { private extension Data {
func isDefinitelyNotFeed() -> Bool { func isDefinitelyNotFeed() -> Bool {