Add buttons in the detail password table

- An icon to show/hide passwords
- An icon to refresh HOTP passwords
This commit is contained in:
Yishi Lin 2017-03-31 03:08:20 +08:00
parent abce9d7be5
commit abb04432fb
8 changed files with 111 additions and 3 deletions

View file

@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Invisible-64.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Invisible-75.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Visible-64.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Visible-75.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -21,15 +21,17 @@ class Globals {
static let repositoryPath = "\(libraryPath)/password-store" static let repositoryPath = "\(libraryPath)/password-store"
static var passcodeConfiguration = PasscodeLockConfiguration() static var passcodeConfiguration = PasscodeLockConfiguration()
static let red = UIColor(red:1.00, green:0.23, blue:0.19, alpha:1.0)
static let blue = UIColor(red:0.00, green:0.48, blue:1.00, alpha:1.0)
static let passwordDefaultLength = ["Random": (min: 6, max: 24, def: 16), static let passwordDefaultLength = ["Random": (min: 6, max: 24, def: 16),
"Apple": (min: 15, max: 15, def: 15)] "Apple": (min: 15, max: 15, def: 15)]
static let passwordDots = "••••••••••••" static let passwordDots = "••••••••••••"
static let passwordFonts = "Menlo" static let passwordFonts = "Menlo"
// UI related
static let red = UIColor(red:1.00, green:0.23, blue:0.19, alpha:1.0)
static let blue = UIColor(red:0.00, green:0.48, blue:1.00, alpha:1.0)
static let tableCellButtonSize = CGFloat(20.0)
private init() { } private init() { }
} }

View file

@ -27,6 +27,9 @@ class LabelTableViewCell: UITableViewCell {
weak var delegatePasswordTableView : PasswordDetailTableViewController? weak var delegatePasswordTableView : PasswordDetailTableViewController?
var passwordDisplayButton: UIButton?
var buttons: UIView?
var cellData: LabelTableViewCellData? { var cellData: LabelTableViewCellData? {
didSet { didSet {
titleLabel.text = cellData?.title ?? "" titleLabel.text = cellData?.title ?? ""
@ -43,9 +46,11 @@ class LabelTableViewCell: UITableViewCell {
} else { } else {
contentLabel.text = Globals.passwordDots contentLabel.text = Globals.passwordDots
} }
contentLabel.font = UIFont(name: Globals.passwordFonts, size: contentLabel.font.pointSize)
} else { } else {
contentLabel.text = cellData?.content contentLabel.text = cellData?.content
} }
updateButtons()
} }
} }
@ -58,6 +63,13 @@ class LabelTableViewCell: UITableViewCell {
override func awakeFromNib() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
} }
override func layoutSubviews() {
super.layoutSubviews()
if buttons != nil {
self.accessoryView = buttons
}
}
override func setSelected(_ selected: Bool, animated: Bool) { override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated) super.setSelected(selected, animated: animated)
@ -99,13 +111,26 @@ class LabelTableViewCell: UITableViewCell {
contentLabel.text = "" contentLabel.text = ""
} }
isReveal = true isReveal = true
passwordDisplayButton?.setImage(#imageLiteral(resourceName: "Invisible"), for: .normal)
} }
func concealPassword(_ sender: Any?) { func concealPassword(_ sender: Any?) {
contentLabel.text = Globals.passwordDots contentLabel.text = Globals.passwordDots
isReveal = false isReveal = false
passwordDisplayButton?.setImage(#imageLiteral(resourceName: "Visible"), for: .normal)
} }
func reversePasswordDisplay(_ sender: Any?) {
if isReveal {
// conceal
concealPassword(sender)
} else {
// reveal
revealPassword(sender)
}
}
func openLink(_ sender: Any?) { func openLink(_ sender: Any?) {
// if isURLCell, passwordTableView should not be nil // if isURLCell, passwordTableView should not be nil
delegatePasswordTableView!.openLink() delegatePasswordTableView!.openLink()
@ -115,4 +140,41 @@ class LabelTableViewCell: UITableViewCell {
// if isHOTPCell, passwordTableView should not be nil // if isHOTPCell, passwordTableView should not be nil
delegatePasswordTableView!.getNextHOTP() delegatePasswordTableView!.getNextHOTP()
} }
func updateButtons() {
passwordDisplayButton = nil
buttons = nil
if isPasswordCell {
// password button
passwordDisplayButton = UIButton(type: .system)
passwordDisplayButton!.frame = CGRect(x: 0, y: 0, width: Globals.tableCellButtonSize, height: Globals.tableCellButtonSize)
passwordDisplayButton!.setImage(#imageLiteral(resourceName: "Visible"), for: .normal)
passwordDisplayButton!.imageView?.contentMode = .scaleAspectFit
passwordDisplayButton!.addTarget(self, action: #selector(reversePasswordDisplay), for: UIControlEvents.touchUpInside)
buttons = passwordDisplayButton
} else if isHOTPCell {
let spacing = CGFloat(10.0)
// hotp button
let nextButton = UIButton(type: .system)
nextButton.frame = CGRect(x: 0, y: 0,
width: Globals.tableCellButtonSize, height: Globals.tableCellButtonSize)
nextButton.setImage(#imageLiteral(resourceName: "Refresh"), for: .normal)
nextButton.imageView?.contentMode = .scaleAspectFit
nextButton.addTarget(self, action: #selector(getNextHOTP), for: UIControlEvents.touchUpInside)
// password button
passwordDisplayButton = UIButton(type: .system)
passwordDisplayButton!.frame = CGRect(x: Globals.tableCellButtonSize + spacing, y: 0,
width: Globals.tableCellButtonSize, height: Globals.tableCellButtonSize)
passwordDisplayButton!.setImage(#imageLiteral(resourceName: "Visible"), for: .normal)
passwordDisplayButton!.imageView?.contentMode = .scaleAspectFit
passwordDisplayButton!.addTarget(self, action: #selector(reversePasswordDisplay), for: UIControlEvents.touchUpInside)
buttons = UIView()
buttons!.frame = CGRect(x: 0, y: 0, width: Globals.tableCellButtonSize * 2 + spacing, height: Globals.tableCellButtonSize)
buttons!.addSubview(nextButton)
buttons!.addSubview(passwordDisplayButton!)
}
}
} }