mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Change progress indicator to be a progress bar instead of the activity indicator.
This commit is contained in:
@@ -37,9 +37,15 @@ class DetailViewController: UIViewController {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(articleSelectionDidChange(_:)), name: .ArticleSelectionDidChange, object: navState)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
updateProgressIndicatorIfNeeded()
|
||||
}
|
||||
|
||||
func markAsRead() {
|
||||
if let article = navState?.currentArticle {
|
||||
markArticles(Set([article]), statusKey: .read, flag: true)
|
||||
@@ -107,6 +113,10 @@ class DetailViewController: UIViewController {
|
||||
updateUI()
|
||||
reloadHTML()
|
||||
}
|
||||
|
||||
@objc func progressDidChange(_ note: Notification) {
|
||||
updateProgressIndicatorIfNeeded()
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
@@ -204,3 +214,13 @@ extension DetailViewController: WKNavigationDelegate {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension DetailViewController {
|
||||
|
||||
func updateProgressIndicatorIfNeeded() {
|
||||
if !(UIDevice.current.userInterfaceIdiom == .pad) {
|
||||
navigationController?.updateAccountRefreshProgressIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import Articles
|
||||
import RSCore
|
||||
import RSTree
|
||||
|
||||
class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||
class MasterViewController: ProgressTableViewController, UndoableCommandRunner {
|
||||
|
||||
@IBOutlet weak var markAllAsReadButton: UIBarButtonItem!
|
||||
|
||||
@@ -35,7 +35,6 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(backingStoresDidRebuild(_:)), name: .BackingStoresDidRebuild, object: navState)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(masterSelectionDidChange(_:)), name: .MasterSelectionDidChange, object: navState)
|
||||
@@ -68,14 +67,6 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
@objc dynamic func progressDidChange(_ notification: Notification) {
|
||||
if AccountManager.shared.combinedRefreshProgress.isComplete {
|
||||
refreshControl?.endRefreshing()
|
||||
} else {
|
||||
refreshControl?.beginRefreshing()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func unreadCountDidChange(_ note: Notification) {
|
||||
|
||||
guard let representedObject = note.object else {
|
||||
@@ -626,6 +617,7 @@ private extension MasterViewController {
|
||||
|
||||
@objc private func refreshAccounts(_ sender: Any) {
|
||||
AccountManager.shared.refreshAll()
|
||||
refreshControl?.endRefreshing()
|
||||
}
|
||||
|
||||
func updateUI() {
|
||||
|
||||
132
iOS/Progress/NavigationProgressView.swift
Normal file
132
iOS/Progress/NavigationProgressView.swift
Normal file
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// NavigationProgressView.swift
|
||||
// KYNavigationProgress
|
||||
//
|
||||
// Created by kyo__hei on 2015/12/29.
|
||||
// Copyright (c) 2015 kyo__hei. All rights reserved.
|
||||
//
|
||||
// Original project: https://github.com/ykyouhei/KYNavigationProgress
|
||||
|
||||
import UIKit
|
||||
|
||||
public final class NavigationProgressView: UIView {
|
||||
|
||||
/* ====================================================================== */
|
||||
// MARK: - Properties
|
||||
/* ====================================================================== */
|
||||
|
||||
internal var progress: Float = 0 {
|
||||
didSet {
|
||||
progress = min(1, progress)
|
||||
barWidthConstraint.constant = bounds.width * CGFloat(progress)
|
||||
}
|
||||
}
|
||||
|
||||
internal let bar = UIView()
|
||||
|
||||
@objc public dynamic var progressTintColor: UIColor? = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1) {
|
||||
didSet {
|
||||
bar.backgroundColor = progressTintColor
|
||||
}
|
||||
}
|
||||
|
||||
@objc public dynamic var trackTintColor: UIColor? = .clear {
|
||||
didSet {
|
||||
backgroundColor = trackTintColor
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate let barWidthConstraint: NSLayoutConstraint
|
||||
|
||||
override public var frame: CGRect {
|
||||
didSet {
|
||||
let tmpProgress = progress
|
||||
progress = tmpProgress
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ====================================================================== */
|
||||
// MARK: - initializer
|
||||
/* ====================================================================== */
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
barWidthConstraint = NSLayoutConstraint(
|
||||
item: bar,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: .notAnAttribute,
|
||||
multiplier: 1,
|
||||
constant: frame.width * CGFloat(progress))
|
||||
|
||||
super.init(frame: frame)
|
||||
|
||||
let leftConstraint = NSLayoutConstraint(
|
||||
item: bar,
|
||||
attribute: .left,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .left,
|
||||
multiplier: 1,
|
||||
constant: 0)
|
||||
|
||||
let bottomConstraint = NSLayoutConstraint(
|
||||
item: bar,
|
||||
attribute: .bottom,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .bottom,
|
||||
multiplier: 1,
|
||||
constant: 0)
|
||||
|
||||
let topConstraint = NSLayoutConstraint(
|
||||
item: bar,
|
||||
attribute: .top,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .top,
|
||||
multiplier: 1,
|
||||
constant: 0)
|
||||
|
||||
addSubview(bar)
|
||||
|
||||
backgroundColor = trackTintColor
|
||||
|
||||
bar.backgroundColor = progressTintColor
|
||||
bar.translatesAutoresizingMaskIntoConstraints = false
|
||||
addConstraints([
|
||||
barWidthConstraint,
|
||||
leftConstraint,
|
||||
topConstraint,
|
||||
bottomConstraint])
|
||||
}
|
||||
|
||||
|
||||
/* ====================================================================== */
|
||||
// MARK: - Notification
|
||||
/* ====================================================================== */
|
||||
|
||||
func deviceDidRotate(_ notification: Notification) {
|
||||
}
|
||||
|
||||
|
||||
/* ====================================================================== */
|
||||
// MARK: - Method
|
||||
/* ====================================================================== */
|
||||
|
||||
internal func setProgress(_ progress: Float, animated: Bool) {
|
||||
let duration: TimeInterval = animated ? 0.1 : 0
|
||||
|
||||
self.progress = progress
|
||||
|
||||
UIView.animate(withDuration: duration, animations: {
|
||||
self.layoutIfNeeded()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
27
iOS/Progress/ProgressTableViewController.swift
Normal file
27
iOS/Progress/ProgressTableViewController.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// ProgressTableViewController.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Maurice Parker on 4/23/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class ProgressTableViewController: UITableViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
navigationController?.updateAccountRefreshProgressIndicator()
|
||||
}
|
||||
|
||||
@objc func progressDidChange(_ note: Notification) {
|
||||
navigationController?.updateAccountRefreshProgressIndicator()
|
||||
}
|
||||
|
||||
}
|
||||
145
iOS/Progress/UINavigationController+Progress.swift
Normal file
145
iOS/Progress/UINavigationController+Progress.swift
Normal file
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// UINavigationController+Progress.swift
|
||||
// KYNavigationProgress
|
||||
//
|
||||
// Created by kyo__hei on 2015/12/29.
|
||||
// Copyright (c) 2015 kyo__hei. All rights reserved.
|
||||
//
|
||||
// Original project: https://github.com/ykyouhei/KYNavigationProgress
|
||||
|
||||
import UIKit
|
||||
import Account
|
||||
|
||||
private let constraintIdentifier = "progressHeightConstraint"
|
||||
|
||||
public extension UINavigationController {
|
||||
|
||||
/* ====================================================================== */
|
||||
// MARK: - Properties
|
||||
/* ====================================================================== */
|
||||
|
||||
/**
|
||||
Default is 2.0
|
||||
*/
|
||||
var progressHeight: CGFloat {
|
||||
get { return progressView.frame.height }
|
||||
set {
|
||||
progressView.frame.origin.y = navigationBar.frame.height - newValue
|
||||
progressView.frame.size.height = newValue
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
The color shown for the portion of the progress bar that is not filled.
|
||||
default is clear color.
|
||||
*/
|
||||
var trackTintColor: UIColor? {
|
||||
get { return progressView.trackTintColor }
|
||||
set { progressView.trackTintColor = newValue }
|
||||
}
|
||||
|
||||
/**
|
||||
The color shown for the portion of the progress bar that is filled.
|
||||
default is (r: 0, g: 122, b: 225, a: 255.
|
||||
*/
|
||||
var progressTintColor: UIColor? {
|
||||
get { return progressView.progressTintColor }
|
||||
set { progressView.progressTintColor = newValue }
|
||||
}
|
||||
|
||||
/**
|
||||
The current progress is represented by a floating-point value between 0.0 and 1.0,
|
||||
inclusive, where 1.0 indicates the completion of the task. The default value is 0.0.
|
||||
*/
|
||||
var progress: Float {
|
||||
get { return progressView.progress }
|
||||
set { progressView.progress = newValue }
|
||||
}
|
||||
|
||||
|
||||
private var progressView: NavigationProgressView {
|
||||
|
||||
for subview in navigationBar.subviews {
|
||||
if let progressView = subview as? NavigationProgressView {
|
||||
return progressView
|
||||
}
|
||||
}
|
||||
|
||||
let defaultHeight = CGFloat(2)
|
||||
let frame = CGRect(
|
||||
x: 0,
|
||||
y: navigationBar.frame.height - defaultHeight,
|
||||
width: navigationBar.frame.width,
|
||||
height: defaultHeight
|
||||
)
|
||||
let progressView = NavigationProgressView(frame: frame)
|
||||
|
||||
navigationBar.addSubview(progressView)
|
||||
|
||||
progressView.autoresizingMask = [
|
||||
.flexibleWidth, .flexibleTopMargin
|
||||
]
|
||||
|
||||
|
||||
return progressView
|
||||
}
|
||||
|
||||
|
||||
/* ====================================================================== */
|
||||
// MARK: - Public Method
|
||||
/* ====================================================================== */
|
||||
|
||||
/**
|
||||
Adjusts the current progress shown by the receiver, optionally animating the change.
|
||||
|
||||
- parameter progress: The new progress value.
|
||||
- parameter animated: true if the change should be animated, false if the change should happen immediately.
|
||||
*/
|
||||
func setProgress(_ progress: Float, animated: Bool) {
|
||||
progressView.bar.alpha = 1
|
||||
progressView.setProgress(progress, animated: animated)
|
||||
}
|
||||
|
||||
/**
|
||||
While progress is changed to 1.0, the bar will fade out. After that, progress will be 0.0.
|
||||
*/
|
||||
func finishProgress() {
|
||||
progressView.bar.alpha = 1
|
||||
progressView.setProgress(1, animated: true)
|
||||
|
||||
UIView.animate(withDuration: 0.25,
|
||||
animations: {
|
||||
self.progressView.bar.alpha = 0
|
||||
}, completion: { finished in
|
||||
self.progressView.progress = 0
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
While progress is changed to 0.0, the bar will fade out.
|
||||
*/
|
||||
func cancelProgress() {
|
||||
progressView.setProgress(0, animated: true)
|
||||
|
||||
UIView.animate(withDuration: 0.25, animations: {
|
||||
self.progressView.bar.alpha = 0
|
||||
})
|
||||
}
|
||||
|
||||
func updateAccountRefreshProgressIndicator() {
|
||||
|
||||
let progress = AccountManager.shared.combinedRefreshProgress
|
||||
|
||||
if progress.isComplete {
|
||||
if self.progress != 0 {
|
||||
finishProgress()
|
||||
}
|
||||
} else {
|
||||
let percent = Float(progress.numberCompleted) / Float(progress.numberOfTasks)
|
||||
setProgress(percent, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import RSCore
|
||||
import Account
|
||||
import Articles
|
||||
|
||||
class MasterTimelineViewController: UITableViewController, UndoableCommandRunner {
|
||||
class MasterTimelineViewController: ProgressTableViewController, UndoableCommandRunner {
|
||||
|
||||
private var rowHeightWithFeedName: CGFloat = 0.0
|
||||
private var rowHeightWithoutFeedName: CGFloat = 0.0
|
||||
@@ -41,7 +41,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(articlesReinitialized(_:)), name: .ArticlesReinitialized, object: navState)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(articleDataDidChange(_:)), name: .ArticleDataDidChange, object: navState)
|
||||
@@ -184,14 +183,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc dynamic func progressDidChange(_ notification: Notification) {
|
||||
if AccountManager.shared.combinedRefreshProgress.isComplete {
|
||||
refreshControl?.endRefreshing()
|
||||
} else {
|
||||
refreshControl?.beginRefreshing()
|
||||
}
|
||||
}
|
||||
|
||||
@objc dynamic func unreadCountDidChange(_ notification: Notification) {
|
||||
updateUI()
|
||||
}
|
||||
@@ -350,6 +341,7 @@ private extension MasterTimelineViewController {
|
||||
|
||||
@objc private func refreshAccounts(_ sender: Any) {
|
||||
AccountManager.shared.refreshAll()
|
||||
refreshControl?.endRefreshing()
|
||||
}
|
||||
|
||||
func resetUI() {
|
||||
|
||||
Reference in New Issue
Block a user