Recognize *url* as url fields

This commit is contained in:
Yishi Lin 2018-04-04 12:54:35 +08:00
parent b0fda8271c
commit f7eabd8258

View file

@ -39,8 +39,7 @@ class LabelTableViewCell: UITableViewCell {
return return
} }
titleLabel.text = title titleLabel.text = title
switch title.lowercased() { if title.caseInsensitiveCompare("password") == .orderedSame {
case "password":
type = .password type = .password
if isReveal { if isReveal {
contentLabel.attributedText = Utils.attributedPassword(plainPassword: content) contentLabel.attributedText = Utils.attributedPassword(plainPassword: content)
@ -52,7 +51,7 @@ class LabelTableViewCell: UITableViewCell {
} }
} }
contentLabel.font = Globals.passwordFont contentLabel.font = Globals.passwordFont
case "hmac-based": } else if title.caseInsensitiveCompare("hmac-based") == .orderedSame {
type = .HOTP type = .HOTP
if isReveal { if isReveal {
contentLabel.text = content contentLabel.text = content
@ -60,11 +59,12 @@ class LabelTableViewCell: UITableViewCell {
contentLabel.text = Globals.oneTimePasswordDots contentLabel.text = Globals.oneTimePasswordDots
} }
contentLabel.font = Globals.passwordFont contentLabel.font = Globals.passwordFont
case "url": } else if title.lowercased().range(of: "url") != nil || verifyUrl(content) {
type = .URL type = .URL
contentLabel.text = content contentLabel.text = content
contentLabel.font = UIFont.systemFont(ofSize: contentLabel.font.pointSize) contentLabel.font = UIFont.systemFont(ofSize: contentLabel.font.pointSize)
default: } else {
// default
type = .other type = .other
contentLabel.text = content contentLabel.text = content
contentLabel.font = UIFont.systemFont(ofSize: contentLabel.font.pointSize) contentLabel.font = UIFont.systemFont(ofSize: contentLabel.font.pointSize)
@ -198,4 +198,12 @@ class LabelTableViewCell: UITableViewCell {
} }
self.accessoryView = buttons self.accessoryView = buttons
} }
private func verifyUrl(_ urlString: String?) -> Bool {
guard let urlString = urlString,
let _ = URL(string: urlString) else {
return false
}
return true
}
} }