Improve the password length slider
- the slider appears after clicking "generate" - the slider goes away after clicking a non-password-related section - generate new password if the slider value changes
This commit is contained in:
parent
e4e20b1d6f
commit
5a02cb726e
6 changed files with 75 additions and 25 deletions
|
|
@ -9,7 +9,7 @@
|
|||
import UIKit
|
||||
|
||||
protocol FillPasswordTableViewCellDelegate {
|
||||
func generatePassword() -> String
|
||||
func generateAndCopyPassword()
|
||||
}
|
||||
|
||||
class FillPasswordTableViewCell: ContentTableViewCell {
|
||||
|
|
@ -30,9 +30,7 @@ class FillPasswordTableViewCell: ContentTableViewCell {
|
|||
}
|
||||
|
||||
@IBAction func generatePassword(_ sender: UIButton) {
|
||||
let plainPassword = self.delegate?.generatePassword() ?? Utils.generatePassword(length: 16)
|
||||
self.setContent(content: plainPassword)
|
||||
Utils.copyToPasteboard(textToCopy: plainPassword)
|
||||
self.delegate?.generateAndCopyPassword()
|
||||
}
|
||||
|
||||
override func getContent() -> String? {
|
||||
|
|
|
|||
|
|
@ -9,15 +9,21 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
protocol PasswordSettingSliderTableViewCellDelegate {
|
||||
func generateAndCopyPassword()
|
||||
}
|
||||
|
||||
class SliderTableViewCell: ContentTableViewCell {
|
||||
|
||||
@IBOutlet weak var titleLabel: UILabel!
|
||||
@IBOutlet weak var valueLabel: UILabel!
|
||||
@IBOutlet weak var slider: UISlider!
|
||||
|
||||
var delegate: UITableViewController?
|
||||
|
||||
var roundedValue: Int {
|
||||
get {
|
||||
return Int(slider.value)
|
||||
return Int(valueLabel.text!)!
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,9 +39,17 @@ class SliderTableViewCell: ContentTableViewCell {
|
|||
}
|
||||
|
||||
@IBAction func handleSliderValueChange(_ sender: UISlider) {
|
||||
let roundedValue = round(sender.value)
|
||||
sender.value = roundedValue
|
||||
valueLabel.text = "\(Int(roundedValue))"
|
||||
let oldRoundedValue = self.roundedValue
|
||||
let newRoundedValue = Int(sender.value)
|
||||
// proceed only when the rounded value gets updated
|
||||
guard newRoundedValue != oldRoundedValue else {
|
||||
return;
|
||||
}
|
||||
sender.value = Float(newRoundedValue)
|
||||
valueLabel.text = "\(newRoundedValue)"
|
||||
if let delegate: PasswordSettingSliderTableViewCellDelegate = self.delegate as? PasswordSettingSliderTableViewCellDelegate {
|
||||
delegate.generateAndCopyPassword()
|
||||
}
|
||||
}
|
||||
|
||||
func reset(title: String, minimumValue: Int, maximumValue: Int, defaultValue: Int) {
|
||||
|
|
|
|||
|
|
@ -13,20 +13,20 @@
|
|||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="71" id="KGk-i7-Jjw" customClass="SliderTableViewCell" customModule="pass" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="71"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="74"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="70.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="73.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="MwT-Jl-hhE">
|
||||
<rect key="frame" x="60.5" y="20.5" width="205.5" height="31"/>
|
||||
<rect key="frame" x="60.5" y="22" width="205.5" height="31"/>
|
||||
<connections>
|
||||
<action selector="handleSliderValueChange:" destination="KGk-i7-Jjw" eventType="valueChanged" id="WwM-ZE-yIB"/>
|
||||
</connections>
|
||||
</slider>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="88" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GJP-Fj-VZt" userLabel="Value">
|
||||
<rect key="frame" x="281" y="8" width="24" height="54.5"/>
|
||||
<rect key="frame" x="281" y="8" width="24" height="57.5"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="24" id="tOG-yp-eFw"/>
|
||||
</constraints>
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="t7T-HC-hUd" userLabel="Title">
|
||||
<rect key="frame" x="15" y="8" width="30" height="54.5"/>
|
||||
<rect key="frame" x="15" y="8" width="30" height="57.5"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="38" id="8Tz-Qo-Mkg"/>
|
||||
</constraints>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue