mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 10:48:47 +03:00
Disable inline autofill toggle when autofill is disabled (#674)
This commit is contained in:
parent
b77de7ba4d
commit
cb306a8377
4 changed files with 60 additions and 3 deletions
|
@ -36,6 +36,8 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
|||
* @param description An optional description label to be displayed below the [label].
|
||||
* @param contentDescription A description of the switch's UI for accessibility purposes.
|
||||
* @param readOnly Disables the click functionality without modifying the other UI characteristics.
|
||||
* @param enabled Whether or not this switch is enabled. This is similar to setting [readOnly] but
|
||||
* comes with some additional visual changes.
|
||||
*/
|
||||
@Composable
|
||||
fun BitwardenWideSwitch(
|
||||
|
@ -46,6 +48,7 @@ fun BitwardenWideSwitch(
|
|||
description: String? = null,
|
||||
contentDescription: String? = null,
|
||||
readOnly: Boolean = false,
|
||||
enabled: Boolean = true,
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
|
@ -56,7 +59,7 @@ fun BitwardenWideSwitch(
|
|||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
||||
onClick = { onCheckedChange?.invoke(!isChecked) },
|
||||
enabled = !readOnly,
|
||||
enabled = !readOnly && enabled,
|
||||
)
|
||||
.semantics(mergeDescendants = true) {
|
||||
toggleableState = ToggleableState(isChecked)
|
||||
|
@ -72,13 +75,21 @@ fun BitwardenWideSwitch(
|
|||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
color = if (enabled) {
|
||||
MaterialTheme.colorScheme.onSurface
|
||||
} else {
|
||||
MaterialTheme.colorScheme.outline
|
||||
},
|
||||
)
|
||||
description?.let {
|
||||
Text(
|
||||
text = it,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
color = if (enabled) {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
} else {
|
||||
MaterialTheme.colorScheme.outline
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,6 +135,7 @@ fun AutoFillScreen(
|
|||
onCheckedChange = remember(viewModel) {
|
||||
{ viewModel.trySendAction(AutoFillAction.UseInlineAutofillClick(it)) }
|
||||
},
|
||||
enabled = state.canInteractWithInlineAutofillToggle,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
|
|
|
@ -127,6 +127,14 @@ data class AutoFillState(
|
|||
val isUseInlineAutoFillEnabled: Boolean,
|
||||
val uriDetectionMethod: UriDetectionMethod,
|
||||
) : Parcelable {
|
||||
|
||||
/**
|
||||
* Whether or not the toggle controlling the [isUseInlineAutoFillEnabled] value can be
|
||||
* interacted with.
|
||||
*/
|
||||
val canInteractWithInlineAutofillToggle: Boolean
|
||||
get() = isAutoFillServicesEnabled
|
||||
|
||||
/**
|
||||
* A representation of the URI detection methods.
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.autofill
|
|||
|
||||
import androidx.compose.ui.test.assert
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsEnabled
|
||||
import androidx.compose.ui.test.assertIsNotEnabled
|
||||
import androidx.compose.ui.test.assertIsOff
|
||||
import androidx.compose.ui.test.assertIsOn
|
||||
import androidx.compose.ui.test.filterToOne
|
||||
|
@ -129,6 +131,12 @@ class AutoFillScreenTest : BaseComposeTest() {
|
|||
|
||||
@Test
|
||||
fun `on use inline auto fill toggle should send UseInlineAutofillClick`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
isAutoFillServicesEnabled = true,
|
||||
isUseInlineAutoFillEnabled = false,
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithText("Use inline autofill")
|
||||
.performScrollTo()
|
||||
|
@ -149,6 +157,35 @@ class AutoFillScreenTest : BaseComposeTest() {
|
|||
.assertIsOn()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `use inline autofill should be disabled or enabled according to state`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
isAutoFillServicesEnabled = true,
|
||||
isUseInlineAutoFillEnabled = true,
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Use inline autofill")
|
||||
.performScrollTo()
|
||||
.assertIsOn()
|
||||
.assertIsEnabled()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
isAutoFillServicesEnabled = false,
|
||||
isUseInlineAutoFillEnabled = true,
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Use inline autofill")
|
||||
.performScrollTo()
|
||||
.assertIsOn()
|
||||
.assertIsNotEnabled()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on copy TOTP automatically toggle should send CopyTotpAutomaticallyClick`() {
|
||||
composeTestRule
|
||||
|
|
Loading…
Add table
Reference in a new issue