summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-10-07 20:25:19 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-10-07 20:25:19 +0530
commit66159923323bcffccf18893a81a542e18b0bda1a (patch)
tree9db519e04e994bf5c6efa107b06fca9b5647614a /app/src
parent6dcffc04d21a612842191f058968315468ac8226 (diff)
refactor: simplify `PasswordDialog` emissions
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/app/passwordstore/ui/crypto/PasswordDialog.kt10
1 files changed, 5 insertions, 5 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/crypto/PasswordDialog.kt b/app/src/main/java/app/passwordstore/ui/crypto/PasswordDialog.kt
index 1ae90da3..25aa18e4 100644
--- a/app/src/main/java/app/passwordstore/ui/crypto/PasswordDialog.kt
+++ b/app/src/main/java/app/passwordstore/ui/crypto/PasswordDialog.kt
@@ -19,6 +19,7 @@ import app.passwordstore.util.extensions.unsafeLazy
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.flow.update
/** [DialogFragment] to request a password from the user and forward it along. */
class PasswordDialog : DialogFragment() {
@@ -32,7 +33,7 @@ class PasswordDialog : DialogFragment() {
val builder = MaterialAlertDialogBuilder(requireContext())
builder.setView(binding.root)
builder.setTitle(R.string.password)
- builder.setPositiveButton(android.R.string.ok) { _, _ -> tryEmitPassword() }
+ builder.setPositiveButton(android.R.string.ok) { _, _ -> setPasswordAndDismiss() }
val dialog = builder.create()
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
dialog.setOnShowListener {
@@ -42,7 +43,7 @@ class PasswordDialog : DialogFragment() {
binding.passwordEditText.doOnTextChanged { _, _, _, _ -> binding.passwordField.error = null }
binding.passwordEditText.setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_ENTER) {
- tryEmitPassword()
+ setPasswordAndDismiss()
return@setOnKeyListener true
}
false
@@ -64,9 +65,8 @@ class PasswordDialog : DialogFragment() {
finish()
}
- @Suppress("ControlFlowWithEmptyBody")
- private fun tryEmitPassword() {
- do {} while (!_password.tryEmit(binding.passwordEditText.text.toString()))
+ private fun setPasswordAndDismiss() {
+ _password.update { binding.passwordEditText.text.toString() }
dismissAllowingStateLoss()
}
}