Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit a6eb4b4

Browse files
Make connection mode a <= 1 toggle group to prevent UI overflow (#778)
1 parent 3711bb9 commit a6eb4b4

2 files changed

Lines changed: 31 additions & 33 deletions

File tree

app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package com.zeapo.pwdstore.git
66

77
import android.os.Bundle
88
import android.os.Handler
9+
import android.view.View
910
import androidx.core.content.edit
1011
import androidx.core.os.postDelayed
1112
import 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

app/src/main/res/layout/activity_git_clone.xml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,43 +145,37 @@
145145
app:layout_constraintStart_toStartOf="parent"
146146
app:layout_constraintTop_toBottomOf="@id/label_server_path" />
147147

148-
<RadioGroup
148+
<com.google.android.material.button.MaterialButtonToggleGroup
149149
android:id="@+id/connection_mode_group"
150+
style="@style/TextAppearance.MaterialComponents.Headline1"
150151
android:layout_width="wrap_content"
151152
android:layout_height="wrap_content"
152-
android:orientation="horizontal"
153+
android:layout_margin="8dp"
153154
app:layout_constraintStart_toStartOf="parent"
154-
app:layout_constraintTop_toBottomOf="@id/label_connection_mode">
155+
app:layout_constraintTop_toBottomOf="@id/label_connection_mode"
156+
app:singleSelection="true">
155157

156-
<RadioButton
158+
<com.google.android.material.button.MaterialButton
157159
android:id="@+id/connection_mode_ssh_key"
160+
style="?attr/materialButtonOutlinedStyle"
158161
android:layout_width="wrap_content"
159162
android:layout_height="wrap_content"
160-
android:padding="4dp"
161163
android:text="@string/connection_mode_ssh_key" />
162164

163-
<RadioButton
165+
<com.google.android.material.button.MaterialButton
164166
android:id="@+id/connection_mode_password"
167+
style="?attr/materialButtonOutlinedStyle"
165168
android:layout_width="wrap_content"
166169
android:layout_height="wrap_content"
167-
android:padding="4dp"
168170
android:text="@string/connection_mode_basic_authentication" />
169171

170-
<RadioButton
172+
<com.google.android.material.button.MaterialButton
171173
android:id="@+id/connection_mode_open_keychain"
174+
style="?attr/materialButtonOutlinedStyle"
172175
android:layout_width="wrap_content"
173176
android:layout_height="wrap_content"
174-
android:padding="4dp"
175177
android:text="@string/connection_mode_openkeychain" />
176-
177-
<RadioButton
178-
android:id="@+id/connection_mode_none"
179-
android:layout_width="wrap_content"
180-
android:layout_height="wrap_content"
181-
android:padding="4dp"
182-
android:text="@string/connection_mode_none" />
183-
184-
</RadioGroup>
178+
</com.google.android.material.button.MaterialButtonToggleGroup>
185179

186180
<com.google.android.material.button.MaterialButton
187181
android:id="@+id/save_button"

0 commit comments

Comments
 (0)