Animate "AdditionField" struct to avoid usage of tuple "(String, String)"
This commit is contained in:
parent
1890e77bd2
commit
b7a0cbaef6
2 changed files with 29 additions and 22 deletions
|
|
@ -278,8 +278,8 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
let filteredAdditionKeys = password.getFilteredAdditions()
|
let filteredAdditionKeys = password.getFilteredAdditions()
|
||||||
if filteredAdditionKeys.count > 0 {
|
if filteredAdditionKeys.count > 0 {
|
||||||
section = TableSection(type: .addition, header: "additions")
|
section = TableSection(type: .addition, header: "additions")
|
||||||
filteredAdditionKeys.forEach({ (key: String, value: String) in
|
filteredAdditionKeys.forEach({ field in
|
||||||
section.item.append(TableCell(title: key, content: value))
|
section.item.append(TableCell(title: field.title, content: field.content))
|
||||||
})
|
})
|
||||||
tableData.append(section)
|
tableData.append(section)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,16 @@ import OneTimePassword
|
||||||
import Base32
|
import Base32
|
||||||
import Yams
|
import Yams
|
||||||
|
|
||||||
struct AdditionField {
|
public struct AdditionField: Equatable {
|
||||||
var title: String
|
public var title: String = ""
|
||||||
var content: String
|
public var content: String = ""
|
||||||
|
|
||||||
|
var asString: String { return title.isEmpty ? content : title + ": " + content }
|
||||||
|
var asTuple: (String, String) { return (title, content) }
|
||||||
|
|
||||||
|
public static func == (first: AdditionField, second: AdditionField) -> Bool {
|
||||||
|
return first.asTuple == second.asTuple
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PasswordChange: Int {
|
enum PasswordChange: Int {
|
||||||
|
|
@ -42,7 +49,7 @@ public class Password {
|
||||||
public var changed: Int = 0
|
public var changed: Int = 0
|
||||||
public var plainText = ""
|
public var plainText = ""
|
||||||
|
|
||||||
private var additions = [(String, String)]()
|
private var additions = [AdditionField]()
|
||||||
private var firstLineIsOTPField = false
|
private var firstLineIsOTPField = false
|
||||||
private var otpToken: Token?
|
private var otpToken: Token?
|
||||||
|
|
||||||
|
|
@ -112,13 +119,13 @@ public class Password {
|
||||||
|
|
||||||
// get and append otp tokens
|
// get and append otp tokens
|
||||||
let otpAdditionalLines = additionalLines.filter { $0.hasPrefix(Password.OTPAUTH_URL_START) }
|
let otpAdditionalLines = additionalLines.filter { $0.hasPrefix(Password.OTPAUTH_URL_START) }
|
||||||
otpAdditionalLines.forEach { self.additions.append((Password.OTPAUTH, $0)) }
|
otpAdditionalLines.forEach { self.additions.append(AdditionField(title: Password.OTPAUTH, content: $0)) }
|
||||||
|
|
||||||
// check whether the first line looks like an otp entry
|
// check whether the first line looks like an otp entry
|
||||||
let (key, value) = Password.getKeyValuePair(from: self.password)
|
let (key, value) = Password.getKeyValuePair(from: self.password)
|
||||||
if Password.otpKeywords.contains(key ?? "") {
|
if Password.otpKeywords.contains(key ?? "") {
|
||||||
firstLineIsOTPField = true
|
firstLineIsOTPField = true
|
||||||
self.additions.append((key!, value))
|
self.additions.append(AdditionField(title: key!, content: value))
|
||||||
} else {
|
} else {
|
||||||
firstLineIsOTPField = false
|
firstLineIsOTPField = false
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +159,7 @@ public class Password {
|
||||||
guard let yamlFile = try Yams.load(yaml: fromYaml) as? [String: String] else {
|
guard let yamlFile = try Yams.load(yaml: fromYaml) as? [String: String] else {
|
||||||
throw AppError.YamlLoadError
|
throw AppError.YamlLoadError
|
||||||
}
|
}
|
||||||
additions.append(contentsOf: yamlFile.map { ($0, String(describing: $1)) })
|
additions.append(contentsOf: yamlFile.map { AdditionField(title: $0, content: String(describing: $1)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getAdditionalFields(fromPlainText: String) {
|
private func getAdditionalFields(fromPlainText: String) {
|
||||||
|
|
@ -164,18 +171,18 @@ public class Password {
|
||||||
unknownIndex += 1
|
unknownIndex += 1
|
||||||
key = "unknown \(unknownIndex)"
|
key = "unknown \(unknownIndex)"
|
||||||
}
|
}
|
||||||
self.additions.append((key!, value))
|
self.additions.append(AdditionField(title: key!, content: value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getFilteredAdditions() -> [(String, String)] {
|
public func getFilteredAdditions() -> [AdditionField] {
|
||||||
var filteredAdditions = [(String, String)]()
|
var filteredAdditions = [AdditionField]()
|
||||||
additions.forEach { (key: String, value: String) in
|
additions.forEach { field in
|
||||||
if key.lowercased() != "username" && key.lowercased() != "login" && key.lowercased() != "password" &&
|
if field.title.lowercased() != "username" && field.title.lowercased() != "login" && field.title.lowercased() != "password" &&
|
||||||
(!key.hasPrefix("unknown") || !SharedDefaults[.isHideUnknownOn]) &&
|
(!field.title.hasPrefix("unknown") || !SharedDefaults[.isHideUnknownOn]) &&
|
||||||
(!Password.otpKeywords.contains(key) || !SharedDefaults[.isHideOTPOn]) {
|
(!Password.otpKeywords.contains(field.title) || !SharedDefaults[.isHideOTPOn]) {
|
||||||
filteredAdditions.append((key, value))
|
filteredAdditions.append(field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredAdditions
|
return filteredAdditions
|
||||||
|
|
@ -237,10 +244,10 @@ public class Password {
|
||||||
|
|
||||||
private func getAdditionValue(withKey key: String, caseSensitive: Bool = true) -> String? {
|
private func getAdditionValue(withKey key: String, caseSensitive: Bool = true) -> String? {
|
||||||
let searchKey = caseSensitive ? key : key.lowercased()
|
let searchKey = caseSensitive ? key : key.lowercased()
|
||||||
for (currentKey, value) in additions {
|
for field in additions {
|
||||||
let currentKeyTrans = caseSensitive ? currentKey : currentKey.lowercased()
|
let currentKeyTrans = caseSensitive ? field.title : field.title.lowercased()
|
||||||
if searchKey == currentKeyTrans {
|
if searchKey == currentKeyTrans {
|
||||||
return value
|
return field.content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue