diff --git a/pass/Assets.xcassets/Invisible.imageset/Contents.json b/pass/Assets.xcassets/Invisible.imageset/Contents.json new file mode 100644 index 0000000..be7c464 --- /dev/null +++ b/pass/Assets.xcassets/Invisible.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/pass/Assets.xcassets/Invisible.imageset/Invisible-64.png b/pass/Assets.xcassets/Invisible.imageset/Invisible-64.png new file mode 100644 index 0000000..d5db588 Binary files /dev/null and b/pass/Assets.xcassets/Invisible.imageset/Invisible-64.png differ diff --git a/pass/Assets.xcassets/Invisible.imageset/Invisible-75.png b/pass/Assets.xcassets/Invisible.imageset/Invisible-75.png new file mode 100644 index 0000000..fe3500c Binary files /dev/null and b/pass/Assets.xcassets/Invisible.imageset/Invisible-75.png differ diff --git a/pass/Assets.xcassets/Visible.imageset/Contents.json b/pass/Assets.xcassets/Visible.imageset/Contents.json new file mode 100644 index 0000000..95be3a5 --- /dev/null +++ b/pass/Assets.xcassets/Visible.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/pass/Assets.xcassets/Visible.imageset/Visible-64.png b/pass/Assets.xcassets/Visible.imageset/Visible-64.png new file mode 100644 index 0000000..bfd6f0a Binary files /dev/null and b/pass/Assets.xcassets/Visible.imageset/Visible-64.png differ diff --git a/pass/Assets.xcassets/Visible.imageset/Visible-75.png b/pass/Assets.xcassets/Visible.imageset/Visible-75.png new file mode 100644 index 0000000..144e87d Binary files /dev/null and b/pass/Assets.xcassets/Visible.imageset/Visible-75.png differ diff --git a/pass/Helpers/Globals.swift b/pass/Helpers/Globals.swift index dda0746..069ff6b 100644 --- a/pass/Helpers/Globals.swift +++ b/pass/Helpers/Globals.swift @@ -21,15 +21,17 @@ class Globals { static let repositoryPath = "\(libraryPath)/password-store" 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), "Apple": (min: 15, max: 15, def: 15)] static let passwordDots = "••••••••••••" 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() { } } diff --git a/pass/Views/LabelTableViewCell.swift b/pass/Views/LabelTableViewCell.swift index 726b535..2ffbc5c 100644 --- a/pass/Views/LabelTableViewCell.swift +++ b/pass/Views/LabelTableViewCell.swift @@ -27,6 +27,9 @@ class LabelTableViewCell: UITableViewCell { weak var delegatePasswordTableView : PasswordDetailTableViewController? + var passwordDisplayButton: UIButton? + var buttons: UIView? + var cellData: LabelTableViewCellData? { didSet { titleLabel.text = cellData?.title ?? "" @@ -43,9 +46,11 @@ class LabelTableViewCell: UITableViewCell { } else { contentLabel.text = Globals.passwordDots } + contentLabel.font = UIFont(name: Globals.passwordFonts, size: contentLabel.font.pointSize) } else { contentLabel.text = cellData?.content } + updateButtons() } } @@ -58,6 +63,13 @@ class LabelTableViewCell: UITableViewCell { override func awakeFromNib() { super.awakeFromNib() } + + override func layoutSubviews() { + super.layoutSubviews() + if buttons != nil { + self.accessoryView = buttons + } + } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) @@ -99,13 +111,26 @@ class LabelTableViewCell: UITableViewCell { contentLabel.text = "" } isReveal = true + passwordDisplayButton?.setImage(#imageLiteral(resourceName: "Invisible"), for: .normal) } func concealPassword(_ sender: Any?) { contentLabel.text = Globals.passwordDots 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?) { // if isURLCell, passwordTableView should not be nil delegatePasswordTableView!.openLink() @@ -115,4 +140,41 @@ class LabelTableViewCell: UITableViewCell { // if isHOTPCell, passwordTableView should not be nil 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!) + } + } }