Show number of hidden fields in password view

This commit is contained in:
Danny Moesch 2018-12-08 00:57:54 +01:00 committed by Bob Sun
parent 68dd60fb8e
commit 5780a439db
2 changed files with 27 additions and 1 deletions

View file

@ -441,13 +441,31 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
cell.selectionStyle = .none cell.selectionStyle = .none
return cell return cell
case .misc: case .misc:
let cell = UITableViewCell() let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
cell.textLabel?.text = tableDataItem.title cell.textLabel?.text = tableDataItem.title
cell.selectionStyle = .default cell.selectionStyle = .default
addHiddenFieldInformation(to: cell)
return cell return cell
} }
} }
private func addHiddenFieldInformation(to cell: UITableViewCell) {
guard password != nil, let detailTextLabel = cell.detailTextLabel else {
return
}
var numberOfHiddenFields = 0
numberOfHiddenFields += SharedDefaults[.isHideUnknownOn] ? password!.numberOfUnknowns : 0
numberOfHiddenFields += SharedDefaults[.isHideOTPOn] ? password!.numberOfOtpRelated : 0
guard numberOfHiddenFields > 0 else {
return
}
detailTextLabel.textAlignment = .center
detailTextLabel.textColor = .gray
detailTextLabel.text = "\(numberOfHiddenFields) hidden field\(numberOfHiddenFields > 1 ? "s" : "")"
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return tableData[section].header return tableData[section].header
} }

View file

@ -59,6 +59,14 @@ public class Password {
return otpToken?.currentPassword return otpToken?.currentPassword
} }
public var numberOfUnknowns: Int {
return additions.map { $0.title }.filter(Constants.isUnknown).count
}
public var numberOfOtpRelated: Int {
return additions.map { $0.title }.filter(Constants.isOtpKeyword).count - (firstLineIsOTPField ? 1 : 0)
}
public init(name: String, url: URL, plainText: String) { public init(name: String, url: URL, plainText: String) {
self.name = name self.name = name
self.url = url self.url = url