From 825cd5446dcbc5dee58f0fa23e36f8006c9d28ef Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Wed, 8 Feb 2017 01:29:00 +0800 Subject: [PATCH] long press to copy password --- pass/PasswordsViewController.swift | 25 ++++++++++++++++++++++++- pass/SettingsTableViewController.swift | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pass/PasswordsViewController.swift b/pass/PasswordsViewController.swift index 72de576..702cfcf 100644 --- a/pass/PasswordsViewController.swift +++ b/pass/PasswordsViewController.swift @@ -28,6 +28,8 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV @IBOutlet weak var tableView: UITableView! func syncPasswords() { + SVProgressHUD.setDefaultMaskType(.black) + SVProgressHUD.setDefaultStyle(.light) SVProgressHUD.show(withStatus: "Sync Password Store") DispatchQueue.global(qos: .userInitiated).async { [unowned self] in do { @@ -110,9 +112,21 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV password = passwordEntities![index] } cell.textLabel?.text = password.name + let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:))) + longPressGestureRecognizer.minimumPressDuration = 1.0 + cell.addGestureRecognizer(longPressGestureRecognizer) return cell } + func longPressAction(_ gesture: UILongPressGestureRecognizer) { + if gesture.state == UIGestureRecognizerState.began { + let touchPoint = gesture.location(in: tableView) + if let indexPath = tableView.indexPathForRow(at: touchPoint) { + copyToPasteboard(from: indexPath) + } + } + } + func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sections[section].title } @@ -125,8 +139,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV return index } - func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { + copyToPasteboard(from: indexPath) + } + + func copyToPasteboard(from indexPath: IndexPath) { let index = sections[indexPath.section].index + indexPath.row let password: PasswordEntity if searchController.isActive && searchController.searchBar.text != "" { @@ -137,6 +154,12 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV do { let decryptedPassword = try password.decrypt()! UIPasteboard.general.string = decryptedPassword.password + let generator = UIImpactFeedbackGenerator(style: .medium) + generator.impactOccurred() + SVProgressHUD.setDefaultMaskType(.clear) + SVProgressHUD.setDefaultStyle(.dark) + SVProgressHUD.showInfo(withStatus: "Password Copied") + SVProgressHUD.dismiss(withDelay: 0.6) } catch { print(error) } diff --git a/pass/SettingsTableViewController.swift b/pass/SettingsTableViewController.swift index 4c13edc..ffa917a 100644 --- a/pass/SettingsTableViewController.swift +++ b/pass/SettingsTableViewController.swift @@ -31,6 +31,7 @@ class SettingsTableViewController: UITableViewController { if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString { SVProgressHUD.setDefaultMaskType(.black) + SVProgressHUD.setDefaultStyle(.light) SVProgressHUD.show(withStatus: "Prepare Repository") var gitCredential: GitCredential if auth == "Password" { @@ -86,6 +87,7 @@ class SettingsTableViewController: UITableViewController { Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text! SVProgressHUD.setDefaultMaskType(.black) + SVProgressHUD.setDefaultStyle(.light) SVProgressHUD.show(withStatus: "Fetching PGP Key") DispatchQueue.global(qos: .userInitiated).async { [unowned self] in do {