aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt76
1 files changed, 36 insertions, 40 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt
index 8edd8f0b..24859852 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/crypto/DecryptActivity.kt
@@ -165,55 +165,51 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
val inputStream = File(fullPath).inputStream()
val outputStream = ByteArrayOutputStream()
- lifecycleScope.launch(Dispatchers.IO) {
- api?.executeApiAsync(data, inputStream, outputStream) { result ->
- when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
- OpenPgpApi.RESULT_CODE_SUCCESS -> {
- startAutoDismissTimer()
- runCatching {
- val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
- val entry = passwordEntryFactory.create(lifecycleScope, outputStream.toByteArray())
- val items = arrayListOf<FieldItem>()
- val adapter = FieldItemAdapter(emptyList(), showPassword) { text -> copyTextToClipboard(text) }
-
- if (settings.getBoolean(PreferenceKeys.COPY_ON_DECRYPT, false)) {
- copyPasswordToClipboard(entry.password)
- }
+ lifecycleScope.launch(Dispatchers.Main) {
+ val result = withContext(Dispatchers.IO) { checkNotNull(api).executeApi(data, inputStream, outputStream) }
+ when (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
+ OpenPgpApi.RESULT_CODE_SUCCESS -> {
+ startAutoDismissTimer()
+ runCatching {
+ val showPassword = settings.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
+ val entry = passwordEntryFactory.create(lifecycleScope, outputStream.toByteArray())
+ val items = arrayListOf<FieldItem>()
+ val adapter = FieldItemAdapter(emptyList(), showPassword) { text -> copyTextToClipboard(text) }
+
+ if (settings.getBoolean(PreferenceKeys.COPY_ON_DECRYPT, false)) {
+ copyPasswordToClipboard(entry.password)
+ }
- passwordEntry = entry
- invalidateOptionsMenu()
+ passwordEntry = entry
+ invalidateOptionsMenu()
- if (!entry.password.isNullOrBlank()) {
- items.add(FieldItem.createPasswordField(entry.password!!))
- }
+ if (!entry.password.isNullOrBlank()) {
+ items.add(FieldItem.createPasswordField(entry.password!!))
+ }
- if (entry.hasTotp()) {
- launch(Dispatchers.IO) {
- withContext(Dispatchers.Main) {
- val code = entry.totp.value
- items.add(FieldItem.createOtpField(code))
- }
- entry.totp.collect { code -> withContext(Dispatchers.Main) { adapter.updateOTPCode(code) } }
- }
+ if (entry.hasTotp()) {
+ launch {
+ items.add(FieldItem.createOtpField(entry.totp.value))
+ entry.totp.collect { code -> withContext(Dispatchers.Main) { adapter.updateOTPCode(code) } }
}
+ }
- if (!entry.username.isNullOrBlank()) {
- items.add(FieldItem.createUsernameField(entry.username!!))
- }
+ if (!entry.username.isNullOrBlank()) {
+ items.add(FieldItem.createUsernameField(entry.username!!))
+ }
- entry.extraContent.forEach { (key, value) -> items.add(FieldItem(key, value, FieldItem.ActionType.COPY)) }
+ entry.extraContent.forEach { (key, value) -> items.add(FieldItem(key, value, FieldItem.ActionType.COPY)) }
- binding.recyclerView.adapter = adapter
- adapter.updateItems(items)
- }
- .onFailure { e -> e(e) }
+ binding.recyclerView.adapter = adapter
+ adapter.updateItems(items)
}
- OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED -> {
- val sender = getUserInteractionRequestIntent(result)
- userInteractionRequiredResult.launch(IntentSenderRequest.Builder(sender).build())
- }
- OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
+ .onFailure { e -> e(e) }
+ }
+ OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED -> {
+ val sender = getUserInteractionRequestIntent(result)
+ userInteractionRequiredResult.launch(IntentSenderRequest.Builder(sender).build())
}
+ OpenPgpApi.RESULT_CODE_ERROR -> handleError(result)
}
}
}