Set name and url in Password non-optional
Name and url in Password class shouldn't be optional because we store them in core data as non-optional. This change also help us to avoid man unneccessary unwrap.
This commit is contained in:
parent
5262ca89f7
commit
2abbceb2e9
9 changed files with 60 additions and 39 deletions
|
|
@ -45,7 +45,7 @@ class EditPasswordTableViewController: PasswordEditorTableViewController {
|
|||
plainText.append(additionsString)
|
||||
}
|
||||
let (name, url) = getNameURL()
|
||||
if password!.plainText != plainText || password!.url!.path != url.path {
|
||||
if password!.plainText != plainText || password!.url.path != url.path {
|
||||
password!.updatePassword(name: name, url: url, plainText: plainText)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ class OTPScannerController: QRScannerController {
|
|||
|
||||
private func presentSaveAlert() {
|
||||
// initialize alert
|
||||
let password = Password(name: "empty", url: nil, plainText: scannedOTP!)
|
||||
// XXX: use Password class for now, we need to come up a better structure to oranize this
|
||||
let password = Password(name: "empty", url: URL(string: ".")!, plainText: scannedOTP!)
|
||||
let (title, content) = password.getOtpStrings()!
|
||||
let alert = UIAlertController(title: "Success", message: "\(title): \(content)", preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "Save", style: UIAlertActionStyle.default, handler: {[unowned self] (action) -> Void in
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
navigationItem.largeTitleDisplayMode = .never
|
||||
}
|
||||
|
||||
if let imageData = passwordEntity?.image {
|
||||
if let imageData = passwordEntity?.getImage() {
|
||||
let image = UIImage(data: imageData as Data)
|
||||
passwordImage = image
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
}
|
||||
|
||||
@objc private func decryptThenShowPassword() {
|
||||
guard let passwordEntity = passwordEntity, passwordEntity.path != nil else {
|
||||
guard let passwordEntity = passwordEntity else {
|
||||
Utils.alert(title: "Cannot Show Password", message: "The password does not exist.", controller: self, handler: {(UIAlertAction) -> Void in
|
||||
self.navigationController!.popViewController(animated: true)
|
||||
})
|
||||
|
|
@ -173,7 +173,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
self?.tableView.reloadData()
|
||||
self?.editUIBarButtonItem.isEnabled = true
|
||||
if let urlString = self?.password?.urlString {
|
||||
if self?.passwordEntity?.image == nil {
|
||||
if self?.passwordEntity?.getImage() == nil {
|
||||
self?.updatePasswordImage(urlString: urlString)
|
||||
}
|
||||
}
|
||||
|
|
@ -431,12 +431,11 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
case .name:
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "passwordDetailTitleTableViewCell", for: indexPath) as! PasswordDetailTitleTableViewCell
|
||||
cell.passwordImageImageView.image = passwordImage ?? #imageLiteral(resourceName: "PasswordImagePlaceHolder")
|
||||
if let passwordName = passwordEntity!.name {
|
||||
if passwordEntity!.synced == false {
|
||||
cell.nameLabel.text = "\(passwordName) ↻"
|
||||
} else {
|
||||
cell.nameLabel.text = passwordName
|
||||
}
|
||||
let passwordName = passwordEntity!.getName()
|
||||
if passwordEntity!.synced == false {
|
||||
cell.nameLabel.text = "\(passwordName) ↻"
|
||||
} else {
|
||||
cell.nameLabel.text = passwordName
|
||||
}
|
||||
cell.categoryLabel.text = passwordEntity!.getCategoryText()
|
||||
cell.selectionStyle = .none
|
||||
|
|
@ -468,7 +467,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
footerLabel.numberOfLines = 0
|
||||
footerLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
|
||||
footerLabel.textColor = UIColor.gray
|
||||
let dateString = self.passwordStore.getLatestUpdateInfo(filename: password!.url!.path)
|
||||
let dateString = self.passwordStore.getLatestUpdateInfo(filename: password!.url.path)
|
||||
footerLabel.text = "Last Updated: \(dateString)"
|
||||
view.addSubview(footerLabel)
|
||||
return view
|
||||
|
|
|
|||
|
|
@ -481,7 +481,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
|||
} else if segue.identifier == "addPasswordSegue" {
|
||||
if let navController = segue.destination as? UINavigationController {
|
||||
if let viewController = navController.topViewController as? AddPasswordTableViewController {
|
||||
if let path = parentPasswordEntity?.path {
|
||||
if let path = parentPasswordEntity?.getPath() {
|
||||
viewController.defaultDirPrefix = "\(path)/"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue