Misc PGP v2 fixes (#1784)

* Don't throw in PGPKeyImportActivity when no file is selected

* PGPSettings: mark import option as dependent on V2 backend pref
This commit is contained in:
Harsh Shandilya 2022-03-13 18:37:29 +05:30 committed by GitHub
parent 7868c6d08e
commit 6fc1fafe99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View file

@ -29,7 +29,7 @@ class PGPKeyImportActivity : AppCompatActivity() {
registerForActivityResult(OpenDocument()) { uri ->
runCatching {
if (uri == null) {
throw IllegalStateException("Selected URI was null")
return@runCatching null
}
val keyInputStream =
contentResolver.openInputStream(uri)
@ -41,13 +41,14 @@ class PGPKeyImportActivity : AppCompatActivity() {
}
.mapBoth(
{ key ->
require(key != null) { "Key cannot be null here" }
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() }
.setOnCancelListener { finish() }
.show()
if (key != null) {
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() }
.setOnCancelListener { finish() }
.show()
}
},
{ throwable ->
MaterialAlertDialogBuilder(this)

View file

@ -18,13 +18,15 @@ class PGPSettings(private val activity: FragmentActivity) : SettingsProvider {
override fun provideSettings(builder: PreferenceScreen.Builder) {
builder.apply {
checkBox(Feature.EnablePGPainlessBackend.configKey) {
title = "Enable new PGP backend"
persistent = true
}
val enablePGPainless =
checkBox(Feature.EnablePGPainlessBackend.configKey) {
title = "Enable new PGP backend"
persistent = true
}
pref("_") {
title = "Import PGP key"
persistent = false
dependency = enablePGPainless.key
onClick {
activity.launchActivity(PGPKeyImportActivity::class.java)
false