diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-09-05 20:45:21 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-09-05 22:49:39 +0530 |
commit | 1d1bfbb5ad06ac6c0a63c949a64406cf100a3505 (patch) | |
tree | 8c3f0009b83f4e7d6a5912fb2215d3732a0d8a9c /app | |
parent | bd49bcfb034910d7e1089348d0f5108e296dddf1 (diff) |
PasswordGeneratorDialogFragment: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt index 5528348f..7aa66a03 100644 --- a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/PasswordGeneratorDialogFragment.kt @@ -17,10 +17,11 @@ import androidx.annotation.IdRes import androidx.appcompat.widget.AppCompatEditText import androidx.appcompat.widget.AppCompatTextView import androidx.fragment.app.DialogFragment +import com.github.michaelbull.result.getOrElse +import com.github.michaelbull.result.runCatching import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.R import com.zeapo.pwdstore.pwgen.PasswordGenerator -import com.zeapo.pwdstore.pwgen.PasswordGenerator.PasswordGeneratorException import com.zeapo.pwdstore.pwgen.PasswordGenerator.generate import com.zeapo.pwdstore.pwgen.PasswordGenerator.setPrefs import com.zeapo.pwdstore.pwgen.PasswordOption @@ -71,11 +72,11 @@ class PasswordGeneratorDialogFragment : DialogFragment() { private fun generate(passwordField: AppCompatTextView) { setPreferences() - try { - passwordField.text = generate(requireContext().applicationContext) - } catch (e: PasswordGeneratorException) { + passwordField.text = runCatching { + generate(requireContext().applicationContext) + }.getOrElse { e -> Toast.makeText(requireActivity(), e.message, Toast.LENGTH_SHORT).show() - passwordField.text = "" + "" } } |