2017-02-09 22:13:31 +08:00
|
|
|
//
|
|
|
|
|
// AboutRepositoryTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 9/2/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2020-06-28 21:25:40 +02:00
|
|
|
import UIKit
|
2017-02-09 22:13:31 +08:00
|
|
|
|
|
|
|
|
class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
2019-01-14 20:57:45 +01:00
|
|
|
private static let VALUE_NOT_AVAILABLE = "ValueNotAvailable".localize()
|
2019-01-07 20:21:04 +01:00
|
|
|
|
2017-03-24 22:05:09 +08:00
|
|
|
private var needRefresh = false
|
2024-11-24 13:14:38 +01:00
|
|
|
private var indicator = UIActivityIndicatorView(style: .medium)
|
2020-06-28 21:25:40 +02:00
|
|
|
|
2017-03-24 22:05:09 +08:00
|
|
|
private let passwordStore = PasswordStore.shared
|
2017-02-09 22:13:31 +08:00
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2017-03-19 14:36:20 -07:00
|
|
|
|
2017-03-24 21:54:31 +08:00
|
|
|
indicator.center = CGPoint(x: view.bounds.midX, y: view.bounds.height * 0.382)
|
2017-02-10 15:43:48 +08:00
|
|
|
tableView.addSubview(indicator)
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-11 00:48:15 +08:00
|
|
|
setTableData()
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-18 00:18:55 +08:00
|
|
|
// all password store updates (including erase, discard) will trigger the refresh
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(setNeedRefresh), name: .passwordStoreUpdated, object: nil)
|
2017-03-11 00:48:15 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-11 00:48:15 +08:00
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
if needRefresh {
|
|
|
|
|
setTableData()
|
2017-03-11 02:21:01 +08:00
|
|
|
needRefresh = false
|
2017-03-11 00:48:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-11 00:48:15 +08:00
|
|
|
private func setTableData() {
|
|
|
|
|
// clear current contents (if any)
|
2020-06-28 21:25:40 +02:00
|
|
|
tableData.removeAll(keepingCapacity: true)
|
|
|
|
|
tableView.reloadData()
|
2017-03-11 00:48:15 +08:00
|
|
|
indicator.startAnimating()
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-11 00:48:15 +08:00
|
|
|
// reload the table
|
2017-02-10 15:43:48 +08:00
|
|
|
DispatchQueue.global(qos: .userInitiated).async {
|
2018-11-16 22:28:19 -08:00
|
|
|
let passwords = self.numberOfPasswordsString()
|
|
|
|
|
let size = self.sizeOfRepositoryString()
|
2020-02-23 18:11:02 +08:00
|
|
|
let localCommits = String(self.passwordStore.numberOfLocalCommits)
|
2018-11-16 22:28:19 -08:00
|
|
|
let lastSynced = self.lastSyncedTimeString()
|
2019-01-06 19:59:16 +01:00
|
|
|
let commits = self.numberOfCommitsString()
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-02-10 15:43:48 +08:00
|
|
|
DispatchQueue.main.async { [weak self] in
|
2018-11-16 22:28:19 -08:00
|
|
|
guard let strongSelf = self else {
|
|
|
|
|
return
|
|
|
|
|
}
|
2019-05-01 17:49:27 +02:00
|
|
|
let type = UITableViewCell.AccessoryType.none
|
2018-11-16 22:28:19 -08:00
|
|
|
strongSelf.tableData = [
|
2017-02-10 15:43:48 +08:00
|
|
|
// section 0
|
2020-07-05 00:25:34 +02:00
|
|
|
[
|
|
|
|
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Passwords".localize(), .detailText: passwords],
|
|
|
|
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Size".localize(), .detailText: size],
|
|
|
|
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "LocalCommits".localize(), .detailText: localCommits],
|
|
|
|
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "LastSynced".localize(), .detailText: lastSynced],
|
|
|
|
|
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Commits".localize(), .detailText: commits],
|
|
|
|
|
[.title: "CommitLogs".localize(), .action: "segue", .link: "showCommitLogsSegue"],
|
|
|
|
|
],
|
2017-02-10 15:43:48 +08:00
|
|
|
]
|
2018-11-16 22:28:19 -08:00
|
|
|
strongSelf.indicator.stopAnimating()
|
|
|
|
|
strongSelf.tableView.reloadData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func numberOfPasswordsString() -> String {
|
|
|
|
|
let formatter = NumberFormatter()
|
|
|
|
|
formatter.numberStyle = NumberFormatter.Style.decimal
|
2020-06-28 21:25:40 +02:00
|
|
|
return formatter.string(from: NSNumber(value: passwordStore.numberOfPasswords)) ?? ""
|
2018-11-16 22:28:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func sizeOfRepositoryString() -> String {
|
2020-06-28 21:25:40 +02:00
|
|
|
ByteCountFormatter.string(fromByteCount: Int64(passwordStore.sizeOfRepositoryByteCount), countStyle: ByteCountFormatter.CountStyle.file)
|
2018-11-16 22:28:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func lastSyncedTimeString() -> String {
|
2020-06-28 21:25:40 +02:00
|
|
|
guard let date = passwordStore.lastSyncedTime else {
|
2019-01-14 20:57:45 +01:00
|
|
|
return "SyncAgain?".localize()
|
2017-02-10 00:50:03 +08:00
|
|
|
}
|
2018-11-16 22:28:19 -08:00
|
|
|
let formatter = DateFormatter()
|
|
|
|
|
formatter.dateStyle = .medium
|
|
|
|
|
formatter.timeStyle = .short
|
|
|
|
|
return formatter.string(from: date)
|
2017-02-09 22:13:31 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2019-01-06 19:59:16 +01:00
|
|
|
private func numberOfCommitsString() -> String {
|
2019-01-07 20:21:04 +01:00
|
|
|
if let numberOfCommits = passwordStore.numberOfCommits {
|
|
|
|
|
return String(numberOfCommits)
|
|
|
|
|
}
|
2021-10-03 05:46:07 +02:00
|
|
|
return Self.VALUE_NOT_AVAILABLE
|
2019-01-06 19:59:16 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
@objc
|
|
|
|
|
func setNeedRefresh() {
|
2017-03-11 00:48:15 +08:00
|
|
|
needRefresh = true
|
|
|
|
|
}
|
2017-02-09 22:13:31 +08:00
|
|
|
}
|