2017-03-09 02:19:47 +08:00
|
|
|
//
|
|
|
|
|
// SliderTableViewCell.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Yishi Lin on 8/3/17.
|
|
|
|
|
// Copyright © 2017 Yishi Lin. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2020-02-28 19:05:23 +01:00
|
|
|
import passKit
|
2017-03-09 02:19:47 +08:00
|
|
|
import UIKit
|
|
|
|
|
|
2020-02-28 19:05:23 +01:00
|
|
|
class SliderTableViewCell: UITableViewCell {
|
|
|
|
|
@IBOutlet var titleLabel: UILabel!
|
|
|
|
|
@IBOutlet var valueLabel: UILabel!
|
|
|
|
|
@IBOutlet var slider: UISlider!
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-02-28 19:05:23 +01:00
|
|
|
private var checker: ((Int) -> Bool)!
|
|
|
|
|
private var updater: ((Int) -> Void)!
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-07-05 23:47:33 +02:00
|
|
|
private weak var delegate: PasswordSettingSliderTableViewCellDelegate!
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBAction
|
2020-07-05 22:49:53 +02:00
|
|
|
private func handleSliderValueChange(_ sender: UISlider) {
|
2017-03-23 01:28:46 +08:00
|
|
|
let newRoundedValue = Int(sender.value)
|
2020-02-28 19:05:23 +01:00
|
|
|
// Proceed only if the rounded value gets updated.
|
|
|
|
|
guard checker(newRoundedValue) else {
|
|
|
|
|
return
|
2017-03-23 01:28:46 +08:00
|
|
|
}
|
|
|
|
|
sender.value = Float(newRoundedValue)
|
|
|
|
|
valueLabel.text = "\(newRoundedValue)"
|
2020-02-28 19:05:23 +01:00
|
|
|
|
|
|
|
|
updater(newRoundedValue)
|
|
|
|
|
delegate.generateAndCopyPassword()
|
2017-03-09 02:19:47 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-02-28 19:05:23 +01:00
|
|
|
func set(title: String) -> SliderTableViewCell {
|
2017-03-09 02:19:47 +08:00
|
|
|
titleLabel.text = title
|
2020-02-28 19:05:23 +01:00
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func configureSlider(with configuration: LengthLimits) -> SliderTableViewCell {
|
|
|
|
|
slider.minimumValue = Float(configuration.min)
|
|
|
|
|
slider.maximumValue = Float(configuration.max)
|
|
|
|
|
return self
|
2017-03-09 02:19:47 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-02-28 19:05:23 +01:00
|
|
|
func set(initialValue: Int) -> SliderTableViewCell {
|
|
|
|
|
slider.value = Float(initialValue)
|
|
|
|
|
valueLabel.text = String(initialValue)
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkNewValue(with checker: @escaping (Int) -> Bool) -> SliderTableViewCell {
|
|
|
|
|
self.checker = checker
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func updateNewValue(using updater: @escaping (Int) -> Void) -> SliderTableViewCell {
|
|
|
|
|
self.updater = updater
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func delegate(to delegate: PasswordSettingSliderTableViewCellDelegate) -> SliderTableViewCell {
|
|
|
|
|
self.delegate = delegate
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension SliderTableViewCell: ContentProvider {
|
2019-01-27 14:26:11 +01:00
|
|
|
func getContent() -> String? {
|
2020-06-28 21:25:40 +02:00
|
|
|
nil
|
2019-01-27 14:26:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-28 19:05:23 +01:00
|
|
|
func setContent(content _: String?) {}
|
2017-03-09 02:19:47 +08:00
|
|
|
}
|