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