Replace TableCell struct with AdditionField
This commit is contained in:
parent
ed387069a4
commit
9e027b878a
4 changed files with 29 additions and 50 deletions
|
|
@ -24,42 +24,18 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
return uiBarButtonItem
|
||||
}()
|
||||
|
||||
private struct TableCell {
|
||||
var title: String
|
||||
var content: String
|
||||
init() {
|
||||
title = ""
|
||||
content = ""
|
||||
}
|
||||
|
||||
init(title: String) {
|
||||
self.title = title
|
||||
self.content = ""
|
||||
}
|
||||
|
||||
init(title: String, content: String) {
|
||||
self.title = title
|
||||
self.content = content
|
||||
}
|
||||
}
|
||||
|
||||
private struct TableSection {
|
||||
var type: PasswordDetailTableViewControllerSectionType
|
||||
var header: String?
|
||||
var item: Array<TableCell>
|
||||
init(type: PasswordDetailTableViewControllerSectionType) {
|
||||
self.type = type
|
||||
header = nil
|
||||
item = [TableCell]()
|
||||
}
|
||||
var item: [AdditionField] = []
|
||||
|
||||
init(type: PasswordDetailTableViewControllerSectionType, header: String) {
|
||||
self.init(type: type)
|
||||
init(type: PasswordDetailTableViewControllerSectionType, header: String? = nil) {
|
||||
self.type = type
|
||||
self.header = header
|
||||
}
|
||||
}
|
||||
|
||||
private var tableData = Array<TableSection>()
|
||||
private var tableData = [TableSection]()
|
||||
|
||||
private enum PasswordDetailTableViewControllerSectionType {
|
||||
case name, main, addition, misc
|
||||
|
|
@ -194,8 +170,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
switch otpType {
|
||||
case .totp:
|
||||
if let (title, otp) = strongSelf.password?.getOtpStrings() {
|
||||
strongSelf.tableData[indexPath.section].item[indexPath.row].title = title
|
||||
strongSelf.tableData[indexPath.section].item[indexPath.row].content = otp
|
||||
strongSelf.tableData[indexPath.section].item[indexPath.row] = title => otp
|
||||
cell.cellData?.title = title
|
||||
cell.cellData?.content = otp
|
||||
}
|
||||
|
|
@ -246,19 +221,19 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
|
||||
// name section
|
||||
var section = TableSection(type: .name)
|
||||
section.item.append(TableCell())
|
||||
section.item.append(AdditionField())
|
||||
tableData.append(section)
|
||||
|
||||
// main section
|
||||
section = TableSection(type: .main)
|
||||
let password = self.password!
|
||||
if let username = password.username {
|
||||
section.item.append(TableCell(title: "username", content: username))
|
||||
section.item.append(Constants.USERNAME_KEYWORD => username)
|
||||
}
|
||||
if let login = password.login {
|
||||
section.item.append(TableCell(title: "login", content: login))
|
||||
section.item.append(Constants.LOGIN_KEYWORD => login)
|
||||
}
|
||||
section.item.append(TableCell(title: "password", content: password.password))
|
||||
section.item.append(Constants.PASSWORD_KEYWORD => password.password)
|
||||
tableData.append(section)
|
||||
|
||||
|
||||
|
|
@ -268,7 +243,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
if password.otpType != .none {
|
||||
if let (title, otp) = self.password?.getOtpStrings() {
|
||||
section = TableSection(type: .addition, header: "One Time Password")
|
||||
section.item.append(TableCell(title: title, content: otp))
|
||||
section.item.append(title => otp)
|
||||
tableData.append(section)
|
||||
oneTimePasswordIndexPath = IndexPath(row: 0, section: tableData.count - 1)
|
||||
}
|
||||
|
|
@ -278,15 +253,13 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
|||
let filteredAdditionKeys = password.getFilteredAdditions()
|
||||
if filteredAdditionKeys.count > 0 {
|
||||
section = TableSection(type: .addition, header: "additions")
|
||||
filteredAdditionKeys.forEach({ field in
|
||||
section.item.append(TableCell(title: field.title, content: field.content))
|
||||
})
|
||||
section.item.append(contentsOf: filteredAdditionKeys)
|
||||
tableData.append(section)
|
||||
}
|
||||
|
||||
// misc section
|
||||
section = TableSection(type: .misc)
|
||||
section.item.append(TableCell(title: "Show Raw"))
|
||||
section.item.append(AdditionField(title: "Show Raw"))
|
||||
tableData.append(section)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ public struct AdditionField: Hashable {
|
|||
|
||||
public let title: String, content: String
|
||||
|
||||
public init(title: String = "", content: String = "") {
|
||||
self.title = title
|
||||
self.content = content
|
||||
}
|
||||
|
||||
var asString: String {
|
||||
return title.isEmpty ? content : title + ": " + content
|
||||
}
|
||||
|
|
@ -42,6 +47,6 @@ extension AdditionField: Equatable {
|
|||
}
|
||||
|
||||
infix operator =>: MultiplicationPrecedence
|
||||
func => (key: String, value: String) -> AdditionField {
|
||||
public func => (key: String, value: String) -> AdditionField {
|
||||
return AdditionField(title: key, content: value)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,11 +41,12 @@ public struct Constants {
|
|||
static let MULTILINE_WITHOUT_LINE_BREAK_SEPARATOR = BLANK
|
||||
|
||||
static let OTPAUTH_URL_START = "\(OTPAUTH)://"
|
||||
static let PASSWORD_KEYWORD = "password"
|
||||
static let USERNAME_KEYWORD = "username"
|
||||
static let LOGIN_KEYWORD = "login"
|
||||
static let URL_KEYWORD = "url"
|
||||
static let UNKNOWN = "unknown"
|
||||
|
||||
public static let PASSWORD_KEYWORD = "password"
|
||||
public static let USERNAME_KEYWORD = "username"
|
||||
public static let LOGIN_KEYWORD = "login"
|
||||
public static let URL_KEYWORD = "url"
|
||||
public static let UNKNOWN = "unknown"
|
||||
|
||||
public static func isOtpRelated(line: String) -> Bool {
|
||||
let (key, _) = Parser.getKeyValuePair(from: line)
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@ import XCTest
|
|||
class AdditionFieldTest: XCTestCase {
|
||||
|
||||
func testAdditionField() {
|
||||
let field1 = "key" => "value"
|
||||
let field2 = "some other key" => "some other value"
|
||||
let field3 = "" => "no title"
|
||||
let field1 = AdditionField(title: "key", content: "value")
|
||||
let field2 = AdditionField(title: "no content")
|
||||
let field3 = AdditionField(content: "no title")
|
||||
|
||||
XCTAssertEqual(field1.asString, "key: value")
|
||||
XCTAssertEqual(field2.asString, "some other key: some other value")
|
||||
XCTAssertEqual(field2.asString, "no content: ")
|
||||
XCTAssertEqual(field3.asString, "no title")
|
||||
|
||||
XCTAssertTrue(field1.asTuple == ("key", "value"))
|
||||
XCTAssertTrue(field2.asTuple == ("some other key", "some other value"))
|
||||
XCTAssertTrue(field2.asTuple == ("no content", ""))
|
||||
XCTAssertTrue(field3.asTuple == ("", "no title"))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue