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.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
2017-03-09 02:19:47 +08:00
|
|
|
protocol FillPasswordTableViewCellDelegate {
|
|
|
|
|
func generatePassword() -> String
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 01:15:42 +08:00
|
|
|
class FillPasswordTableViewCell: ContentTableViewCell {
|
2017-02-11 21:37:22 +08:00
|
|
|
|
|
|
|
|
@IBOutlet weak var contentTextField: UITextField!
|
2017-03-09 02:19:47 +08:00
|
|
|
var delegate: FillPasswordTableViewCellDelegate?
|
|
|
|
|
|
2017-02-11 21:37:22 +08:00
|
|
|
override func awakeFromNib() {
|
|
|
|
|
super.awakeFromNib()
|
|
|
|
|
// Initialization code
|
2017-03-22 01:57:51 +08:00
|
|
|
contentTextField.font = UIFont(name: Globals.passwordFonts, size: (contentTextField.font?.pointSize)!)
|
2017-02-11 21:37:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func setSelected(_ selected: Bool, animated: Bool) {
|
|
|
|
|
super.setSelected(selected, animated: animated)
|
|
|
|
|
|
|
|
|
|
// Configure the view for the selected state
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func generatePassword(_ sender: UIButton) {
|
2017-03-09 02:19:47 +08:00
|
|
|
let plainPassword = self.delegate?.generatePassword() ?? Utils.generatePassword(length: 16)
|
2017-03-22 01:57:51 +08:00
|
|
|
self.setContent(content: plainPassword)
|
2017-02-28 10:28:14 +08:00
|
|
|
Utils.copyToPasteboard(textToCopy: plainPassword)
|
2017-02-11 21:37:22 +08:00
|
|
|
}
|
2017-02-13 01:15:42 +08:00
|
|
|
|
|
|
|
|
override func getContent() -> String? {
|
2017-02-26 00:58:18 +08:00
|
|
|
return contentTextField.attributedText?.string
|
2017-02-13 01:15:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func setContent(content: String) {
|
2017-02-26 00:58:18 +08:00
|
|
|
contentTextField.attributedText = Utils.attributedPassword(plainPassword: content)
|
2017-02-13 01:15:42 +08:00
|
|
|
}
|
2017-02-11 21:37:22 +08:00
|
|
|
}
|