Use PasswordGeneratorFlavor class to set user defaults and UI elements

This commit is contained in:
Danny Moesch 2019-01-14 20:24:56 +01:00 committed by Mingshen Sun
parent 857a8f44bf
commit 2d5ca58bd9
6 changed files with 19 additions and 8 deletions

View file

@ -20,7 +20,7 @@ class AddPasswordTableViewController: PasswordEditorTableViewController {
[[.type: PasswordEditorCellType.additionsCell, .title: "additions"]],
[[.type: PasswordEditorCellType.scanQRCodeCell]]
]
if PasswordGeneratorFlavour.from(SharedDefaults[.passwordGeneratorFlavor]) == PasswordGeneratorFlavour.RANDOM {
if PasswordGeneratorFlavour.from(SharedDefaults[.passwordGeneratorFlavor]) == .RANDOM {
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
}
tableData[1].append([.type: PasswordEditorCellType.memorablePasswordGeneratorCell])

View file

@ -18,7 +18,7 @@ class EditPasswordTableViewController: PasswordEditorTableViewController {
[[.type: PasswordEditorCellType.scanQRCodeCell],
[.type: PasswordEditorCellType.deletePasswordCell]]
]
if PasswordGeneratorFlavour.from(SharedDefaults[.passwordGeneratorFlavor]) == PasswordGeneratorFlavour.RANDOM {
if PasswordGeneratorFlavour.from(SharedDefaults[.passwordGeneratorFlavor]) == .RANDOM {
tableData[1].append([.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"])
}
tableData[1].append([.type: PasswordEditorCellType.memorablePasswordGeneratorCell])

View file

@ -122,7 +122,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
cell.accessoryView = showFolderSwitch
case "Password Generator Flavor":
cell.accessoryType = .disclosureIndicator
cell.detailTextLabel?.text = SharedDefaults[.passwordGeneratorFlavor]
cell.detailTextLabel?.text = PasswordGeneratorFlavour.from(SharedDefaults[.passwordGeneratorFlavor]).name
default: break
}
return cell
@ -141,21 +141,21 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
var randomFlavorActionTitle = ""
var appleFlavorActionTitle = ""
if SharedDefaults[.passwordGeneratorFlavor] == "Random" {
randomFlavorActionTitle = "✓ Random String"
appleFlavorActionTitle = "Apple's Keychain Style"
if SharedDefaults[.passwordGeneratorFlavor] == PasswordGeneratorFlavour.RANDOM.rawValue {
} else {
randomFlavorActionTitle = "Random String"
appleFlavorActionTitle = "✓ Apple's Keychain Style"
}
let randomFlavorAction = UIAlertAction(title: randomFlavorActionTitle, style: .default) { _ in
SharedDefaults[.passwordGeneratorFlavor] = "Random"
sourceCell.detailTextLabel?.text = "Random"
SharedDefaults[.passwordGeneratorFlavor] = PasswordGeneratorFlavour.RANDOM.rawValue
sourceCell.detailTextLabel?.text = PasswordGeneratorFlavour.RANDOM.name
}
let appleFlavorAction = UIAlertAction(title: appleFlavorActionTitle, style: .default) { _ in
SharedDefaults[.passwordGeneratorFlavor] = "Apple"
sourceCell.detailTextLabel?.text = "Apple"
SharedDefaults[.passwordGeneratorFlavor] = PasswordGeneratorFlavour.APPLE.rawValue
sourceCell.detailTextLabel?.text = PasswordGeneratorFlavour.APPLE.name
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)