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:
parent
f7c5919674
commit
ab82febb9a
|
@ -192,13 +192,13 @@
|
|||
path = Container;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8419742B1F6DDE84006346C4 /* Local */ = {
|
||||
8419742B1F6DDE84006346C4 /* LocalAccount */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8419742C1F6DDE84006346C4 /* LocalAccountDelegate.swift */,
|
||||
8419742D1F6DDE96006346C4 /* LocalAccountRefresher.swift */,
|
||||
);
|
||||
path = Local;
|
||||
path = LocalAccount;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8469F80F1F6DC3C10084783E /* Frameworks */ = {
|
||||
|
@ -230,7 +230,7 @@
|
|||
841974001F6DD1EC006346C4 /* Folder.swift */,
|
||||
846E77551F6F03B200A165E2 /* Extensions */,
|
||||
841974141F6DD4FF006346C4 /* Container */,
|
||||
8419742B1F6DDE84006346C4 /* Local */,
|
||||
8419742B1F6DDE84006346C4 /* LocalAccount */,
|
||||
8469F80F1F6DC3C10084783E /* Frameworks */,
|
||||
848934FA1F62484F00CEBD24 /* Info.plist */,
|
||||
848935031F62484F00CEBD24 /* AccountTests */,
|
||||
|
|
|
@ -84,9 +84,7 @@ public final class AccountManager: UnreadCountProvider {
|
|||
|
||||
public func refreshAll() {
|
||||
|
||||
accounts.forEach { (account) in
|
||||
account.refreshAll()
|
||||
}
|
||||
accounts.forEach { $0.refreshAll() }
|
||||
}
|
||||
|
||||
public func anyAccountHasAtLeastOneFeed() -> Bool {
|
||||
|
|
|
@ -15,6 +15,6 @@ struct LocalAccountDelegate: AccountDelegate {
|
|||
|
||||
func refreshAll(for account: Account) {
|
||||
|
||||
// TODO
|
||||
refresher.refreshFeeds(account.flattenedFeeds())
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ import RSParser
|
|||
import RSWeb
|
||||
import Data
|
||||
|
||||
final class LocalAccountRefresher: DownloadSessionDelegate {
|
||||
final class LocalAccountRefresher {
|
||||
|
||||
private lazy var downloadSession: DownloadSession = {
|
||||
return DownloadSession(delegate: self)
|
||||
|
@ -24,14 +24,17 @@ final class LocalAccountRefresher: DownloadSessionDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
public func refreshFeeds(_ feeds: NSSet) {
|
||||
|
||||
downloadSession.downloadObjects(feeds)
|
||||
}
|
||||
public func refreshFeeds(_ feeds: Set<Feed>) {
|
||||
|
||||
// MARK: DownloadSessionDelegate
|
||||
|
||||
public func downloadSession(_ downloadSession: DownloadSession, requestForRepresentedObject representedObject: AnyObject) -> URLRequest? {
|
||||
downloadSession.downloadObjects(feeds as NSSet)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - DownloadSessionDelegate
|
||||
|
||||
extension LocalAccountRefresher: DownloadSessionDelegate {
|
||||
|
||||
func downloadSession(_ downloadSession: DownloadSession, requestForRepresentedObject representedObject: AnyObject) -> URLRequest? {
|
||||
|
||||
guard let feed = representedObject as? Feed else {
|
||||
return nil
|
||||
|
@ -49,7 +52,7 @@ final class LocalAccountRefresher: DownloadSessionDelegate {
|
|||
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 {
|
||||
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 {
|
||||
return false
|
||||
|
@ -106,23 +109,25 @@ final class LocalAccountRefresher: DownloadSessionDelegate {
|
|||
|
||||
func downloadSession(_ downloadSession: DownloadSession, didReceiveUnexpectedResponse response: URLResponse, representedObject: AnyObject) {
|
||||
|
||||
// guard let feed = representedObject as? LocalFeed else {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// print("Unexpected response \(response) for \(feed.url).")
|
||||
guard let feed = representedObject as? Feed else {
|
||||
return
|
||||
}
|
||||
|
||||
print("Unexpected response \(response) for \(feed.url).")
|
||||
}
|
||||
|
||||
func downloadSession(_ downloadSession: DownloadSession, didReceiveNotModifiedResponse: URLResponse, representedObject: AnyObject) {
|
||||
|
||||
// guard let feed = representedObject as? LocalFeed else {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// print("Not modified response for \(feed.url).")
|
||||
guard let feed = representedObject as? Feed else {
|
||||
return
|
||||
}
|
||||
|
||||
print("Not modified response for \(feed.url).")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Utility
|
||||
|
||||
private extension Data {
|
||||
|
||||
func isDefinitelyNotFeed() -> Bool {
|
Loading…
Reference in New Issue