Merge branch 'develop' of github.com:mssun/passforios into develop
This commit is contained in:
commit
dcf04332cd
3 changed files with 42 additions and 21 deletions
|
|
@ -16,7 +16,8 @@ class AddPasswordTableViewController: PasswordEditorTableViewController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
tableData = [
|
tableData = [
|
||||||
[[.type: PasswordEditorCellType.textFieldCell, .title: "name"]],
|
[[.type: PasswordEditorCellType.textFieldCell, .title: "name"]],
|
||||||
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password"]],
|
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password"],
|
||||||
|
[.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"]],
|
||||||
[[.type: PasswordEditorCellType.textViewCell, .title: "additions"]],
|
[[.type: PasswordEditorCellType.textViewCell, .title: "additions"]],
|
||||||
]
|
]
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ class EditPasswordTableViewController: PasswordEditorTableViewController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
tableData = [
|
tableData = [
|
||||||
[[.type: PasswordEditorCellType.textFieldCell, .title: "name", .content: password!.name]],
|
[[.type: PasswordEditorCellType.textFieldCell, .title: "name", .content: password!.name]],
|
||||||
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password", .content: password!.password]],
|
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password", .content: password!.password],
|
||||||
|
[.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"]],
|
||||||
[[.type: PasswordEditorCellType.textViewCell, .title: "additions", .content: password!.getAdditionsPlainText()]],
|
[[.type: PasswordEditorCellType.textViewCell, .title: "additions", .content: password!.getAdditionsPlainText()]],
|
||||||
[[.type: PasswordEditorCellType.deletePasswordCell]],
|
[[.type: PasswordEditorCellType.deletePasswordCell]],
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
var sectionHeaderTitles = ["name", "password", "additions",""].map {$0.uppercased()}
|
var sectionHeaderTitles = ["name", "password", "additions",""].map {$0.uppercased()}
|
||||||
var sectionFooterTitles = ["", "", "Use \"key: value\" format for additional fields.", ""]
|
var sectionFooterTitles = ["", "", "Use \"key: value\" format for additional fields.", ""]
|
||||||
let passwordSection = 1
|
let passwordSection = 1
|
||||||
|
var hidePasswordSettings = true
|
||||||
|
|
||||||
var fillPasswordCell: FillPasswordTableViewCell?
|
var fillPasswordCell: FillPasswordTableViewCell?
|
||||||
var passwordLengthCell: SliderTableViewCell?
|
var passwordLengthCell: SliderTableViewCell?
|
||||||
|
|
@ -52,6 +53,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
|
|
||||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tableTapped))
|
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tableTapped))
|
||||||
tapGesture.delegate = self
|
tapGesture.delegate = self
|
||||||
|
tapGesture.cancelsTouchesInView = false
|
||||||
tableView.addGestureRecognizer(tapGesture)
|
tableView.addGestureRecognizer(tapGesture)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,8 +93,13 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
if section == passwordSection, hidePasswordSettings {
|
||||||
|
// hide the password section, only the password should be shown
|
||||||
|
return 1
|
||||||
|
} else {
|
||||||
return tableData[section].count
|
return tableData[section].count
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
return sectionHeaderTitles[section]
|
return sectionHeaderTitles[section]
|
||||||
|
|
@ -116,35 +123,47 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
|
|
||||||
// generate password, copy to pasteboard, and set the cell
|
// generate password, copy to pasteboard, and set the cell
|
||||||
func generateAndCopyPassword() {
|
func generateAndCopyPassword() {
|
||||||
// insert the length slider if not existed
|
// show password settings (e.g., the length slider)
|
||||||
if passwordLengthCell == nil {
|
if hidePasswordSettings == true {
|
||||||
let row = tableData[passwordSection].count
|
hidePasswordSettings = false
|
||||||
tableData[passwordSection].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
|
tableView.reloadSections([passwordSection], with: .fade)
|
||||||
let indexPath = IndexPath(row: row, section: passwordSection)
|
|
||||||
tableView.insertRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
|
|
||||||
}
|
}
|
||||||
let length = passwordLengthCell?.roundedValue ?? Globals.passwordDefaultLength
|
let length = passwordLengthCell?.roundedValue ?? Globals.passwordDefaultLength
|
||||||
let plainPassword = Utils.generatePassword(length: length)
|
let plainPassword = Utils.generatePassword(length: length)
|
||||||
Utils.copyToPasteboard(textToCopy: plainPassword)
|
Utils.copyToPasteboard(textToCopy: plainPassword)
|
||||||
|
|
||||||
|
// update tableData so to make sure reloadData() works correctly
|
||||||
|
tableData[passwordSection][0][PasswordEditorCellKey.content] = plainPassword
|
||||||
|
|
||||||
|
// update cell manually, no need to call reloadData()
|
||||||
fillPasswordCell?.setContent(content: plainPassword)
|
fillPasswordCell?.setContent(content: plainPassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableTapped(tap: UITapGestureRecognizer) {
|
func tableTapped(recognizer: UITapGestureRecognizer) {
|
||||||
let location = tap.location(in: self.tableView)
|
if recognizer.state == UIGestureRecognizerState.ended {
|
||||||
let path = self.tableView.indexPathForRow(at: location)
|
let tapLocation = recognizer.location(in: self.tableView)
|
||||||
if path?.section != passwordSection, tableData[passwordSection].count > 1 {
|
let tapIndexPath = self.tableView.indexPathForRow(at: tapLocation)
|
||||||
// remove password settings (e.g., sliders)
|
|
||||||
let row = tableData[passwordSection].count
|
// do nothing, if delete is tapped (a temporary solution)
|
||||||
passwordLengthCell = nil
|
if tapIndexPath != nil, deletePasswordCell != nil,
|
||||||
tableData[passwordSection].removeLast(row - 1)
|
tableView.cellForRow(at: tapIndexPath!) == deletePasswordCell {
|
||||||
let indexPaths = (1...row-1).map{IndexPath(row: $0, section: passwordSection)}
|
return
|
||||||
print(indexPaths)
|
}
|
||||||
tableView.deleteRows(at: indexPaths, with: UITableViewRowAnimation.automatic)
|
|
||||||
|
// hide password settings (e.g., the length slider)
|
||||||
|
if tapIndexPath?.section != passwordSection, hidePasswordSettings == false {
|
||||||
|
hidePasswordSettings = true
|
||||||
|
tableView.reloadSections([passwordSection], with: .fade)
|
||||||
|
// select the row at tapIndexPath manually
|
||||||
|
if tapIndexPath != nil {
|
||||||
|
self.tableView(self.tableView, didSelectRowAt: tapIndexPath!)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||||
if (gestureRecognizer is UITapGestureRecognizer) {
|
if gestureRecognizer is UITapGestureRecognizer {
|
||||||
// so that the tap gesture could be passed by
|
// so that the tap gesture could be passed by
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue