Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit d68958c

Browse files
committed
refactor: switch DecryptActivity to DispatcherProvider
1 parent b313c42 commit d68958c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import app.passwordstore.data.passfile.PasswordEntry
1616
import app.passwordstore.data.password.FieldItem
1717
import app.passwordstore.databinding.DecryptLayoutBinding
1818
import app.passwordstore.ui.adapters.FieldItemAdapter
19+
import app.passwordstore.util.coroutines.DispatcherProvider
1920
import app.passwordstore.util.extensions.getString
2021
import app.passwordstore.util.extensions.unsafeLazy
2122
import app.passwordstore.util.extensions.viewBinding
@@ -30,7 +31,6 @@ import java.io.File
3031
import javax.inject.Inject
3132
import kotlin.time.Duration.Companion.seconds
3233
import kotlin.time.ExperimentalTime
33-
import kotlinx.coroutines.Dispatchers
3434
import kotlinx.coroutines.delay
3535
import kotlinx.coroutines.flow.collectLatest
3636
import kotlinx.coroutines.flow.first
@@ -49,6 +49,7 @@ class DecryptActivity : BasePgpActivity() {
4949
private val relativeParentPath by unsafeLazy { getParentPath(fullPath, repoPath) }
5050
@Inject lateinit var passwordEntryFactory: PasswordEntry.Factory
5151
@Inject lateinit var repository: CryptoRepository
52+
@Inject lateinit var dispatcherProvider: DispatcherProvider
5253

5354
private var passwordEntry: PasswordEntry? = null
5455
private var retries = 0
@@ -147,7 +148,7 @@ class DecryptActivity : BasePgpActivity() {
147148
if (isError) {
148149
dialog.setError()
149150
}
150-
lifecycleScope.launch(Dispatchers.Main) {
151+
lifecycleScope.launch(dispatcherProvider.main()) {
151152
dialog.password.collectLatest { value ->
152153
if (value != null) {
153154
when (val result = decryptWithPassphrase(value)) {
@@ -169,7 +170,7 @@ class DecryptActivity : BasePgpActivity() {
169170
}
170171

171172
private suspend fun decryptWithPassphrase(password: String) = runCatching {
172-
val message = withContext(Dispatchers.IO) { File(fullPath).readBytes().inputStream() }
173+
val message = withContext(dispatcherProvider.io()) { File(fullPath).readBytes().inputStream() }
173174
val outputStream = ByteArrayOutputStream()
174175
val result =
175176
repository.decrypt(
@@ -184,7 +185,7 @@ class DecryptActivity : BasePgpActivity() {
184185
}
185186

186187
private suspend fun createPasswordUI(entry: PasswordEntry) =
187-
withContext(Dispatchers.Main) {
188+
withContext(dispatcherProvider.main()) {
188189
val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
189190
invalidateOptionsMenu()
190191

0 commit comments

Comments
 (0)