Handle refresh progress

This commit is contained in:
Anh Do 2020-03-14 18:33:38 -04:00
parent 0479bbd9f5
commit fb07cfe187
No known key found for this signature in database
GPG Key ID: 451E3092F917B62D
1 changed files with 9 additions and 3 deletions

View File

@ -90,7 +90,11 @@ final class NewsBlurAccountDelegate: AccountDelegate {
} }
case .failure(let error): case .failure(let error):
completion(.failure(error)) DispatchQueue.main.async {
self.refreshProgress.clear()
let wrappedError = AccountError.wrappedError(error: error, account: account)
completion(.failure(wrappedError))
}
} }
} }
@ -231,6 +235,10 @@ final class NewsBlurAccountDelegate: AccountDelegate {
case .success(let storyHashes): case .success(let storyHashes):
self.refreshProgress.completeTask() self.refreshProgress.completeTask()
if let count = storyHashes?.count, count > 0 {
self.refreshProgress.addToNumberOfTasksAndRemaining((count - 1) / 100 + 1)
}
self.refreshUnreadStories(for: account, hashes: storyHashes, updateFetchDate: nil, completion: completion) self.refreshUnreadStories(for: account, hashes: storyHashes, updateFetchDate: nil, completion: completion)
case .failure(let error): case .failure(let error):
completion(.failure(error)) completion(.failure(error))
@ -255,14 +263,12 @@ final class NewsBlurAccountDelegate: AccountDelegate {
switch result { switch result {
case .success(let stories): case .success(let stories):
self.processStories(account: account, stories: stories) { error in self.processStories(account: account, stories: stories) { error in
group.leave() group.leave()
if error != nil { if error != nil {
errorOccurred = true errorOccurred = true
} }
} }
case .failure(let error): case .failure(let error):
errorOccurred = true errorOccurred = true
os_log(.error, log: self.log, "Refresh missing stories failed: %@.", error.localizedDescription) os_log(.error, log: self.log, "Refresh missing stories failed: %@.", error.localizedDescription)