show last updated time
This commit is contained in:
parent
0ae47c2b30
commit
7eee62fa01
3 changed files with 18 additions and 3 deletions
|
|
@ -23,6 +23,5 @@ extension DefaultsKeys {
|
||||||
static let gitRepositorySSHPublicKeyURL = DefaultsKey<URL?>("gitRepositorySSHPublicKeyURL")
|
static let gitRepositorySSHPublicKeyURL = DefaultsKey<URL?>("gitRepositorySSHPublicKeyURL")
|
||||||
static let gitRepositorySSHPrivateKeyURL = DefaultsKey<URL?>("gitRepositorySSHPrivateKeyURL")
|
static let gitRepositorySSHPrivateKeyURL = DefaultsKey<URL?>("gitRepositorySSHPrivateKeyURL")
|
||||||
static let gitRepositorySSHPrivateKeyPassphrase = DefaultsKey<String?>("gitRepositorySSHPrivateKeyPassphrase")
|
static let gitRepositorySSHPrivateKeyPassphrase = DefaultsKey<String?>("gitRepositorySSHPrivateKeyPassphrase")
|
||||||
|
static let lastUpdatedTime = DefaultsKey<Date?>("lasteUpdatedTime")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
lazy var refreshControl: UIRefreshControl = {
|
lazy var refreshControl: UIRefreshControl = {
|
||||||
let refreshControl = UIRefreshControl()
|
let refreshControl = UIRefreshControl()
|
||||||
refreshControl.addTarget(self, action: #selector(PasswordsViewController.handleRefresh(_:)), for: UIControlEvents.valueChanged)
|
refreshControl.addTarget(self, action: #selector(PasswordsViewController.handleRefresh(_:)), for: UIControlEvents.valueChanged)
|
||||||
refreshControl.attributedTitle = NSAttributedString(string: "Sync Password Store")
|
|
||||||
return refreshControl
|
return refreshControl
|
||||||
}()
|
}()
|
||||||
let searchBarView = UIView(frame: CGRect(x: 0, y: 64, width: UIScreen.main.bounds.width, height: 44))
|
let searchBarView = UIView(frame: CGRect(x: 0, y: 64, width: UIScreen.main.bounds.width, height: 44))
|
||||||
|
|
@ -39,6 +38,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
self.passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
self.reloadTableView(data: self.passwordEntities!)
|
self.reloadTableView(data: self.passwordEntities!)
|
||||||
|
Defaults[.lastUpdatedTime] = Date()
|
||||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||||
SVProgressHUD.dismiss(withDelay: 1)
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
}
|
}
|
||||||
|
|
@ -66,6 +66,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
view.addSubview(searchBarView)
|
view.addSubview(searchBarView)
|
||||||
tableView.insertSubview(refreshControl, at: 0)
|
tableView.insertSubview(refreshControl, at: 0)
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
|
updateRefreshControlTitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
|
@ -197,9 +198,22 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateRefreshControlTitle() {
|
||||||
|
var atribbutedTitle = "Pull to Sync Password Store"
|
||||||
|
if let lastUpdatedTime = Defaults[.lastUpdatedTime] {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateStyle = .long
|
||||||
|
formatter.timeStyle = .short
|
||||||
|
let dateString = formatter.string(from: lastUpdatedTime)
|
||||||
|
atribbutedTitle = "Last Sync: \(dateString)"
|
||||||
|
}
|
||||||
|
refreshControl.attributedTitle = NSAttributedString(string: atribbutedTitle)
|
||||||
|
}
|
||||||
|
|
||||||
func reloadTableView (data: [PasswordEntity]) {
|
func reloadTableView (data: [PasswordEntity]) {
|
||||||
generateSections(item: data)
|
generateSections(item: data)
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
|
updateRefreshControlTitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRefresh(_ refreshControl: UIRefreshControl) {
|
func handleRefresh(_ refreshControl: UIRefreshControl) {
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,8 @@ class SettingsTableViewController: UITableViewController {
|
||||||
Defaults[.gitRepositoryPassword] = password
|
Defaults[.gitRepositoryPassword] = password
|
||||||
Defaults[.gitRepositoryAuthenticationMethod] = auth
|
Defaults[.gitRepositoryAuthenticationMethod] = auth
|
||||||
|
|
||||||
|
Defaults[.lastUpdatedTime] = Date()
|
||||||
|
|
||||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue