Refactor core data classes (#671)
This commit is contained in:
parent
ab453580ad
commit
d1de81d919
24 changed files with 605 additions and 433 deletions
|
|
@ -43,8 +43,8 @@ class AddPasswordTableViewController: PasswordEditorTableViewController {
|
|||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
super.prepare(for: segue, sender: sender)
|
||||
if segue.identifier == "saveAddPasswordSegue" {
|
||||
let (name, url) = getNameURL()
|
||||
password = Password(name: name, url: url, plainText: plainText)
|
||||
let (name, path) = getNamePath()
|
||||
password = Password(name: name, path: path, plainText: plainText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ class EditPasswordTableViewController: PasswordEditorTableViewController {
|
|||
super.prepare(for: segue, sender: sender)
|
||||
if segue.identifier == "saveEditPasswordSegue" {
|
||||
let editedPlainText = plainText
|
||||
let (name, url) = getNameURL()
|
||||
if password!.plainText != editedPlainText || password!.url.path != url.path {
|
||||
password!.updatePassword(name: name, url: url, plainText: editedPlainText)
|
||||
let (name, path) = getNamePath()
|
||||
if password!.plainText != editedPlainText || password!.path != path {
|
||||
password!.updatePassword(name: name, path: path, plainText: editedPlainText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
navigationItem.rightBarButtonItem = editUIBarButtonItem
|
||||
navigationItem.largeTitleDisplayMode = .never
|
||||
|
||||
if let imageData = passwordEntity?.getImage() {
|
||||
if let imageData = passwordEntity?.image {
|
||||
let image = UIImage(data: imageData as Data)
|
||||
passwordImage = image
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
self?.editUIBarButtonItem.isEnabled = true
|
||||
if !Defaults.isHidePasswordImagesOn {
|
||||
if let urlString = self?.password?.urlString {
|
||||
if self?.passwordEntity?.getImage() == nil {
|
||||
if self?.passwordEntity?.image == nil {
|
||||
self?.updatePasswordImage(urlString: urlString)
|
||||
}
|
||||
}
|
||||
|
|
@ -337,7 +337,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
self?.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.automatic)
|
||||
let imageData = image.jpegData(compressionQuality: 1)
|
||||
if let entity = self?.passwordEntity {
|
||||
self?.passwordStore.updateImage(passwordEntity: entity, image: imageData)
|
||||
entity.image = imageData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -443,13 +443,13 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
cell.labelImageConstraint.isActive = false
|
||||
cell.labelCellConstraint.isActive = true
|
||||
}
|
||||
let passwordName = passwordEntity!.getName()
|
||||
if passwordEntity!.synced == false {
|
||||
let passwordName = passwordEntity!.name
|
||||
if passwordEntity!.isSynced == false {
|
||||
cell.nameLabel.text = "\(passwordName) ↻"
|
||||
} else {
|
||||
cell.nameLabel.text = passwordName
|
||||
}
|
||||
cell.categoryLabel.text = passwordEntity!.getCategoryText()
|
||||
cell.categoryLabel.text = passwordEntity!.dirText
|
||||
cell.selectionStyle = .none
|
||||
return cell
|
||||
case .addition, .main:
|
||||
|
|
@ -504,7 +504,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
footerLabel.numberOfLines = 0
|
||||
footerLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
|
||||
footerLabel.textColor = UIColor.gray
|
||||
let dateString = passwordStore.getLatestUpdateInfo(filename: password!.url.path)
|
||||
let dateString = passwordStore.getLatestUpdateInfo(path: password!.path)
|
||||
footerLabel.text = "LastUpdated".localize(dateString)
|
||||
view.addSubview(footerLabel)
|
||||
return view
|
||||
|
|
@ -593,7 +593,7 @@ extension PasswordDetailTableViewController {
|
|||
handleError(error: AppError.other(message: "PasswordDoesNotExist"))
|
||||
return
|
||||
}
|
||||
let encryptedDataPath = PasswordStore.shared.storeURL.appendingPathComponent(passwordEntity.getPath())
|
||||
let encryptedDataPath = PasswordStore.shared.storeURL.appendingPathComponent(passwordEntity.path)
|
||||
|
||||
guard let encryptedData = try? Data(contentsOf: encryptedDataPath) else {
|
||||
handleError(error: AppError.other(message: "PasswordDoesNotExist"))
|
||||
|
|
@ -606,9 +606,7 @@ extension PasswordDetailTableViewController {
|
|||
guard let decryptedDataString = String(data: decryptedData, encoding: .utf8) else {
|
||||
throw AppError.yubiKey(.decipher(message: "Failed to convert plaintext to string."))
|
||||
}
|
||||
guard let password = try? Password(name: passwordEntity.getName(), url: passwordEntity.getURL(), plainText: decryptedDataString) else {
|
||||
throw AppError.yubiKey(.decipher(message: "Failed to construct password."))
|
||||
}
|
||||
password = Password(name: passwordEntity.name, path: passwordEntity.path, plainText: decryptedDataString)
|
||||
self.password = password
|
||||
self.showPassword()
|
||||
} catch let error as AppError {
|
||||
|
|
|
|||
|
|
@ -351,11 +351,13 @@ class PasswordEditorTableViewController: UITableViewController {
|
|||
}
|
||||
}
|
||||
|
||||
func getNameURL() -> (String, URL) {
|
||||
let encodedName = (nameCell?.getContent()?.stringByAddingPercentEncodingForRFC3986())!
|
||||
let name = URL(string: encodedName)!.lastPathComponent
|
||||
let url = URL(string: encodedName)!.appendingPathExtension("gpg")
|
||||
return (name, url)
|
||||
func getNamePath() -> (String, String) {
|
||||
guard let encodedName = nameCell?.getContent()?.stringByAddingPercentEncodingForRFC3986(), let url = URL(string: encodedName) else {
|
||||
return ("", "")
|
||||
}
|
||||
let name = url.lastPathComponent
|
||||
let path = url.appendingPathExtension("gpg").path
|
||||
return (name, path)
|
||||
}
|
||||
|
||||
func checkName() -> Bool {
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ class PasswordNavigationViewController: UIViewController {
|
|||
navigationItem.title = "PasswordStore".localize()
|
||||
} else {
|
||||
navigationItem.largeTitleDisplayMode = .never
|
||||
navigationItem.title = parentPasswordEntity?.getName()
|
||||
navigationItem.title = parentPasswordEntity?.name
|
||||
}
|
||||
if viewingUnsyncedPasswords {
|
||||
navigationItem.title = "Unsynced"
|
||||
|
|
@ -261,7 +261,7 @@ class PasswordNavigationViewController: UIViewController {
|
|||
if passwordTableEntry.isDir {
|
||||
return
|
||||
}
|
||||
passwordManager.providePasswordPasteboard(with: passwordTableEntry.passwordEntity.getPath())
|
||||
passwordManager.providePasswordPasteboard(with: passwordTableEntry.passwordEntity.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -335,7 +335,7 @@ extension PasswordNavigationViewController {
|
|||
} else if segue.identifier == "addPasswordSegue" {
|
||||
if let navController = segue.destination as? UINavigationController,
|
||||
let viewController = navController.topViewController as? AddPasswordTableViewController,
|
||||
let path = parentPasswordEntity?.getPath() {
|
||||
let path = parentPasswordEntity?.path {
|
||||
viewController.defaultDirPrefix = "\(path)/"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue