Polish code to make sure detail text in settings are correct

This commit is contained in:
Bob Sun 2017-02-26 20:59:27 +08:00
parent 30ae32ec5f
commit ea3c12f2e4
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -170,21 +170,43 @@ class SettingsTableViewController: UITableViewController {
touchIDSwitch.onTintColor = UIColor(displayP3Red: 0, green: 122.0/255, blue: 1, alpha: 1)
touchIDTableViewCell.accessoryView = touchIDSwitch
touchIDSwitch.addTarget(self, action: #selector(touchIDSwitchAction), for: UIControlEvents.valueChanged)
if Defaults[.pgpKeyID] == "" {
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
} else {
pgpKeyTableViewCell.detailTextLabel?.text = Defaults[.pgpKeyID]
}
if Defaults[.isTouchIDOn] {
touchIDSwitch.isOn = true
} else {
touchIDSwitch.isOn = false
}
setPGPKeyTableViewCellDetailText()
setPasswordRepositoryTableViewCellDetailText()
setTouchIDSwitch()
setPasscodeLockRepositoryTableViewCellDetailText()
}
private func setPasscodeLockRepositoryTableViewCellDetailText() {
if PasscodeLockRepository().hasPasscode {
self.passcodeTableViewCell.detailTextLabel?.text = "On"
} else {
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
touchIDSwitch.isEnabled = false
Globals.passcodeConfiguration.isTouchIDAllowed = false
}
}
private func setPGPKeyTableViewCellDetailText() {
if Defaults[.pgpKeyID] == nil {
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
} else {
pgpKeyTableViewCell.detailTextLabel?.text = Defaults[.pgpKeyID]
}
}
private func setPasswordRepositoryTableViewCellDetailText() {
if Defaults[.gitRepositoryURL] == nil {
passwordRepositoryTableViewCell.detailTextLabel?.text = "Not Set"
} else {
passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryURL]!.host
}
}
private func setTouchIDSwitch() {
if Defaults[.isTouchIDOn] {
touchIDSwitch.isOn = true
} else {
touchIDSwitch.isOn = false
}
}
@ -214,10 +236,10 @@ class SettingsTableViewController: UITableViewController {
}
func actOnPasswordStoreErasedNotification() {
pgpKeyTableViewCell.detailTextLabel?.text = "Not Set"
touchIDSwitch.isOn = false
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
Globals.passcodeConfiguration.isTouchIDAllowed = false
setPGPKeyTableViewCellDetailText()
setPasswordRepositoryTableViewCellDetailText()
setTouchIDSwitch()
setPasscodeLockRepositoryTableViewCellDetailText()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)