simplify alert code
This commit is contained in:
parent
5ed3629c52
commit
edfd8c97a7
7 changed files with 21 additions and 40 deletions
|
|
@ -26,10 +26,9 @@ class EditPasswordTableViewController: PasswordEditorTableViewController {
|
|||
if identifier == "saveEditPasswordSegue" {
|
||||
let nameCell = tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as! ContentTableViewCell
|
||||
if nameCell.getContent() != password?.name {
|
||||
let alertTitle = "Cannot Save Edit"
|
||||
let alertMessage = "Editing name is not supported."
|
||||
let alert = UIAlertController(title: "Cannot Save Edit", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true) {
|
||||
Utils.alert(title: alertTitle, message: alertMessage, controller: self) {
|
||||
nameCell.setContent(content: self.password!.name)
|
||||
}
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -48,9 +48,8 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
|||
|
||||
func tapHideUnknownSwitchDetailButton(_ sender: Any?) {
|
||||
let alertMessage = "Only \"key: value\" format in additional fields is supported. Unsupported fields will be given \"unkown\" keys. Turn on this switch to hide unsupported fields."
|
||||
let alert = UIAlertController(title: "Hide Unknown Fields", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
let alertTitle = "Hide Unknown Fields"
|
||||
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
|
||||
}
|
||||
|
||||
func hideUnknownSwitchAction(_ sender: Any?) {
|
||||
|
|
|
|||
|
|
@ -38,11 +38,7 @@ class GitServerSettingTableViewController: UITableViewController {
|
|||
if authenticationMethod == "SSH Key" {
|
||||
if Defaults[.gitRepositorySSHPublicKeyURL] == nil && Defaults[.gitRepositorySSHPrivateKeyURL] == nil {
|
||||
authenticationMethod = "Password"
|
||||
|
||||
let alertController = UIAlertController(title: "Attention", message: "Please setup SSH key first.", preferredStyle: .alert)
|
||||
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
|
||||
alertController.addAction(defaultAction)
|
||||
present(alertController, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Select SSH Key", message: "Please setup SSH key first.", controller: self, completion: nil)
|
||||
} else {
|
||||
authenticationMethod = "SSH Key"
|
||||
}
|
||||
|
|
@ -65,9 +61,7 @@ class GitServerSettingTableViewController: UITableViewController {
|
|||
if authenticationMethod == nil {
|
||||
alertMessage = "Authentication method is not set. Please set your authentication method first."
|
||||
}
|
||||
let alert = UIAlertController(title: "Cannot Save Settings", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Save Settings", message: alertMessage, controller: self, completion: nil)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,26 +32,17 @@ class PGPKeySettingTableViewController: UITableViewController {
|
|||
}
|
||||
|
||||
guard URL(string: pgpPublicKeyURLTextField.text!) != nil else {
|
||||
let alertMessage = "Please set Public Key URL first."
|
||||
let alert = UIAlertController(title: "Cannot Save", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Save", message: "Please set Public Key URL first.", controller: self, completion: nil)
|
||||
return false
|
||||
}
|
||||
guard URL(string: pgpPrivateKeyURLTextField.text!) != nil else {
|
||||
let alertMessage = "Please set Private Key URL first."
|
||||
let alert = UIAlertController(title: "Cannot Save", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Save", message: "Please set Private Key URL first.", controller: self, completion: nil)
|
||||
return false
|
||||
}
|
||||
|
||||
if URL(string: pgpPublicKeyURLTextField.text!)!.scheme! == "http" &&
|
||||
URL(string: pgpPrivateKeyURLTextField.text!)!.scheme! == "http" {
|
||||
let alertMessage = "HTTP connection is not supported."
|
||||
let alert = UIAlertController(title: "Cannot Save Settings", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Save Settings", message: "HTTP connection is not supported.", controller: self, completion: nil)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,9 +179,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
|||
|
||||
func copyToPasteboard(from indexPath: IndexPath) {
|
||||
if Defaults[.pgpKeyID] == nil {
|
||||
let alert = UIAlertController(title: "Cannot Copy Password", message: "PGP Key is not set. Please set your PGP Key first.", preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Copy Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil)
|
||||
return
|
||||
}
|
||||
let index = sections[indexPath.section].index + indexPath.row
|
||||
|
|
@ -263,9 +261,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
|||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
||||
if identifier == "showPasswordDetail" {
|
||||
if Defaults[.pgpKeyID] == nil {
|
||||
let alert = UIAlertController(title: "Cannot Show Password", message: "PGP Key is not set. Please set your PGP Key first.", preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Show Password", message: "PGP Key is not set. Please set your PGP Key first.", controller: self, completion: nil)
|
||||
if let s = sender as? UITableViewCell {
|
||||
let selectedIndexPath = tableView.indexPath(for: s)!
|
||||
tableView.deselectRow(at: selectedIndexPath, animated: true)
|
||||
|
|
|
|||
|
|
@ -33,17 +33,11 @@ class SSHKeySettingTableViewController: UITableViewController {
|
|||
|
||||
func doneButtonTapped(_ sender: UIButton) {
|
||||
guard URL(string: publicKeyURLTextField.text!) != nil else {
|
||||
let alertMessage = "Please set Public Key URL first."
|
||||
let alert = UIAlertController(title: "Cannot Save", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Save", message: "Please set Public Key URL first.", controller: self, completion: nil)
|
||||
return
|
||||
}
|
||||
guard URL(string: privateKeyURLTextField.text!) != nil else {
|
||||
let alertMessage = "Please set Private Key URL first."
|
||||
let alert = UIAlertController(title: "Cannot Save", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
Utils.alert(title: "Cannot Save", message: "Please set Private Key URL first.", controller: self, completion: nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue