aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt26
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt5
2 files changed, 22 insertions, 9 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt b/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt
index 289391b4..8671b5cb 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/settings/RepositorySettings.kt
@@ -9,6 +9,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.ShortcutManager
import android.os.Build
+import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.edit
import androidx.core.content.getSystemService
import androidx.fragment.app.FragmentActivity
@@ -38,11 +39,17 @@ import dev.msfjarvis.aps.util.extensions.getString
import dev.msfjarvis.aps.util.extensions.sharedPrefs
import dev.msfjarvis.aps.util.extensions.snackbar
import dev.msfjarvis.aps.util.extensions.unsafeLazy
+import dev.msfjarvis.aps.util.git.sshj.SshKey
import dev.msfjarvis.aps.util.settings.GitSettings
import dev.msfjarvis.aps.util.settings.PreferenceKeys
class RepositorySettings(private val activity: FragmentActivity) : SettingsProvider {
+ private val generateSshKey =
+ activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
+ showSshKeyPref?.visible = SshKey.canShowSshPublicKey
+ }
+
private val hiltEntryPoint by unsafeLazy {
EntryPointAccessors.fromApplication(
activity.applicationContext,
@@ -50,6 +57,8 @@ class RepositorySettings(private val activity: FragmentActivity) : SettingsProvi
)
}
+ private var showSshKeyPref: Preference? = null
+
private fun <T : FragmentActivity> launchActivity(clazz: Class<T>) {
activity.startActivity(Intent(activity, clazz))
}
@@ -111,18 +120,19 @@ class RepositorySettings(private val activity: FragmentActivity) : SettingsProvi
pref(PreferenceKeys.SSH_KEYGEN) {
titleRes = R.string.pref_ssh_keygen_title
onClick {
- launchActivity(SshKeyGenActivity::class.java)
+ generateSshKey.launch(Intent(activity, SshKeyGenActivity::class.java))
true
}
}
- pref(PreferenceKeys.SSH_SEE_KEY) {
- titleRes = R.string.pref_ssh_see_key_title
- visible = PasswordRepository.isGitRepo()
- onClick {
- ShowSshKeyFragment().show(activity.supportFragmentManager, "public_key")
- true
+ showSshKeyPref =
+ pref(PreferenceKeys.SSH_SEE_KEY) {
+ titleRes = R.string.pref_ssh_see_key_title
+ visible = PasswordRepository.isGitRepo() && SshKey.canShowSshPublicKey
+ onClick {
+ ShowSshKeyFragment().show(activity.supportFragmentManager, "public_key")
+ true
+ }
}
- }
pref(PreferenceKeys.CLEAR_SAVED_PASS) {
fun Preference.updatePref() {
val sshPass = encryptedPreferences.getString(PreferenceKeys.SSH_KEY_LOCAL_PASSPHRASE)
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt
index 83f44aa6..0d8ffcbc 100644
--- a/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/ui/sshkeygen/SshKeyGenActivity.kt
@@ -64,7 +64,10 @@ class SshKeyGenActivity : AppCompatActivity() {
setPositiveButton(R.string.ssh_keygen_existing_replace) { _, _ ->
lifecycleScope.launch { generate() }
}
- setNegativeButton(R.string.ssh_keygen_existing_keep) { _, _ -> finish() }
+ setNegativeButton(R.string.ssh_keygen_existing_keep) { _, _ ->
+ setResult(RESULT_CANCELED)
+ finish()
+ }
show()
}
} else {