mirror of
https://github.com/bitwarden/android.git
synced 2026-03-21 22:00:42 -05:00
PM-14179: Update generator screen copy button (#4530)
This commit is contained in:
@@ -69,10 +69,10 @@ import kotlinx.collections.immutable.toImmutableList
|
||||
* @param keyboardType the preferred type of keyboard input.
|
||||
* @param textToolbarType The type of [TextToolbar] to use on the text field.
|
||||
*/
|
||||
@Suppress("LongMethod")
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||
@Composable
|
||||
fun BitwardenTextField(
|
||||
label: String,
|
||||
label: String?,
|
||||
value: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -136,7 +136,7 @@ fun BitwardenTextField(
|
||||
.focusRequester(focusRequester)
|
||||
.fillMaxWidth(),
|
||||
enabled = enabled,
|
||||
label = { Text(text = label) },
|
||||
label = label?.let { { Text(text = it) } },
|
||||
value = textFieldValue,
|
||||
leadingIcon = leadingIconResource?.let { iconResource ->
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.TextToolbar
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTag
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
@@ -48,7 +47,7 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
*/
|
||||
@Composable
|
||||
fun BitwardenTextFieldWithActions(
|
||||
label: String,
|
||||
label: String?,
|
||||
value: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenMediumTopAppBa
|
||||
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
|
||||
import com.x8bit.bitwarden.ui.platform.components.appbar.action.BitwardenOverflowActionItem
|
||||
import com.x8bit.bitwarden.ui.platform.components.appbar.action.OverflowMenuItemData
|
||||
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenFilledButton
|
||||
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton
|
||||
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTonalIconButton
|
||||
import com.x8bit.bitwarden.ui.platform.components.card.BitwardenInfoCalloutCard
|
||||
@@ -302,8 +303,8 @@ private fun ScrollContent(
|
||||
.fillMaxHeight()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
if (state.isUnderPolicy) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
BitwardenInfoCalloutCard(
|
||||
text = stringResource(id = R.string.password_generator_policy_in_effect),
|
||||
modifier = Modifier
|
||||
@@ -312,16 +313,29 @@ private fun ScrollContent(
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
}
|
||||
|
||||
GeneratedStringItem(
|
||||
generatedText = state.generatedText,
|
||||
onCopyClick = onCopyClick,
|
||||
onRegenerateClick = onRegenerateClick,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
.fillMaxWidth(),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
BitwardenFilledButton(
|
||||
label = stringResource(id = R.string.copy),
|
||||
onClick = onCopyClick,
|
||||
modifier = Modifier
|
||||
.testTag(tag = "CopyValueButton")
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
BitwardenListHeaderText(
|
||||
label = stringResource(id = R.string.options),
|
||||
@@ -365,22 +379,15 @@ private fun ScrollContent(
|
||||
@Composable
|
||||
private fun GeneratedStringItem(
|
||||
generatedText: String,
|
||||
onCopyClick: () -> Unit,
|
||||
onRegenerateClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
BitwardenTextFieldWithActions(
|
||||
label = "",
|
||||
label = null,
|
||||
textFieldTestTag = "GeneratedPasswordLabel",
|
||||
value = generatedText,
|
||||
singleLine = false,
|
||||
actions = {
|
||||
BitwardenTonalIconButton(
|
||||
vectorIconRes = R.drawable.ic_copy,
|
||||
contentDescription = stringResource(id = R.string.copy),
|
||||
onClick = onCopyClick,
|
||||
modifier = Modifier.testTag("CopyValueButton"),
|
||||
)
|
||||
BitwardenTonalIconButton(
|
||||
vectorIconRes = R.drawable.ic_generate,
|
||||
contentDescription = stringResource(id = R.string.generate_password),
|
||||
@@ -393,7 +400,7 @@ private fun GeneratedStringItem(
|
||||
textStyle = BitwardenTheme.typography.sensitiveInfoSmall,
|
||||
shouldAddCustomLineBreaks = true,
|
||||
visualTransformation = nonLetterColorVisualTransformation(),
|
||||
modifier = modifier.padding(horizontal = 16.dp),
|
||||
modifier = modifier,
|
||||
textToolbarType = TextToolbarType.NONE,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
@Test
|
||||
fun `clicking the Copy button should send CopyClick action`() {
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription(label = "Copy")
|
||||
.onNodeWithText(text = "Copy")
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
|
||||
Reference in New Issue
Block a user