diff options
Diffstat (limited to 'app/src')
3 files changed, 19 insertions, 6 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyImportActivity.kt b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyImportActivity.kt index 4c9060f7..0b3fdd4e 100644 --- a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyImportActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyImportActivity.kt @@ -73,6 +73,7 @@ class PGPKeyImportActivity : AppCompatActivity() { is Ok<PGPKey?> -> { val key = result.value if (key == null) { + setResult(RESULT_CANCELED) finish() // This return convinces Kotlin that the control flow for `key == null` definitely // terminates here and allows for a smart cast below. @@ -81,7 +82,10 @@ class PGPKeyImportActivity : AppCompatActivity() { MaterialAlertDialogBuilder(this) .setTitle(getString(R.string.pgp_key_import_succeeded)) .setMessage(getString(R.string.pgp_key_import_succeeded_message, tryGetId(key))) - .setPositiveButton(android.R.string.ok) { _, _ -> finish() } + .setPositiveButton(android.R.string.ok) { _, _ -> + setResult(RESULT_OK) + finish() + } .setCancelable(false) .show() } diff --git a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt index 43fba086..90a6d21f 100644 --- a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyListActivity.kt @@ -1,8 +1,10 @@ package app.passwordstore.ui.pgp +import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult import androidx.activity.viewModels import androidx.compose.foundation.layout.padding import androidx.compose.material3.ExperimentalMaterial3Api @@ -19,7 +21,6 @@ import app.passwordstore.R import app.passwordstore.ui.APSAppBar import app.passwordstore.ui.compose.theme.APSTheme import app.passwordstore.ui.compose.theme.decideColorScheme -import app.passwordstore.util.extensions.launchActivity import app.passwordstore.util.viewmodel.PGPKeyListViewModel import dagger.hilt.android.AndroidEntryPoint @@ -28,6 +29,12 @@ import dagger.hilt.android.AndroidEntryPoint class PGPKeyListActivity : ComponentActivity() { private val viewModel: PGPKeyListViewModel by viewModels() + private val keyImportAction = + registerForActivityResult(StartActivityForResult()) { + if (it.resultCode == RESULT_OK) { + viewModel.updateKeySet() + } + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -44,7 +51,9 @@ class PGPKeyListActivity : ComponentActivity() { ) }, floatingActionButton = { - FloatingActionButton(onClick = { launchActivity(PGPKeyImportActivity::class.java) }) { + FloatingActionButton( + onClick = { keyImportAction.launch(Intent(this, PGPKeyImportActivity::class.java)) } + ) { Icon( painter = painterResource(R.drawable.ic_add_48dp), stringResource(R.string.pref_import_pgp_key_title) diff --git a/app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt b/app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt index 93e450b4..a21a6962 100644 --- a/app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt +++ b/app/src/main/java/app/passwordstore/util/viewmodel/PGPKeyListViewModel.kt @@ -20,10 +20,10 @@ class PGPKeyListViewModel @Inject constructor(private val keyManager: PGPKeyMana var keys: List<GpgIdentifier> by mutableStateOf(emptyList()) init { - getKeys() + updateKeySet() } - private fun getKeys() { + fun updateKeySet() { viewModelScope.launch { when ( val result = @@ -40,7 +40,7 @@ class PGPKeyListViewModel @Inject constructor(private val keyManager: PGPKeyMana fun deleteKey(identifier: GpgIdentifier) { viewModelScope.launch { keyManager.removeKey(identifier) - getKeys() + updateKeySet() } } } |