2017-09-17 20:32:58 +02:00
|
|
|
//
|
|
|
|
// LocalAccountDelegate.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 9/16/17.
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2017-10-07 23:40:14 +02:00
|
|
|
final class LocalAccountDelegate: AccountDelegate {
|
2017-09-17 20:32:58 +02:00
|
|
|
|
2017-09-28 22:16:47 +02:00
|
|
|
let supportsSubFolders = false
|
2017-10-02 22:15:07 +02:00
|
|
|
private let refresher = LocalAccountRefresher()
|
2017-10-07 23:40:14 +02:00
|
|
|
private weak var account: Account?
|
|
|
|
|
|
|
|
init(account: Account) {
|
|
|
|
|
|
|
|
self.account = account
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: refresher.progress)
|
|
|
|
}
|
2017-09-28 22:16:47 +02:00
|
|
|
|
2017-10-07 23:40:14 +02:00
|
|
|
func refreshAll() {
|
|
|
|
|
|
|
|
guard let account = account else {
|
|
|
|
return
|
|
|
|
}
|
2017-09-17 20:32:58 +02:00
|
|
|
|
2017-10-07 23:40:14 +02:00
|
|
|
account.refreshInProgress = true
|
2017-10-07 21:40:14 +02:00
|
|
|
refresher.refreshFeeds(account.flattenedFeeds())
|
2017-09-17 20:32:58 +02:00
|
|
|
}
|
2017-10-07 23:40:14 +02:00
|
|
|
|
|
|
|
// MARK: - Notifications
|
|
|
|
|
|
|
|
@objc func downloadProgressDidChange(_ note: Notification) {
|
|
|
|
|
|
|
|
if refresher.progress.numberRemaining < 1 {
|
|
|
|
account?.refreshInProgress = false
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
account?.refreshInProgress = true
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 20:32:58 +02:00
|
|
|
}
|