Add download progress for Feedbin accounts

This commit is contained in:
Maurice Parker 2019-05-14 13:10:07 -05:00
parent e31e1a4d60
commit 1984af4664
3 changed files with 39 additions and 4 deletions

View File

@ -324,7 +324,7 @@ final class FeedbinAPICaller: NSObject {
}
func retrieveEntries(completion: @escaping (Result<([FeedbinEntry]?, String?), Error>) -> Void) {
func retrieveEntries(completion: @escaping (Result<([FeedbinEntry]?, String?, Int?), Error>) -> Void) {
let since: Date = {
if let lastArticleFetch = accountMetadata?.lastArticleFetch {
@ -348,7 +348,8 @@ final class FeedbinAPICaller: NSObject {
self?.accountMetadata?.lastArticleFetch = dateInfo?.date
let pagingInfo = HTTPLinkPagingInfo(urlResponse: response)
completion(.success((entries, pagingInfo.nextPage)))
let lastPageNumber = self?.extractPageNumber(link: pagingInfo.lastPage)
completion(.success((entries, pagingInfo.nextPage, lastPageNumber)))
case .failure(let error):
completion(.failure(error))
@ -358,6 +359,25 @@ final class FeedbinAPICaller: NSObject {
}
func extractPageNumber(link: String?) -> Int? {
guard let link = link else {
return nil
}
if let lowerBound = link.range(of: "page=")?.upperBound {
if let upperBound = link.range(of: "&")?.lowerBound {
return Int(link[lowerBound..<upperBound])
}
if let upperBound = link.range(of: ">")?.lowerBound {
return Int(link[lowerBound..<upperBound])
}
}
return nil
}
func retrieveEntries(page: String, completion: @escaping (Result<([FeedbinEntry]?, String?), Error>) -> Void) {
guard let callURL = URL(string: page) else {

View File

@ -72,6 +72,8 @@ final class FeedbinAccountDelegate: AccountDelegate {
func refreshAll(for account: Account, completion: (() -> Void)? = nil) {
refreshProgress.addToNumberOfTasksAndRemaining(5)
refreshAccount(account) { [weak self] result in
switch result {
case .success():
@ -85,6 +87,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
case .failure(let error):
DispatchQueue.main.async {
completion?()
self?.refreshProgress.clear()
self?.handleError(error)
}
}
@ -438,6 +441,7 @@ private extension FeedbinAccountDelegate {
BatchUpdate.shared.perform {
self?.syncFolders(account, tags)
}
self?.refreshProgress.completeTask()
self?.refreshFeeds(account, completion: completion)
case .failure(let error):
completion(.failure(error))
@ -494,10 +498,12 @@ private extension FeedbinAccountDelegate {
switch result {
case .success(let subscriptions):
self?.refreshProgress.completeTask()
self?.caller.retrieveTaggings { [weak self] result in
switch result {
case .success(let taggings):
self?.refreshProgress.completeTask()
self?.caller.retrieveIcons { [weak self] result in
switch result {
case .success(let icons):
@ -508,6 +514,7 @@ private extension FeedbinAccountDelegate {
self?.syncFavicons(account, icons)
}
self?.refreshProgress.completeTask()
completion(.success(()))
case .failure(let error):
@ -922,14 +929,21 @@ private extension FeedbinAccountDelegate {
caller.retrieveEntries() { [weak self] result in
switch result {
case .success(let (entries, page)):
case .success(let (entries, page, lastPageNumber)):
if let last = lastPageNumber {
self?.refreshProgress.addToNumberOfTasksAndRemaining(last - 1)
}
self?.processEntries(account: account, entries: entries) {
self?.refreshProgress.completeTask()
self?.refreshArticles(account, page: page) {
guard let self = self else { return }
os_log(.debug, log: self.log, "Done refreshing articles.")
completion()
}
}
case .failure(let error):
@ -955,6 +969,7 @@ private extension FeedbinAccountDelegate {
case .success(let (entries, nextPage)):
self?.processEntries(account: account, entries: entries) {
self?.refreshProgress.completeTask()
self?.refreshArticles(account, page: nextPage, completion: completion)
}

@ -1 +1 @@
Subproject commit 517583fecf997254642ff7dfd629b5445b661e10
Subproject commit 809f9e1680594990a98e9266c974b5cbad6fa788