long press to copy password

This commit is contained in:
Bob Sun 2017-02-08 01:29:00 +08:00
parent 3720eab6b5
commit 825cd5446d
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
2 changed files with 26 additions and 1 deletions

View file

@ -28,6 +28,8 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
@IBOutlet weak var tableView: UITableView! @IBOutlet weak var tableView: UITableView!
func syncPasswords() { func syncPasswords() {
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
SVProgressHUD.show(withStatus: "Sync Password Store") SVProgressHUD.show(withStatus: "Sync Password Store")
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
do { do {
@ -110,9 +112,21 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
password = passwordEntities![index] password = passwordEntities![index]
} }
cell.textLabel?.text = password.name cell.textLabel?.text = password.name
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:)))
longPressGestureRecognizer.minimumPressDuration = 1.0
cell.addGestureRecognizer(longPressGestureRecognizer)
return cell 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? { func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section].title return sections[section].title
} }
@ -125,8 +139,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
return index return index
} }
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
copyToPasteboard(from: indexPath)
}
func copyToPasteboard(from indexPath: IndexPath) {
let index = sections[indexPath.section].index + indexPath.row let index = sections[indexPath.section].index + indexPath.row
let password: PasswordEntity let password: PasswordEntity
if searchController.isActive && searchController.searchBar.text != "" { if searchController.isActive && searchController.searchBar.text != "" {
@ -137,6 +154,12 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
do { do {
let decryptedPassword = try password.decrypt()! let decryptedPassword = try password.decrypt()!
UIPasteboard.general.string = decryptedPassword.password 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 { } catch {
print(error) print(error)
} }

View file

@ -31,6 +31,7 @@ class SettingsTableViewController: UITableViewController {
if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString { if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString {
SVProgressHUD.setDefaultMaskType(.black) SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
SVProgressHUD.show(withStatus: "Prepare Repository") SVProgressHUD.show(withStatus: "Prepare Repository")
var gitCredential: GitCredential var gitCredential: GitCredential
if auth == "Password" { if auth == "Password" {
@ -86,6 +87,7 @@ class SettingsTableViewController: UITableViewController {
Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text! Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text!
SVProgressHUD.setDefaultMaskType(.black) SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.setDefaultStyle(.light)
SVProgressHUD.show(withStatus: "Fetching PGP Key") SVProgressHUD.show(withStatus: "Fetching PGP Key")
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
do { do {