@@ -6,6 +6,7 @@ package com.zeapo.pwdstore.git
66
77import android.os.Bundle
88import android.os.Handler
9+ import android.view.View
910import androidx.core.content.edit
1011import androidx.core.os.postDelayed
1112import androidx.core.widget.doOnTextChanged
@@ -50,18 +51,20 @@ class GitServerConfigActivity : BaseGitActivity() {
5051 }
5152 }
5253
53- binding.connectionModeGroup.check(when (connectionMode) {
54- ConnectionMode .SshKey -> R .id.connection_mode_ssh_key
55- ConnectionMode .Password -> R .id.connection_mode_password
56- ConnectionMode .OpenKeychain -> R .id.connection_mode_open_keychain
57- ConnectionMode .None -> R .id.connection_mode_none
58- })
59- binding.connectionModeGroup.setOnCheckedChangeListener { group, _ ->
60- when (group.checkedRadioButtonId) {
61- R .id.connection_mode_ssh_key -> connectionMode = ConnectionMode .SshKey
62- R .id.connection_mode_open_keychain -> connectionMode = ConnectionMode .OpenKeychain
63- R .id.connection_mode_password -> connectionMode = ConnectionMode .Password
64- R .id.connection_mode_none -> connectionMode = ConnectionMode .None
54+ binding.connectionModeGroup.apply {
55+ when (connectionMode) {
56+ ConnectionMode .SshKey -> check(R .id.connection_mode_ssh_key)
57+ ConnectionMode .Password -> check(R .id.connection_mode_password)
58+ ConnectionMode .OpenKeychain -> check(R .id.connection_mode_open_keychain)
59+ ConnectionMode .None -> uncheck(checkedButtonId)
60+ }
61+ addOnButtonCheckedListener { group, _, _ ->
62+ when (checkedButtonId) {
63+ R .id.connection_mode_ssh_key -> connectionMode = ConnectionMode .SshKey
64+ R .id.connection_mode_open_keychain -> connectionMode = ConnectionMode .OpenKeychain
65+ R .id.connection_mode_password -> connectionMode = ConnectionMode .Password
66+ View .NO_ID -> connectionMode = ConnectionMode .None
67+ }
6568 }
6669 }
6770 updateConnectionModeToggleGroup()
@@ -120,20 +123,21 @@ class GitServerConfigActivity : BaseGitActivity() {
120123
121124 private fun updateConnectionModeToggleGroup () {
122125 if (protocol == Protocol .Ssh ) {
123- if (binding.connectionModeNone.isChecked)
126+ // Reset connection mode to SSH key if the current value (none) is not valid for SSH
127+ if (binding.connectionModeGroup.checkedButtonIds.isEmpty())
124128 binding.connectionModeGroup.check(R .id.connection_mode_ssh_key)
125129 binding.connectionModeSshKey.isEnabled = true
126130 binding.connectionModeOpenKeychain.isEnabled = true
127- binding.connectionModeNone.isEnabled = false
131+ binding.connectionModeGroup.isSelectionRequired = true
128132 } else {
133+ binding.connectionModeGroup.isSelectionRequired = false
129134 // Reset connection mode to password if the current value is not valid for HTTPS
130135 // Important note: This has to happen before disabling the other toggle buttons or they
131136 // won't uncheck.
132137 if (connectionMode !in listOf (ConnectionMode .None , ConnectionMode .Password ))
133138 binding.connectionModeGroup.check(R .id.connection_mode_password)
134139 binding.connectionModeSshKey.isEnabled = false
135140 binding.connectionModeOpenKeychain.isEnabled = false
136- binding.connectionModeNone.isEnabled = true
137141 }
138142 }
139143
0 commit comments