Add switch to turn on/off showing folders

This commit is contained in:
Bob Sun 2017-03-02 15:01:52 +08:00
parent 050a960167
commit f75f949ab1
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
3 changed files with 33 additions and 3 deletions

View file

@ -18,6 +18,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction(_:)), for: UIControlEvents.valueChanged)
return uiSwitch
}()
let rememberPassphraseSwitch: UISwitch = {
let uiSwitch = UISwitch()
uiSwitch.onTintColor = Globals.blue
@ -26,6 +27,15 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
uiSwitch.isOn = Defaults[.isRememberPassphraseOn]
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() {
navigationItemTitle = "General"
@ -36,6 +46,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
// section 1
[
[.title: "Remember Phassphrase", .action: "none",],
[.title: "Show Folder", .action: "none",],
[.title: "Hide Unknown Fields", .action: "none",],
],
@ -46,7 +57,8 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
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
let detailButton = UIButton(type: .detailDisclosure)
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.selectionStyle = .none
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
} else if cell.textLabel?.text == "Remember Phassphrase" {
case "Remember Phassphrase":
cell.accessoryType = .none
cell.selectionStyle = .none
cell.accessoryView = rememberPassphraseSwitch
case "Show Folder":
cell.accessoryType = .none
cell.selectionStyle = .none
cell.accessoryView = showFolderSwitch
default: break
}
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")))
}
}

View file

@ -29,7 +29,14 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
private func initPasswordsTableEntries() {
passwordsTableEntries.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)
}
}

View file

@ -34,6 +34,7 @@ extension DefaultsKeys {
static let isHideUnknownOn = DefaultsKey<Bool>("isHideUnknownOn")
static let isRememberPassphraseOn = DefaultsKey<Bool>("isRememberPassphraseOn")
static let isShowFolderOn = DefaultsKey<Bool>("isShowFolderOn")
static let passwordGenerationMethod = DefaultsKey<String>("passwordGenerationMethod")