Skip to content

Commit

Permalink
fix: SonarQube issues
Browse files Browse the repository at this point in the history
Resolves: 10696
  • Loading branch information
ThomasIent committed Dec 11, 2024
1 parent 6acc54c commit 5a16806
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowForward
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
Expand Down Expand Up @@ -192,7 +192,7 @@ class InformationBannerParamProvider : PreviewParameterProvider<InformationBanne
title = R.string.preview__GdsInformationBanner__title,
content = R.string.preview__GdsInformationBanner__content,
link = R.string.preview__GdsInformationBanner__link,
icon = Icons.Default.ArrowForward,
icon = Icons.AutoMirrored.Filled.ArrowForward,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,25 @@ data class RadioChoiceQuestionParameters(
)

class RadioChoiceQuestionProvider : PreviewParameterProvider<RadioChoiceQuestionParameters> {
private val radioOptionOne = "option one"
private val radioOptionTwo = "option two"
override val values: Sequence<RadioChoiceQuestionParameters> = sequenceOf(
RadioChoiceQuestionParameters(
title = string.preview__BrpInstructions__title,
content = pagesR.array.preview__BrpInstructions__array_1,
radioOptions = listOf(
RadioOption("option one"),
RadioOption("option two"),
RadioOption(radioOptionOne),
RadioOption(radioOptionTwo),
),
radioState = mutableStateOf(RadioOption("option one")),
radioState = mutableStateOf(RadioOption(radioOptionOne)),
primaryButtonText = string.preview__BrpInstructions__primary_button,
),
RadioChoiceQuestionParameters(
title = string.preview__BrpInstructions__title,
content = pagesR.array.preview__BrpInstructions__array_1,
radioOptions = listOf(
RadioOption("option one"),
RadioOption("option two"),
RadioOption(radioOptionOne),
RadioOption(radioOptionTwo),
),
radioState = mutableStateOf(null),
primaryButtonText = string.preview__BrpInstructions__primary_button,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import uk.gov.android.ui.components.m3.content.ContentParameters
import uk.gov.android.ui.components.m3.information.InformationParameters

class ErrorPageProvider : PreviewParameterProvider<ErrorPageParameters> {
private val buttonText = "Primary button"
override val values: Sequence<ErrorPageParameters> = sequenceOf(
ErrorPageParameters(
primaryButtonParameters = ButtonParameters(
buttonType = ButtonType.PRIMARY(),
onClick = {},
text = "Primary button",
text = buttonText,
),
informationParameters = InformationParameters(
contentParameters = ContentParameters(
Expand All @@ -38,7 +39,7 @@ class ErrorPageProvider : PreviewParameterProvider<ErrorPageParameters> {
primaryButtonParameters = ButtonParameters(
buttonType = ButtonType.PRIMARY(),
onClick = {},
text = "Primary button",
text = buttonText,
),
secondaryButtonParameters = ButtonParameters(
buttonType = ButtonType.ICON(
Expand Down Expand Up @@ -69,7 +70,7 @@ class ErrorPageProvider : PreviewParameterProvider<ErrorPageParameters> {
primaryButtonParameters = ButtonParameters(
buttonType = ButtonType.PRIMARY(),
onClick = {},
text = "Primary button",
text = buttonText,
),
secondaryButtonParameters = ButtonParameters(
buttonType = ButtonType.ICON(
Expand Down Expand Up @@ -102,7 +103,7 @@ class ErrorPageProvider : PreviewParameterProvider<ErrorPageParameters> {
primaryButtonParameters = ButtonParameters(
buttonType = ButtonType.PRIMARY(),
onClick = {},
text = "Primary button",
text = buttonText,
),
informationParameters = InformationParameters(
contentParameters = ContentParameters(
Expand All @@ -126,7 +127,7 @@ class ErrorPageProvider : PreviewParameterProvider<ErrorPageParameters> {
primaryButtonParameters = ButtonParameters(
buttonType = ButtonType.PRIMARY(),
onClick = {},
text = "Primary button",
text = buttonText,
),
informationParameters = InformationParameters(
contentParameters = ContentParameters(
Expand Down
39 changes: 13 additions & 26 deletions theme/src/main/java/uk/gov/android/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fun Theme() {
Swatch(MaterialTheme.colors.secondary, "Secondary")
Swatch(MaterialTheme.colors.secondaryVariant, "Secondary Variant")
}
PalletteSpacer()
PaletteSpacer()
Row {
Swatch(
MaterialTheme.colors.background,
Expand All @@ -160,7 +160,7 @@ fun Theme() {
SWATCH_COL_3,
)
}
PalletteSpacer()
PaletteSpacer()
Row {
Swatch(
MaterialTheme.colors.onPrimary,
Expand All @@ -175,7 +175,7 @@ fun Theme() {
SWATCH_COL_2,
)
}
PalletteSpacer()
PaletteSpacer()
Row {
Swatch(
MaterialTheme.colors.onBackground,
Expand Down Expand Up @@ -219,38 +219,25 @@ private fun Swatch(
) {
Text(
text = label,
color = MaterialTheme.colors.contentColorFor(backgroundColor).let {
if (it == Color.Unspecified) {
if (backgroundColor.isDark()) {
Color.White
} else {
Color.Black
}
} else {
it
}
},
color = textColorForColor(MaterialTheme.colors.contentColorFor(backgroundColor)),
)
Text(
text = backgroundColor.toHexString(),
color = MaterialTheme.colors.contentColorFor(backgroundColor).let {
if (it == Color.Unspecified) {
if (backgroundColor.isDark()) {
Color.White
} else {
Color.Black
}
} else {
it
}
},
color = textColorForColor(MaterialTheme.colors.contentColorFor(backgroundColor)),
)
}
}
}

@Composable
private fun PalletteSpacer() {
private fun textColorForColor(color: Color) = if (color == Color.Unspecified) {
if (color.isDark()) Color.White else Color.Black
} else {
color
}

@Composable
private fun PaletteSpacer() {
Spacer(
modifier = Modifier.height(PALETTE_PADDING.dp),
)
Expand Down
43 changes: 15 additions & 28 deletions theme/src/main/java/uk/gov/android/ui/theme/m3/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fun Theme() {
color = MaterialTheme.colorScheme.error,
)
}
PalletteSpacer()
PaletteSpacer()
Row {
Swatch(
MaterialTheme.colorScheme.primaryContainer,
Expand Down Expand Up @@ -178,7 +178,7 @@ fun Theme() {
"Scrim",
)
}
PalletteSpacer()
PaletteSpacer()
Row {
Swatch(
MaterialTheme.colorScheme.onPrimaryContainer,
Expand All @@ -201,7 +201,7 @@ fun Theme() {
color = MaterialTheme.colorScheme.errorContainer,
)
}
PalletteSpacer()
PaletteSpacer()
Row {
Swatch(
MaterialTheme.colorScheme.surface,
Expand All @@ -228,7 +228,7 @@ fun Theme() {
color = MaterialTheme.colorScheme.surfaceVariant,
)
}
PalletteSpacer()
PaletteSpacer()
Row {
Swatch(
MaterialTheme.colorScheme.outline,
Expand Down Expand Up @@ -266,43 +266,30 @@ private fun Swatch(
color = if (color != Color.Unspecified) {
color
} else {
MaterialTheme.colorScheme.contentColorFor(backgroundColor).let {
if (it == Color.Unspecified) {
if (backgroundColor.isDark()) {
Color.White
} else {
Color.Black
}
} else {
it
}
}
textColorForColor(MaterialTheme.colorScheme.contentColorFor(backgroundColor))
},
)
Text(
text = backgroundColor.toHexString(),
color = if (color != Color.Unspecified) {
color = if (color == Color.Unspecified) {
color
} else {
MaterialTheme.colorScheme.contentColorFor(backgroundColor).let {
if (it == Color.Unspecified) {
if (backgroundColor.isDark()) {
Color.White
} else {
Color.Black
}
} else {
it
}
}
textColorForColor(MaterialTheme.colorScheme.contentColorFor(backgroundColor))
},
)
}
}
}

@Composable
private fun PalletteSpacer() {
private fun textColorForColor(color: Color) = if (color == Color.Unspecified) {
if (color.isDark()) Color.White else Color.Black
} else {
color
}

@Composable
private fun PaletteSpacer() {
Spacer(
modifier = Modifier.height(PALETTE_PADDING.dp),
)
Expand Down
4 changes: 2 additions & 2 deletions theme/src/main/java/uk/gov/android/ui/theme/m3/Typography.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -149,7 +149,7 @@ private fun TypographyPreview() {
Text(style = type.second, text = type.first)
Text(text = " - ${type.second.fontSize.value.toInt()}sp")
}
Divider(modifier = Modifier.fillMaxWidth())
HorizontalDivider(modifier = Modifier.fillMaxWidth())
}
}
}
Expand Down

0 comments on commit 5a16806

Please sign in to comment.