add pull to refresh function: sync password

This commit is contained in:
Bob Sun 2017-02-04 11:47:57 +08:00
parent 57a6a3f881
commit 6c7d4c0410
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -19,7 +19,7 @@ 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 Passwords")
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))
@ -27,8 +27,12 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
@IBOutlet weak var tableView: UITableView! @IBOutlet weak var tableView: UITableView!
@IBAction func refreshPasswords(_ sender: UIBarButtonItem) { @IBAction func refreshPasswords(_ sender: UIBarButtonItem) {
syncPasswords()
}
func syncPasswords() {
SVProgressHUD.setDefaultMaskType(.black) SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.show(withStatus: "Pull Remote Repository") SVProgressHUD.show(withStatus: "Sync Passwords")
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
if PasswordStore.shared.pullRepository(transferProgressBlock: {(git_transfer_progress, stop) in if PasswordStore.shared.pullRepository(transferProgressBlock: {(git_transfer_progress, stop) in
DispatchQueue.main.async { DispatchQueue.main.async {
@ -177,6 +181,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
} }
func handleRefresh(_ refreshControl: UIRefreshControl) { func handleRefresh(_ refreshControl: UIRefreshControl) {
syncPasswords()
refreshControl.endRefreshing() refreshControl.endRefreshing()
} }
} }