@@ -16,6 +16,7 @@ import app.passwordstore.data.passfile.PasswordEntry
16
16
import app.passwordstore.data.password.FieldItem
17
17
import app.passwordstore.databinding.DecryptLayoutBinding
18
18
import app.passwordstore.ui.adapters.FieldItemAdapter
19
+ import app.passwordstore.util.coroutines.DispatcherProvider
19
20
import app.passwordstore.util.extensions.getString
20
21
import app.passwordstore.util.extensions.unsafeLazy
21
22
import app.passwordstore.util.extensions.viewBinding
@@ -30,7 +31,6 @@ import java.io.File
30
31
import javax.inject.Inject
31
32
import kotlin.time.Duration.Companion.seconds
32
33
import kotlin.time.ExperimentalTime
33
- import kotlinx.coroutines.Dispatchers
34
34
import kotlinx.coroutines.delay
35
35
import kotlinx.coroutines.flow.collectLatest
36
36
import kotlinx.coroutines.flow.first
@@ -49,6 +49,7 @@ class DecryptActivity : BasePgpActivity() {
49
49
private val relativeParentPath by unsafeLazy { getParentPath(fullPath, repoPath) }
50
50
@Inject lateinit var passwordEntryFactory: PasswordEntry .Factory
51
51
@Inject lateinit var repository: CryptoRepository
52
+ @Inject lateinit var dispatcherProvider: DispatcherProvider
52
53
53
54
private var passwordEntry: PasswordEntry ? = null
54
55
private var retries = 0
@@ -147,7 +148,7 @@ class DecryptActivity : BasePgpActivity() {
147
148
if (isError) {
148
149
dialog.setError()
149
150
}
150
- lifecycleScope.launch(Dispatchers . Main ) {
151
+ lifecycleScope.launch(dispatcherProvider.main() ) {
151
152
dialog.password.collectLatest { value ->
152
153
if (value != null ) {
153
154
when (val result = decryptWithPassphrase(value)) {
@@ -169,7 +170,7 @@ class DecryptActivity : BasePgpActivity() {
169
170
}
170
171
171
172
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() }
173
174
val outputStream = ByteArrayOutputStream ()
174
175
val result =
175
176
repository.decrypt(
@@ -184,7 +185,7 @@ class DecryptActivity : BasePgpActivity() {
184
185
}
185
186
186
187
private suspend fun createPasswordUI (entry : PasswordEntry ) =
187
- withContext(Dispatchers . Main ) {
188
+ withContext(dispatcherProvider.main() ) {
188
189
val showPassword = settings.getBoolean(PreferenceKeys .SHOW_PASSWORD , true )
189
190
invalidateOptionsMenu()
190
191
0 commit comments