mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-29 13:27:46 +00:00
Fix 'View generated SSH key' option showing when not applicable (#1426)
* RepositorySettings: only show preference when available Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * RepositorySettings: update 'View generated SSH key' preference after generating Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
1446947811
commit
f769968bdc
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user