Fix error message in password generator

This commit is contained in:
J-Jamet
2020-04-29 17:46:33 +02:00
parent c6832d6478
commit fab5626741
2 changed files with 9 additions and 18 deletions

View File

@@ -167,7 +167,6 @@ class GeneratePasswordDialogFragment : DialogFragment() {
var password = ""
try {
val length = Integer.valueOf(root?.findViewById<EditText>(R.id.length)?.text.toString())
password = PasswordGenerator(resources).generatePassword(length,
uppercaseBox?.isChecked == true,
lowercaseBox?.isChecked == true,
@@ -178,6 +177,7 @@ class GeneratePasswordDialogFragment : DialogFragment() {
specialsBox?.isChecked == true,
bracketsBox?.isChecked == true,
extendedBox?.isChecked == true)
passwordInputLayoutView?.error = null
} catch (e: NumberFormatException) {
passwordInputLayoutView?.error = getString(R.string.error_wrong_length)
} catch (e: IllegalArgumentException) {
@@ -193,7 +193,6 @@ class GeneratePasswordDialogFragment : DialogFragment() {
}
companion object {
const val KEY_PASSWORD_ID = "KEY_PASSWORD_ID"
}
}

View File

@@ -65,14 +65,14 @@ class PasswordGenerator(private val resources: Resources) {
// No option has been checked
if (!upperCase
&& !lowerCase
&& !digits
&& !minus
&& !underline
&& !space
&& !specials
&& !brackets
&& !extended) {
&& !lowerCase
&& !digits
&& !minus
&& !underline
&& !space
&& !specials
&& !brackets
&& !extended) {
throw IllegalArgumentException(resources.getString(R.string.error_pass_gen_type))
}
@@ -114,35 +114,27 @@ class PasswordGenerator(private val resources: Resources) {
if (upperCase) {
charSet.append(UPPERCASE_CHARS)
}
if (lowerCase) {
charSet.append(LOWERCASE_CHARS)
}
if (digits) {
charSet.append(DIGIT_CHARS)
}
if (minus) {
charSet.append(MINUS_CHAR)
}
if (underline) {
charSet.append(UNDERLINE_CHAR)
}
if (space) {
charSet.append(SPACE_CHAR)
}
if (specials) {
charSet.append(SPECIAL_CHARS)
}
if (brackets) {
charSet.append(BRACKET_CHARS)
}
if (extended) {
charSet.append(extendedChars())
}