diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bda723b..78c5f3f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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") diff --git a/app/src/main/java/me/arianb/usb_hid_client/input_views/ManualInput.kt b/app/src/main/java/me/arianb/usb_hid_client/input_views/ManualInput.kt index 3b58ba2..5eed2b9 100644 --- a/app/src/main/java/me/arianb/usb_hid_client/input_views/ManualInput.kt +++ b/app/src/main/java/me/arianb/usb_hid_client/input_views/ManualInput.kt @@ -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 @@ -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 @@ -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(), @@ -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(),