Automatically update the "about repository" page when the repository gets updated
This commit is contained in:
parent
453e6d251a
commit
11066d0bb6
1 changed files with 48 additions and 15 deletions
|
|
@ -10,22 +10,47 @@ import UIKit
|
|||
|
||||
class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||
|
||||
var needRefresh = false
|
||||
var indicatorLabel: UILabel!
|
||||
var indicator: UIActivityIndicatorView!
|
||||
|
||||
override func viewDidLoad() {
|
||||
navigationItemTitle = "About Repository"
|
||||
super.viewDidLoad()
|
||||
let indicatorLable = UILabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 21))
|
||||
indicatorLable.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382 + 22)
|
||||
indicatorLable.backgroundColor = UIColor.clear
|
||||
indicatorLable.textColor = UIColor.gray
|
||||
indicatorLable.text = "calculating"
|
||||
indicatorLable.textAlignment = .center
|
||||
indicatorLable.font = UIFont.preferredFont(forTextStyle: .footnote)
|
||||
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
||||
indicator.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382)
|
||||
indicator.startAnimating()
|
||||
tableView.addSubview(indicator)
|
||||
tableView.addSubview(indicatorLable)
|
||||
|
||||
indicatorLabel = UILabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 21))
|
||||
indicatorLabel.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382 + 22)
|
||||
indicatorLabel.backgroundColor = UIColor.clear
|
||||
indicatorLabel.textColor = UIColor.gray
|
||||
indicatorLabel.text = "calculating"
|
||||
indicatorLabel.textAlignment = .center
|
||||
indicatorLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
|
||||
indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
||||
indicator.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382)
|
||||
tableView.addSubview(indicator)
|
||||
tableView.addSubview(indicatorLabel)
|
||||
|
||||
setTableData()
|
||||
addNotificationObservers()
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
if needRefresh {
|
||||
indicatorLabel.text = "reloading"
|
||||
setTableData()
|
||||
}
|
||||
}
|
||||
|
||||
private func setTableData() {
|
||||
|
||||
// clear current contents (if any)
|
||||
self.tableData.removeAll(keepingCapacity: true)
|
||||
self.tableView.reloadData()
|
||||
indicatorLabel.isHidden = false
|
||||
indicator.startAnimating()
|
||||
|
||||
// reload the table
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let numberFormatter = NumberFormatter()
|
||||
numberFormatter.numberStyle = NumberFormatter.Style.decimal
|
||||
|
|
@ -59,11 +84,19 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
|||
[.title: "Commit Logs", .action: "segue", .link: "showCommitLogsSegue"],
|
||||
],
|
||||
]
|
||||
indicator.stopAnimating()
|
||||
indicatorLable.isHidden = true
|
||||
self?.indicator.stopAnimating()
|
||||
self?.indicatorLabel.isHidden = true
|
||||
self?.tableView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func addNotificationObservers() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(setNeedRefresh), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(setNeedRefresh), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
|
||||
}
|
||||
|
||||
func setNeedRefresh() {
|
||||
needRefresh = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue