Password with "Apple" flavor has a fixed length

This commit is contained in:
Yishi Lin 2017-03-29 00:00:24 +08:00
parent fe4ea4e79c
commit c93a63d8cc
3 changed files with 18 additions and 5 deletions

View file

@ -7,6 +7,8 @@
// //
import UIKit import UIKit
import SwiftyUserDefaults
enum PasswordEditorCellType { enum PasswordEditorCellType {
case textFieldCell, textViewCell, fillPasswordCell, passwordLengthCell, deletePasswordCell case textFieldCell, textViewCell, fillPasswordCell, passwordLengthCell, deletePasswordCell
} }
@ -76,7 +78,12 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
return fillPasswordCell! return fillPasswordCell!
case .passwordLengthCell: case .passwordLengthCell:
passwordLengthCell = tableView.dequeueReusableCell(withIdentifier: "passwordLengthCell", for: indexPath) as? SliderTableViewCell passwordLengthCell = tableView.dequeueReusableCell(withIdentifier: "passwordLengthCell", for: indexPath) as? SliderTableViewCell
passwordLengthCell?.reset(title: "Length", minimumValue: Globals.passwordMinimumLength, maximumValue: Globals.passwordMaximumLength, defaultValue: Globals.passwordDefaultLength) let lengthSetting = Globals.passwordDefaultLength[Defaults[.passwordGeneratorFlavor]] ??
Globals.passwordDefaultLength["Random"]
passwordLengthCell?.reset(title: "Length",
minimumValue: lengthSetting?.min ?? 0,
maximumValue: lengthSetting?.max ?? 0,
defaultValue: lengthSetting?.def ?? 0)
passwordLengthCell?.delegate = self passwordLengthCell?.delegate = self
return passwordLengthCell! return passwordLengthCell!
case .deletePasswordCell: case .deletePasswordCell:
@ -148,7 +155,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
hidePasswordSettings = false hidePasswordSettings = false
tableView.reloadSections([passwordSection], with: .fade) tableView.reloadSections([passwordSection], with: .fade)
} }
let length = passwordLengthCell?.roundedValue ?? Globals.passwordDefaultLength let length = passwordLengthCell?.roundedValue ?? 0
let plainPassword = Utils.generatePassword(length: length) let plainPassword = Utils.generatePassword(length: length)
Utils.copyToPasteboard(textToCopy: plainPassword) Utils.copyToPasteboard(textToCopy: plainPassword)

View file

@ -24,9 +24,8 @@ class Globals {
static let red = UIColor(red:1.00, green:0.23, blue:0.19, alpha:1.0) static let red = UIColor(red:1.00, green:0.23, blue:0.19, alpha:1.0)
static let blue = UIColor(red:0.00, green:0.48, blue:1.00, alpha:1.0) static let blue = UIColor(red:0.00, green:0.48, blue:1.00, alpha:1.0)
static let passwordMinimumLength = 6 static let passwordDefaultLength = ["Random": (min: 6, max: 24, def: 16),
static let passwordMaximumLength = 24 "Apple": (min: 15, max: 15, def: 15)]
static let passwordDefaultLength = 16
static let passwordDots = "••••••••••••" static let passwordDots = "••••••••••••"
static let passwordFonts = "Menlo" static let passwordFonts = "Menlo"

View file

@ -58,6 +58,13 @@ class SliderTableViewCell: ContentTableViewCell {
slider.maximumValue = Float(maximumValue) slider.maximumValue = Float(maximumValue)
slider.value = Float(defaultValue) slider.value = Float(defaultValue)
valueLabel.text = String(defaultValue) valueLabel.text = String(defaultValue)
// "not editable"
if minimumValue == maximumValue {
titleLabel.textColor = UIColor.gray
valueLabel.textColor = UIColor.gray
slider.isUserInteractionEnabled = false
}
} }
} }