Fix bugs in the password editor
This commit is contained in:
parent
f8f43a1225
commit
3593974ca4
2 changed files with 20 additions and 7 deletions
|
|
@ -88,6 +88,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
case .fillPasswordCell:
|
case .fillPasswordCell:
|
||||||
fillPasswordCell = tableView.dequeueReusableCell(withIdentifier: "fillPasswordCell", for: indexPath) as? FillPasswordTableViewCell
|
fillPasswordCell = tableView.dequeueReusableCell(withIdentifier: "fillPasswordCell", for: indexPath) as? FillPasswordTableViewCell
|
||||||
fillPasswordCell?.delegate = self
|
fillPasswordCell?.delegate = self
|
||||||
|
fillPasswordCell?.contentTextField.delegate = self
|
||||||
fillPasswordCell?.setContent(content: cellData[PasswordEditorCellKey.content] as? String)
|
fillPasswordCell?.setContent(content: cellData[PasswordEditorCellKey.content] as? String)
|
||||||
if tableData[passwordSection].count == 1 {
|
if tableData[passwordSection].count == 1 {
|
||||||
fillPasswordCell?.settingButton.isHidden = true
|
fillPasswordCell?.settingButton.isHidden = true
|
||||||
|
|
@ -97,10 +98,18 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
passwordLengthCell = tableView.dequeueReusableCell(withIdentifier: "passwordLengthCell", for: indexPath) as? SliderTableViewCell
|
passwordLengthCell = tableView.dequeueReusableCell(withIdentifier: "passwordLengthCell", for: indexPath) as? SliderTableViewCell
|
||||||
let lengthSetting = Globals.passwordDefaultLength[SharedDefaults[.passwordGeneratorFlavor]] ??
|
let lengthSetting = Globals.passwordDefaultLength[SharedDefaults[.passwordGeneratorFlavor]] ??
|
||||||
Globals.passwordDefaultLength["Random"]
|
Globals.passwordDefaultLength["Random"]
|
||||||
|
let minimumLength = lengthSetting?.min ?? 0
|
||||||
|
let maximumLength = lengthSetting?.max ?? 0
|
||||||
|
var defaultLength = lengthSetting?.def ?? 0
|
||||||
|
if let currentPasswordLength = (tableData[passwordSection][0][PasswordEditorCellKey.content] as? String)?.characters.count,
|
||||||
|
currentPasswordLength >= minimumLength,
|
||||||
|
currentPasswordLength <= maximumLength {
|
||||||
|
defaultLength = currentPasswordLength
|
||||||
|
}
|
||||||
passwordLengthCell?.reset(title: "Length",
|
passwordLengthCell?.reset(title: "Length",
|
||||||
minimumValue: lengthSetting?.min ?? 0,
|
minimumValue: minimumLength,
|
||||||
maximumValue: lengthSetting?.max ?? 0,
|
maximumValue: maximumLength,
|
||||||
defaultValue: lengthSetting?.def ?? 0)
|
defaultValue: defaultLength)
|
||||||
passwordLengthCell?.delegate = self
|
passwordLengthCell?.delegate = self
|
||||||
return passwordLengthCell!
|
return passwordLengthCell!
|
||||||
case .additionsCell:
|
case .additionsCell:
|
||||||
|
|
@ -234,14 +243,16 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the data table after editing
|
// update tableData so to make sure reloadData() works correctly
|
||||||
func textFieldDidEndEditing(_ textField: UITextField) {
|
func textFieldDidEndEditing(_ textField: UITextField) {
|
||||||
if textField == nameCell?.contentTextField {
|
if textField == nameCell?.contentTextField {
|
||||||
tableData[nameSection][0][PasswordEditorCellKey.content] = nameCell?.getContent()
|
tableData[nameSection][0][PasswordEditorCellKey.content] = nameCell?.getContent()
|
||||||
|
} else if textField == fillPasswordCell?.contentTextField {
|
||||||
|
tableData[passwordSection][0][PasswordEditorCellKey.content] = fillPasswordCell?.getContent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the data table after editing
|
// update tableData so to make sure reloadData() works correctly
|
||||||
func textViewDidEndEditing(_ textView: UITextView) {
|
func textViewDidEndEditing(_ textView: UITextView) {
|
||||||
if textView == additionsCell?.contentTextView {
|
if textView == additionsCell?.contentTextView {
|
||||||
tableData[additionsSection][0][PasswordEditorCellKey.content] = additionsCell?.getContent()
|
tableData[additionsSection][0][PasswordEditorCellKey.content] = additionsCell?.getContent()
|
||||||
|
|
|
||||||
|
|
@ -111,11 +111,13 @@ public class Utils {
|
||||||
// draw all digits in the password into red
|
// draw all digits in the password into red
|
||||||
// draw all punctuation characters in the password into blue
|
// draw all punctuation characters in the password into blue
|
||||||
for (index, element) in plainPassword.unicodeScalars.enumerated() {
|
for (index, element) in plainPassword.unicodeScalars.enumerated() {
|
||||||
|
var charColor = UIColor.darkText
|
||||||
if NSCharacterSet.decimalDigits.contains(element) {
|
if NSCharacterSet.decimalDigits.contains(element) {
|
||||||
attributedPassword.addAttribute(NSForegroundColorAttributeName, value: Globals.red, range: NSRange(location: index, length: 1))
|
charColor = Globals.red
|
||||||
} else if !NSCharacterSet.letters.contains(element) {
|
} else if !NSCharacterSet.letters.contains(element) {
|
||||||
attributedPassword.addAttribute(NSForegroundColorAttributeName, value: Globals.blue, range: NSRange(location: index, length: 1))
|
charColor = Globals.blue
|
||||||
}
|
}
|
||||||
|
attributedPassword.addAttribute(NSForegroundColorAttributeName, value: charColor, range: NSRange(location: index, length: 1))
|
||||||
}
|
}
|
||||||
return attributedPassword
|
return attributedPassword
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue