Add switch to turn on/off showing folders
This commit is contained in:
parent
050a960167
commit
f75f949ab1
3 changed files with 33 additions and 3 deletions
|
|
@ -18,6 +18,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction(_:)), for: UIControlEvents.valueChanged)
|
uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction(_:)), for: UIControlEvents.valueChanged)
|
||||||
return uiSwitch
|
return uiSwitch
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let rememberPassphraseSwitch: UISwitch = {
|
let rememberPassphraseSwitch: UISwitch = {
|
||||||
let uiSwitch = UISwitch()
|
let uiSwitch = UISwitch()
|
||||||
uiSwitch.onTintColor = Globals.blue
|
uiSwitch.onTintColor = Globals.blue
|
||||||
|
|
@ -26,6 +27,15 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
uiSwitch.isOn = Defaults[.isRememberPassphraseOn]
|
uiSwitch.isOn = Defaults[.isRememberPassphraseOn]
|
||||||
return uiSwitch
|
return uiSwitch
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
let showFolderSwitch: UISwitch = {
|
||||||
|
let uiSwitch = UISwitch()
|
||||||
|
uiSwitch.onTintColor = Globals.blue
|
||||||
|
uiSwitch.sizeToFit()
|
||||||
|
uiSwitch.addTarget(self, action: #selector(showFolderSwitchAction(_:)), for: UIControlEvents.valueChanged)
|
||||||
|
uiSwitch.isOn = Defaults[.isShowFolderOn]
|
||||||
|
return uiSwitch
|
||||||
|
}()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
navigationItemTitle = "General"
|
navigationItemTitle = "General"
|
||||||
|
|
@ -36,6 +46,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
// section 1
|
// section 1
|
||||||
[
|
[
|
||||||
[.title: "Remember Phassphrase", .action: "none",],
|
[.title: "Remember Phassphrase", .action: "none",],
|
||||||
|
[.title: "Show Folder", .action: "none",],
|
||||||
[.title: "Hide Unknown Fields", .action: "none",],
|
[.title: "Hide Unknown Fields", .action: "none",],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
@ -46,7 +57,8 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
let cell = super.tableView(tableView, cellForRowAt: indexPath)
|
let cell = super.tableView(tableView, cellForRowAt: indexPath)
|
||||||
if cell.textLabel?.text == "Hide Unknown Fields" {
|
switch cell.textLabel!.text! {
|
||||||
|
case "Hide Unknown Fields":
|
||||||
cell.accessoryType = .none
|
cell.accessoryType = .none
|
||||||
let detailButton = UIButton(type: .detailDisclosure)
|
let detailButton = UIButton(type: .detailDisclosure)
|
||||||
hideUnknownSwitch.frame = CGRect(x: detailButton.bounds.width+10, y: 0, width: hideUnknownSwitch.bounds.width, height: hideUnknownSwitch.bounds.height)
|
hideUnknownSwitch.frame = CGRect(x: detailButton.bounds.width+10, y: 0, width: hideUnknownSwitch.bounds.width, height: hideUnknownSwitch.bounds.height)
|
||||||
|
|
@ -58,10 +70,15 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
cell.accessoryView = accessoryView
|
cell.accessoryView = accessoryView
|
||||||
cell.selectionStyle = .none
|
cell.selectionStyle = .none
|
||||||
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
|
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
|
||||||
} else if cell.textLabel?.text == "Remember Phassphrase" {
|
case "Remember Phassphrase":
|
||||||
cell.accessoryType = .none
|
cell.accessoryType = .none
|
||||||
cell.selectionStyle = .none
|
cell.selectionStyle = .none
|
||||||
cell.accessoryView = rememberPassphraseSwitch
|
cell.accessoryView = rememberPassphraseSwitch
|
||||||
|
case "Show Folder":
|
||||||
|
cell.accessoryType = .none
|
||||||
|
cell.selectionStyle = .none
|
||||||
|
cell.accessoryView = showFolderSwitch
|
||||||
|
default: break
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
@ -83,4 +100,9 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showFolderSwitchAction(_ sender: Any?) {
|
||||||
|
Defaults[.isShowFolderOn] = showFolderSwitch.isOn
|
||||||
|
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,14 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
private func initPasswordsTableEntries() {
|
private func initPasswordsTableEntries() {
|
||||||
passwordsTableEntries.removeAll()
|
passwordsTableEntries.removeAll()
|
||||||
filteredPasswordsTableEntries.removeAll()
|
filteredPasswordsTableEntries.removeAll()
|
||||||
passwordsTableEntries = PasswordStore.shared.fetchPasswordEntityCoreData(parent: parentPasswordEntity).map {
|
var passwordEntities = [PasswordEntity]()
|
||||||
|
if Defaults[.isShowFolderOn] {
|
||||||
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData(parent: parentPasswordEntity)
|
||||||
|
} else {
|
||||||
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false)
|
||||||
|
|
||||||
|
}
|
||||||
|
passwordsTableEntries = passwordEntities.map {
|
||||||
PasswordsTableEntry(title: $0.name!, isDir: $0.isDir, passwordEntity: $0)
|
PasswordsTableEntry(title: $0.name!, isDir: $0.isDir, passwordEntity: $0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ extension DefaultsKeys {
|
||||||
|
|
||||||
static let isHideUnknownOn = DefaultsKey<Bool>("isHideUnknownOn")
|
static let isHideUnknownOn = DefaultsKey<Bool>("isHideUnknownOn")
|
||||||
static let isRememberPassphraseOn = DefaultsKey<Bool>("isRememberPassphraseOn")
|
static let isRememberPassphraseOn = DefaultsKey<Bool>("isRememberPassphraseOn")
|
||||||
|
static let isShowFolderOn = DefaultsKey<Bool>("isShowFolderOn")
|
||||||
|
|
||||||
static let passwordGenerationMethod = DefaultsKey<String>("passwordGenerationMethod")
|
static let passwordGenerationMethod = DefaultsKey<String>("passwordGenerationMethod")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue