Remove hand-rolled CoroutineScope and fix inverted conditions (#1386)

This commit is contained in:
Harsh Shandilya 2021-04-18 14:15:45 +05:30 committed by GitHub
parent a3ebcfcc62
commit 7710ca9024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 11 deletions

View File

@ -40,10 +40,7 @@ import kotlin.coroutines.Continuation
import kotlin.coroutines.resume import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import me.msfjarvis.openpgpktx.util.OpenPgpApi import me.msfjarvis.openpgpktx.util.OpenPgpApi
@ -53,7 +50,7 @@ import org.openintents.openpgp.OpenPgpError
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
@AndroidEntryPoint @AndroidEntryPoint
class AutofillDecryptActivity : AppCompatActivity(), CoroutineScope { class AutofillDecryptActivity : AppCompatActivity() {
companion object { companion object {
@ -101,9 +98,6 @@ class AutofillDecryptActivity : AppCompatActivity(), CoroutineScope {
private var continueAfterUserInteraction: Continuation<Intent>? = null private var continueAfterUserInteraction: Continuation<Intent>? = null
private lateinit var directoryStructure: DirectoryStructure private lateinit var directoryStructure: DirectoryStructure
override val coroutineContext
get() = Dispatchers.IO + SupervisorJob()
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
val filePath = val filePath =
@ -124,7 +118,7 @@ class AutofillDecryptActivity : AppCompatActivity(), CoroutineScope {
val action = if (isSearchAction) AutofillAction.Search else AutofillAction.Match val action = if (isSearchAction) AutofillAction.Search else AutofillAction.Match
directoryStructure = AutofillPreferences.directoryStructure(this) directoryStructure = AutofillPreferences.directoryStructure(this)
d { action.toString() } d { action.toString() }
launch { lifecycleScope.launch {
val credentials = decryptCredential(File(filePath)) val credentials = decryptCredential(File(filePath))
if (credentials == null) { if (credentials == null) {
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
@ -141,7 +135,6 @@ class AutofillDecryptActivity : AppCompatActivity(), CoroutineScope {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
coroutineContext.cancelChildren()
} }
private suspend fun executeOpenPgpApi(data: Intent, input: InputStream, output: OutputStream): Intent? { private suspend fun executeOpenPgpApi(data: Intent, input: InputStream, output: OutputStream): Intent? {

View File

@ -91,7 +91,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
passwordEntry?.let { entry -> passwordEntry?.let { entry ->
if (menu != null) { if (menu != null) {
menu.findItem(R.id.edit_password).isVisible = true menu.findItem(R.id.edit_password).isVisible = true
if (entry.password.isNullOrBlank()) { if (!entry.password.isNullOrBlank()) {
menu.findItem(R.id.share_password_as_plaintext).isVisible = true menu.findItem(R.id.share_password_as_plaintext).isVisible = true
menu.findItem(R.id.copy_password).isVisible = true menu.findItem(R.id.copy_password).isVisible = true
} }
@ -189,7 +189,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
passwordEntry = entry passwordEntry = entry
invalidateOptionsMenu() invalidateOptionsMenu()
if (entry.password.isNullOrBlank()) { if (!entry.password.isNullOrBlank()) {
items.add(FieldItem.createPasswordField(entry.password!!)) items.add(FieldItem.createPasswordField(entry.password!!))
} }