Update the progress bar when it comes into view so that it is always current

This commit is contained in:
Maurice Parker 2020-05-10 10:00:04 -05:00
parent 6c6f401e3e
commit fda9be2e41
3 changed files with 29 additions and 27 deletions

View File

@ -496,7 +496,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
} else { } else {
setFilterButtonToInactive() setFilterButtonToInactive()
} }
refreshProgressView?.updateRefreshLabel() refreshProgressView?.update()
addNewItemButton?.isEnabled = !AccountManager.shared.activeAccounts.isEmpty addNewItemButton?.isEnabled = !AccountManager.shared.activeAccounts.isEmpty
} }

View File

@ -17,42 +17,22 @@ class RefreshProgressView: UIView {
override func awakeFromNib() { override func awakeFromNib() {
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange(_:)), name: UIContentSizeCategory.didChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange(_:)), name: UIContentSizeCategory.didChangeNotification, object: nil)
update()
scheduleUpdateRefreshLabel()
}
func update() {
if !AccountManager.shared.combinedRefreshProgress.isComplete { if !AccountManager.shared.combinedRefreshProgress.isComplete {
progressChanged(animated: false) progressChanged(animated: false)
} else { } else {
updateRefreshLabel() updateRefreshLabel()
} }
scheduleUpdateRefreshLabel()
} }
override func didMoveToSuperview() { override func didMoveToSuperview() {
progressChanged(animated: false) progressChanged(animated: false)
} }
func updateRefreshLabel() {
if let accountLastArticleFetchEndTime = AccountManager.shared.lastArticleFetchEndTime {
if Date() > accountLastArticleFetchEndTime.addingTimeInterval(60) {
let relativeDateTimeFormatter = RelativeDateTimeFormatter()
relativeDateTimeFormatter.dateTimeStyle = .named
let refreshed = relativeDateTimeFormatter.localizedString(for: accountLastArticleFetchEndTime, relativeTo: Date())
let localizedRefreshText = NSLocalizedString("Updated %@", comment: "Updated")
let refreshText = NSString.localizedStringWithFormat(localizedRefreshText as NSString, refreshed) as String
label.text = refreshText
} else {
label.text = NSLocalizedString("Updated Just Now", comment: "Updated Just Now")
}
} else {
label.text = ""
}
}
@objc func progressDidChange(_ note: Notification) { @objc func progressDidChange(_ note: Notification) {
progressChanged(animated: true) progressChanged(animated: true)
} }
@ -109,6 +89,28 @@ private extension RefreshProgressView {
} }
} }
func updateRefreshLabel() {
if let accountLastArticleFetchEndTime = AccountManager.shared.lastArticleFetchEndTime {
if Date() > accountLastArticleFetchEndTime.addingTimeInterval(60) {
let relativeDateTimeFormatter = RelativeDateTimeFormatter()
relativeDateTimeFormatter.dateTimeStyle = .named
let refreshed = relativeDateTimeFormatter.localizedString(for: accountLastArticleFetchEndTime, relativeTo: Date())
let localizedRefreshText = NSLocalizedString("Updated %@", comment: "Updated")
let refreshText = NSString.localizedStringWithFormat(localizedRefreshText as NSString, refreshed) as String
label.text = refreshText
} else {
label.text = NSLocalizedString("Updated Just Now", comment: "Updated Just Now")
}
} else {
label.text = ""
}
}
func scheduleUpdateRefreshLabel() { func scheduleUpdateRefreshLabel() {
DispatchQueue.main.asyncAfter(deadline: .now() + 60) { [weak self] in DispatchQueue.main.asyncAfter(deadline: .now() + 60) { [weak self] in
self?.updateRefreshLabel() self?.updateRefreshLabel()

View File

@ -190,7 +190,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
} }
func updateUI() { func updateUI() {
refreshProgressView?.updateRefreshLabel() refreshProgressView?.update()
updateTitleUnreadCount() updateTitleUnreadCount()
updateToolbar() updateToolbar()
} }