From c93a63d8ccbf9ea3c946f3551769d64b6d006aa2 Mon Sep 17 00:00:00 2001 From: Yishi Lin Date: Wed, 29 Mar 2017 00:00:24 +0800 Subject: [PATCH] Password with "Apple" flavor has a fixed length --- .../PasswordEditorTableViewController.swift | 11 +++++++++-- pass/Helpers/Globals.swift | 5 ++--- pass/Views/SliderTableViewCell.swift | 7 +++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pass/Controllers/PasswordEditorTableViewController.swift b/pass/Controllers/PasswordEditorTableViewController.swift index ccd5b03..cdef75f 100644 --- a/pass/Controllers/PasswordEditorTableViewController.swift +++ b/pass/Controllers/PasswordEditorTableViewController.swift @@ -7,6 +7,8 @@ // import UIKit +import SwiftyUserDefaults + enum PasswordEditorCellType { case textFieldCell, textViewCell, fillPasswordCell, passwordLengthCell, deletePasswordCell } @@ -76,7 +78,12 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl return fillPasswordCell! case .passwordLengthCell: 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 return passwordLengthCell! case .deletePasswordCell: @@ -148,7 +155,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl hidePasswordSettings = false tableView.reloadSections([passwordSection], with: .fade) } - let length = passwordLengthCell?.roundedValue ?? Globals.passwordDefaultLength + let length = passwordLengthCell?.roundedValue ?? 0 let plainPassword = Utils.generatePassword(length: length) Utils.copyToPasteboard(textToCopy: plainPassword) diff --git a/pass/Helpers/Globals.swift b/pass/Helpers/Globals.swift index 3959550..dda0746 100644 --- a/pass/Helpers/Globals.swift +++ b/pass/Helpers/Globals.swift @@ -24,9 +24,8 @@ class Globals { 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 passwordMinimumLength = 6 - static let passwordMaximumLength = 24 - static let passwordDefaultLength = 16 + static let passwordDefaultLength = ["Random": (min: 6, max: 24, def: 16), + "Apple": (min: 15, max: 15, def: 15)] static let passwordDots = "••••••••••••" static let passwordFonts = "Menlo" diff --git a/pass/Views/SliderTableViewCell.swift b/pass/Views/SliderTableViewCell.swift index a641c44..cbcdebb 100644 --- a/pass/Views/SliderTableViewCell.swift +++ b/pass/Views/SliderTableViewCell.swift @@ -58,6 +58,13 @@ class SliderTableViewCell: ContentTableViewCell { slider.maximumValue = Float(maximumValue) slider.value = Float(defaultValue) valueLabel.text = String(defaultValue) + + // "not editable" + if minimumValue == maximumValue { + titleLabel.textColor = UIColor.gray + valueLabel.textColor = UIColor.gray + slider.isUserInteractionEnabled = false + } } }