Skip to content

Adding the ability to hide the input #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ dependencies {
implementation("androidx.compose.animation:animation-core:$composeUIVersion")
implementation("androidx.compose.foundation:foundation-layout:$composeUIVersion")
implementation("androidx.compose.foundation:foundation:$composeUIVersion")
implementation("androidx.compose.material:material-icons-core:$composeUIVersion")
implementation("androidx.compose.material:material-icons-extended:$composeUIVersion")
implementation("androidx.compose.runtime:runtime:$composeUIVersion")
implementation("androidx.compose.ui:ui-text:$composeUIVersion")
implementation("androidx.compose.ui:ui-unit:$composeUIVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
Expand All @@ -15,6 +21,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.lifecycle.viewmodel.compose.viewModel
import me.arianb.usb_hid_client.MainViewModel
import me.arianb.usb_hid_client.R
Expand All @@ -30,6 +39,7 @@ fun ManualInput(
settingsViewModel: SettingsViewModel = viewModel()
) {
var manualInputString by remember { mutableStateOf("") }
var showInputString by remember { mutableStateOf(value = true) }

Row(
modifier = Modifier.fillMaxWidth(),
Expand All @@ -42,7 +52,35 @@ fun ManualInput(
.weight(1f), // For some reason, this makes the button not be squished at the end of the Row
value = manualInputString,
label = { Text(stringResource(R.string.manual_input)) },
onValueChange = { manualInputString = it }
onValueChange = { manualInputString = it },
visualTransformation = if (showInputString) {
VisualTransformation.None
} else {
PasswordVisualTransformation()
},
keyboardOptions = if (showInputString) {
KeyboardOptions(keyboardType = KeyboardType.Text)
} else {
KeyboardOptions(keyboardType = KeyboardType.Password)
},
trailingIcon = {
if (showInputString) {
IconButton(onClick = { showInputString = false }) {
Icon(
imageVector = Icons.Filled.Visibility,
contentDescription = "Show Input"
)
}
} else {
IconButton(
onClick = { showInputString = true }) {
Icon(
imageVector = Icons.Filled.VisibilityOff,
contentDescription = "Hide Input"
)
}
}
}
)
Button(
modifier = Modifier.wrapContentSize(),
Expand Down