From f86a5eee65f7e8d875d2bc6fb247603f0ea773bd Mon Sep 17 00:00:00 2001 From: Yishi Lin Date: Thu, 27 Jul 2017 22:38:07 +0800 Subject: [PATCH] Simplify codes --- .../Controllers/PasswordsViewController.swift | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/pass/Controllers/PasswordsViewController.swift b/pass/Controllers/PasswordsViewController.swift index 5fa05b4..6b35047 100644 --- a/pass/Controllers/PasswordsViewController.swift +++ b/pass/Controllers/PasswordsViewController.swift @@ -306,7 +306,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV if gesture.state == UIGestureRecognizerState.began { let touchPoint = gesture.location(in: tableView) if let indexPath = tableView.indexPathForRow(at: touchPoint) { - copyToPasteboard(from: indexPath) + decryptThenCopyPassword(from: indexPath) } } } @@ -324,21 +324,9 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV } func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { - copyToPasteboard(from: indexPath) + decryptThenCopyPassword(from: indexPath) } - private func copyToPasteboard(from indexPath: IndexPath) { - guard self.passwordStore.privateKey != nil else { - Utils.alert(title: "Cannot Copy Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil) - return - } - let password = getPasswordEntry(by: indexPath).passwordEntity! - UIImpactFeedbackGenerator(style: .medium).impactOccurred() - decryptThenCopyPassword(passwordEntity: password) - } - - - private func requestPGPKeyPassphrase() -> String { let sem = DispatchSemaphore(value: 0) var passphrase = "" @@ -367,7 +355,13 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV return passphrase } - private func decryptThenCopyPassword(passwordEntity: PasswordEntity) { + private func decryptThenCopyPassword(from indexPath: IndexPath) { + guard self.passwordStore.privateKey != nil else { + Utils.alert(title: "Cannot Copy Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil) + return + } + let passwordEntity = getPasswordEntry(by: indexPath).passwordEntity! + UIImpactFeedbackGenerator(style: .medium).impactOccurred() SVProgressHUD.setDefaultMaskType(.black) SVProgressHUD.setDefaultStyle(.dark) SVProgressHUD.show(withStatus: "Decrypting")