2020-02-28 19:05:23 +01:00
|
|
|
//
|
|
|
|
|
// SwitchTableViewCell.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Danny Moesch on 28.02.20.
|
|
|
|
|
// Copyright © 2020 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import passKit
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
|
|
class SwitchTableViewCell: UITableViewCell {
|
|
|
|
|
@IBOutlet var titleLabel: UILabel!
|
|
|
|
|
@IBOutlet var controlSwitch: UISwitch!
|
|
|
|
|
|
|
|
|
|
private var updater: ((Bool) -> Void)!
|
|
|
|
|
|
2020-07-05 23:47:33 +02:00
|
|
|
private weak var delegate: PasswordSettingSliderTableViewCellDelegate!
|
2020-02-28 19:05:23 +01:00
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBAction
|
2020-07-05 22:49:53 +02:00
|
|
|
private func switchValueChanged(_: Any) {
|
2020-02-28 19:05:23 +01:00
|
|
|
updater(controlSwitch.isOn)
|
|
|
|
|
delegate.generateAndCopyPassword()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func set(title: String) -> SwitchTableViewCell {
|
|
|
|
|
titleLabel.text = title
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-12 21:30:31 -07:00
|
|
|
override func layoutMarginsDidChange() {
|
|
|
|
|
layoutMargins.left = passKit.Globals.passwordGeneratorLeftLayoutMargin
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 19:05:23 +01:00
|
|
|
func set(initialValue: Bool) -> SwitchTableViewCell {
|
|
|
|
|
controlSwitch.isOn = initialValue
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func updateNewValue(using updater: @escaping (Bool) -> Void) -> SwitchTableViewCell {
|
|
|
|
|
self.updater = updater
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func delegate(to delegate: PasswordSettingSliderTableViewCellDelegate) -> SwitchTableViewCell {
|
|
|
|
|
self.delegate = delegate
|
|
|
|
|
return self
|
|
|
|
|
}
|
|
|
|
|
}
|