diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-10-07 19:45:54 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-10-07 19:45:54 +0530 |
commit | d68958c3e145b8f0591098db5e50adc6e2a8d0c6 (patch) | |
tree | 2252e43307886baf1530dc0f2065281898aef01c /app | |
parent | b313c4216ea86d6202e2730b26e4fc3924d731eb (diff) |
refactor: switch `DecryptActivity` to `DispatcherProvider`
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt index bb3d2fdf..ce14c64d 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt @@ -16,6 +16,7 @@ import app.passwordstore.data.passfile.PasswordEntry import app.passwordstore.data.password.FieldItem import app.passwordstore.databinding.DecryptLayoutBinding import app.passwordstore.ui.adapters.FieldItemAdapter +import app.passwordstore.util.coroutines.DispatcherProvider import app.passwordstore.util.extensions.getString import app.passwordstore.util.extensions.unsafeLazy import app.passwordstore.util.extensions.viewBinding @@ -30,7 +31,6 @@ import java.io.File import javax.inject.Inject import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.first @@ -49,6 +49,7 @@ class DecryptActivity : BasePgpActivity() { private val relativeParentPath by unsafeLazy { getParentPath(fullPath, repoPath) } @Inject lateinit var passwordEntryFactory: PasswordEntry.Factory @Inject lateinit var repository: CryptoRepository + @Inject lateinit var dispatcherProvider: DispatcherProvider private var passwordEntry: PasswordEntry? = null private var retries = 0 @@ -147,7 +148,7 @@ class DecryptActivity : BasePgpActivity() { if (isError) { dialog.setError() } - lifecycleScope.launch(Dispatchers.Main) { + lifecycleScope.launch(dispatcherProvider.main()) { dialog.password.collectLatest { value -> if (value != null) { when (val result = decryptWithPassphrase(value)) { @@ -169,7 +170,7 @@ class DecryptActivity : BasePgpActivity() { } private suspend fun decryptWithPassphrase(password: String) = runCatching { - val message = withContext(Dispatchers.IO) { File(fullPath).readBytes().inputStream() } + val message = withContext(dispatcherProvider.io()) { File(fullPath).readBytes().inputStream() } val outputStream = ByteArrayOutputStream() val result = repository.decrypt( @@ -184,7 +185,7 @@ class DecryptActivity : BasePgpActivity() { } private suspend fun createPasswordUI(entry: PasswordEntry) = - withContext(Dispatchers.Main) { + withContext(dispatcherProvider.main()) { val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true) invalidateOptionsMenu() |