2017-02-11 21:37:22 +08:00
|
|
|
//
|
|
|
|
|
// FillPasswordTableViewCell.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 11/2/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2020-06-28 21:25:40 +02:00
|
|
|
import UIKit
|
2017-02-11 21:37:22 +08:00
|
|
|
|
2020-07-04 21:54:02 +02:00
|
|
|
protocol FillPasswordTableViewCellDelegate: AnyObject {
|
2017-03-23 01:28:46 +08:00
|
|
|
func generateAndCopyPassword()
|
2017-03-30 01:17:22 +08:00
|
|
|
func showHidePasswordSettings()
|
2017-03-09 02:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 14:26:11 +01:00
|
|
|
class FillPasswordTableViewCell: UITableViewCell, ContentProvider {
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBOutlet var contentTextField: UITextField!
|
|
|
|
|
@IBOutlet var settingButton: UIButton!
|
|
|
|
|
@IBOutlet var generateButton: UIButton!
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-07-05 23:47:33 +02:00
|
|
|
weak var delegate: FillPasswordTableViewCellDelegate?
|
|
|
|
|
|
2017-02-11 21:37:22 +08:00
|
|
|
override func awakeFromNib() {
|
|
|
|
|
super.awakeFromNib()
|
|
|
|
|
// Initialization code
|
2017-10-07 23:05:26 -07:00
|
|
|
contentTextField.font = Globals.passwordFont
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-30 01:17:22 +08:00
|
|
|
// Force aspect ratio of button images
|
|
|
|
|
settingButton.imageView?.contentMode = .scaleAspectFit
|
|
|
|
|
generateButton.imageView?.contentMode = .scaleAspectFit
|
2017-02-11 21:37:22 +08:00
|
|
|
}
|
|
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBAction
|
2020-07-05 22:49:53 +02:00
|
|
|
private func generatePassword(_: UIButton) {
|
2020-06-28 21:25:40 +02:00
|
|
|
delegate?.generateAndCopyPassword()
|
2017-02-11 21:37:22 +08:00
|
|
|
}
|
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 showHidePasswordSettings() {
|
2020-06-28 21:25:40 +02:00
|
|
|
delegate?.showHidePasswordSettings()
|
2017-03-30 01:17:22 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2017-03-24 01:34:45 +08:00
|
|
|
// re-color
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBAction
|
2020-07-05 22:49:53 +02:00
|
|
|
private func textFieldDidChange(_ sender: UITextField) {
|
2017-03-24 01:34:45 +08:00
|
|
|
contentTextField.attributedText = Utils.attributedPassword(plainPassword: sender.text ?? "")
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2019-01-27 14:26:11 +01:00
|
|
|
func getContent() -> String? {
|
2020-06-28 21:25:40 +02:00
|
|
|
contentTextField.attributedText?.string
|
2017-02-13 01:15:42 +08:00
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2019-01-27 14:26:11 +01:00
|
|
|
func setContent(content: String?) {
|
2017-03-21 13:16:25 -07:00
|
|
|
contentTextField.attributedText = Utils.attributedPassword(plainPassword: content ?? "")
|
2017-02-13 01:15:42 +08:00
|
|
|
}
|
2017-02-11 21:37:22 +08:00
|
|
|
}
|