async calculating about repository page
This commit is contained in:
parent
c010d28911
commit
24139e932b
1 changed files with 36 additions and 16 deletions
|
|
@ -13,23 +13,43 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
navigationItemTitle = "About Repository"
|
navigationItemTitle = "About Repository"
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
let passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
let indicatorLable = UILabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 21))
|
||||||
let fm = FileManager.default
|
indicatorLable.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.height * 0.382 + 22)
|
||||||
var size = UInt64(0)
|
indicatorLable.backgroundColor = UIColor.clear
|
||||||
do {
|
indicatorLable.textColor = UIColor.gray
|
||||||
size = try fm.allocatedSizeOfDirectoryAtURL(directoryURL: PasswordStore.shared.storeURL)
|
indicatorLable.text = "calculating"
|
||||||
} catch {
|
indicatorLable.textAlignment = .center
|
||||||
print(error)
|
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)
|
||||||
|
|
||||||
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
|
let passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
|
let fm = FileManager.default
|
||||||
|
var size = UInt64(0)
|
||||||
|
do {
|
||||||
|
size = try fm.allocatedSizeOfDirectoryAtURL(directoryURL: PasswordStore.shared.storeURL)
|
||||||
|
} catch {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
let formatted = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: ByteCountFormatter.CountStyle.file)
|
||||||
|
self?.tableData = [
|
||||||
|
// section 0
|
||||||
|
[[.type: CellDataType.detail, .title: "Passwords", .detailText: String(passwordEntities.count)],
|
||||||
|
[.type: CellDataType.detail, .title: "Size", .detailText: formatted],
|
||||||
|
[.type: CellDataType.detail, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
indicator.stopAnimating()
|
||||||
|
indicatorLable.isHidden = true
|
||||||
|
self?.tableView.reloadData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let formatted = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: ByteCountFormatter.CountStyle.file)
|
|
||||||
tableData = [
|
|
||||||
// section 0
|
|
||||||
[[.type: CellDataType.detail, .title: "Passwords", .detailText: String(passwordEntities.count)],
|
|
||||||
[.type: CellDataType.detail, .title: "Size", .detailText: formatted],
|
|
||||||
[.type: CellDataType.detail, .title: "Last Synced", .detailText: Utils.getLastUpdatedTimeString()],
|
|
||||||
],
|
|
||||||
]
|
|
||||||
tableView.reloadData()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue